How To Set Separate pickup.RespawnTime timer

Started by MacTavish, Mar 06, 2015, 12:35 PM

Previous topic - Next topic

MacTavish

as the topic name say How To Set Separate pickup.RespawnTime timer


I've tried Many stupid ways but didn't succeed :-\

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

.

I'm not sure I get what you mean :-\ I have an idea but I don't want to assume things.
.

MacTavish

S.L.C i wanna add separate time for each pickup

Likeheal pickup spawns after 3 secs
weapon pickup spawns after 6 secs

I've tried this
if ( pickup.Model == 366 )
 {
 if ( player.Health < 100 )
{
pickup.RespawnTime = 3000;
 player.Health = 100;
 MessagePlayer("[#F5F5F5][INFO]:[#FFFF00]Healed",player);
}
 else  MessagePlayer("[#F5F5F5][INFO]:[#FFFF00]You Don't Need To Be Healed",player);
 }
 else if(pickup.Model==280)
{
pickup.RespawnTime = 6000;
player.SetWeapon(26,-250+500);
}

But only one works from them

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

.

Oh, ok. One second. I'll be back with an example and see if I got it.
.

.

#4
Note that I haven't tested this. It's just an example to see if I understand what you meant:
// Do not modify directly
local _PickupPool = [];

function _ProcessPickups()
{
    // Cache the time to avoid too many function calls
    local tm = time();
    // Process all pickups
    foreach (pkp in _PickupPool)
    {
        // See if the pickup is valid and the time out expired
        if (pkp && tm >= pkp.Timer) {
            // Since the pickup time epired it's time to respawn it
            pkp.Inst.Respawn();
            // Update the pickup timer for the next respawn
            pkp.Timer = pkp.Time + tm;
        }
    }
}

function CheckPickup(pickup)
{
    // First make sure the ID is in range and then check if it's valid
    return pickup.ID >= _PickupPool.len() ? false : !(!_PickupPool[pickup.ID]);
}

function AddPickup(pickup, tm)
{
    // See if the pickup doesn't already exist
    if (CheckPickup(pickup)) {
        // Just update the timer in this case
        _PickupPool[pickup.ID].Time = tm;
        // Can be considered successfull
        return true;
    }
    // See if the ID is in range and attempt to accomodate for space
    if (pickup.ID >= _PickupPool.len()) _PickupPool.resize(pickup.ID+8);
    // Make sure the pickup is no longer automatic
    pickup.Automatic = false;
    // See if the specified time is invalid
    if (tm < 1) tm = pickup.Timer;
    // See if the timer is still invalid
    if (tm < 1) return false;
    // Now try to insert the specified pickup
    _PickupPool[pickup.ID] = {Inst = pickup, Time = tm, Timer = time() + tm};
    // Specify that the insertion was successful
    return true;
}

function RemovePickup(pickup)
{
    if (CheckPickup(pickup)) {
        _PickupPool[pickup.ID] = null;
    }
}

function onServerStart()
{
    // Start the safe-update update timer
    NewTimer("_ProcessPickups", 1000, 0);
}
.

MacTavish

Thanks for your time S.L.C but you still didn't get me. Let me explain :)

I've added This I want them to spawn instantly. And after these pickup i've added an heal pickup and i want it to spawn after 30secs

But when i put pickup.RespawnTime in Heal pickup code then These also spawn after 30 secs but i want it instantly

I hope now you get what i mean

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

.

Well, I get it and I don't get it at the same time. Perhaps someone else should answer this. Someone that understands better.
.

MacTavish

Ok i have solved this ;D

Solution:
else if (pickup.Model==274) // this pickup will spawn instantly
{
 player.SetWeapon(17,-250+500);
 }
else if (pickup.Model==289) // and this pickup will spawn after 30secs
{
 pickup.RespawnTime = 30000;
 player.SetWeapon(32,-250+500);
 }

Previously it wasnt solved because i was just Reloading script Now i've restarted server and it worked
Thanks S.L.C For response

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

Thijn

Whats the point of -250+500? That only cost another cpu cycle and makes the script inefficient.

MacTavish

Quote from: Thijn on Mar 07, 2015, 11:24 AMWhats the point of -250+500? That only cost another cpu cycle and makes the script inefficient.
I've just copy-paste pickups from my 0.3 script :D but in 0.4 server i've replaced it with 250

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P