Custom Pickup Respawn Function

Started by Inferno, Jan 26, 2021, 08:27 AM

Previous topic - Next topic

Inferno

Why need of this when you have Pickup.Timer?

Here's why : https://forum.vc-mp.org/?topic=8306

Snippets

Alternative #1 ( Aligned Timer : Use only if your server's time rate is 1000ms ( 1 second ) as OnTimeChange depends on Time Rate )

OnScriptLoad
SetToRespawn<- array( 5000, null);
 RespawnCD <- 0;


OnTimeChange
function onTimeChange( lastHour, lastMinute, hour, minute )
{
    for(local pi = 0; pi < 2000; pi++)
    {
        local pickup = FindPickup(pi);
       if(pickup)
        {
if(RespawnCD < 16) {
RespawnCD ++; // increase respawn cd till it doesnt reach 16 seconds
}
if(SetToRespawn[pickup.ID] == true && RespawnCD > 14) { // checks if pickup is set to respawn && respawning countdown is greater than 14 seconds
RespawnCD = 0; // resets respawn cd
SetToRespawn[pickup.ID] = false; // disables respawn again without execution
pickup.World = 1; // default world
}
}
}
}

Anywhere in main script
function onPickupPickedUp( player, pickup )
{
SetPickupToRespawn(pickup); // sets pickup to respawn upon picking up
}

function SetPickupToRespawn(pickup)  // sets pickup into respawning
{
SetToRespawn[pickup.ID] = true;
pickup.World = 5555;
}

function iCreatePickup( model, pos ) // custom function so it can set class
{
local pick = CreatePickup( model, 1, 1, pos, 255, true );
SetToRespawn[pick.ID] = false;
}


Usage
Quote* Paste them correctly
* Create pickups using iCreatePickup(mode,pos) so class gets set i.e SetToRespawn[pickup.ID]
* This is used for example & sample only, the pickup which has been set to respawn can respawn even after 1s or 15s as its dependant on RespawnCD , so u will need to modify it.

Alternative #2 & #3


// onscriptload

SetToRespawn <- array(5000,null);

// ontimechange wont be used here

// onpickuppickedup

function onPickupPickedUp( player, pickup )
{
SetPickupToRespawn(pickup);
}

// function

function SetPickupToRespawn(pickup)
{
SetToRespawn[pickup.ID] = true;
 NewTimer("RespawnPickup", 15000, 1, pickup.ID); // unrecommended, Use Extended Timer here instead ( alternative #3 )
pickup.World = 5555;
}

// timer callback to use
function RespawnPickup(pick)
{
local pickup = FindPickup(pick);
if(pickup && SetToRespawn[pickup.ID] == true) {
SetToRespawn[pickup.ID] = false;
pickup.World = 1;
}
}
Viva la VU
VFS Developer
VCCNR Administrator