Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: MacTavish on Mar 06, 2015, 12:35 PM

Title: How To Set Separate pickup.RespawnTime timer
Post by: MacTavish on Mar 06, 2015, 12:35 PM
as the topic name say How To Set Separate pickup.RespawnTime timer


I've tried Many stupid ways but didn't succeed :-\
Title: Re: How To Set Separate pickup.RespawnTime timer
Post by: . on Mar 06, 2015, 12:49 PM
I'm not sure I get what you mean :-\ I have an idea but I don't want to assume things.
Title: Re: How To Set Separate pickup.RespawnTime timer
Post by: MacTavish on Mar 06, 2015, 01:02 PM
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
Title: Re: How To Set Separate pickup.RespawnTime timer
Post by: . on Mar 06, 2015, 01:03 PM
Oh, ok. One second. I'll be back with an example and see if I got it.
Title: Re: How To Set Separate pickup.RespawnTime timer
Post by: . on Mar 06, 2015, 01:31 PM
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);
}
Title: Re: How To Set Separate pickup.RespawnTime timer
Post by: MacTavish on Mar 06, 2015, 01:51 PM
Thanks for your time S.L.C but you still didn't get me. Let me explain :)

I've added This (http://forum.vc-mp.org/?topic=18.0) 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 (http://forum.vc-mp.org/?topic=18.0) also spawn after 30 secs but i want it instantly

I hope now you get what i mean
Title: Re: How To Set Separate pickup.RespawnTime timer
Post by: . on Mar 06, 2015, 01:53 PM
Well, I get it and I don't get it at the same time. Perhaps someone else should answer this. Someone that understands better.
Title: Re: How To Set Separate pickup.RespawnTime timer
Post by: MacTavish on Mar 06, 2015, 03:37 PM
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
Title: Re: How To Set Separate pickup.RespawnTime timer
Post by: Thijn on Mar 07, 2015, 11:24 AM
Whats the point of -250+500? That only cost another cpu cycle and makes the script inefficient.
Title: Re: How To Set Separate pickup.RespawnTime timer
Post by: MacTavish on Mar 07, 2015, 02:07 PM
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