SA-MP Forums Archive
Pickups didn't destroy after time over. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Pickups didn't destroy after time over. (/showthread.php?tid=630673)



Pickups didn't destroy after time over. - Pokemon64 - 17.03.2017

My script

On the top
Код:
new meatDrops[MAX_PLAYERS];
OnPlayerDeath callback
Код:
meatDrops[playerid] = CreatePickup(2804,19,Float:x,Float:y,Float:z,0);
This one create pickup if player dead

Ongamemodeinit
Код:
SetTimer("Destroypickup", 20000, false);
Set timer for 20 seconds

Код:
forward Destroypickup(playerid);
public Destroypickup(playerid)
{
    DestroyPickup(meatDrops[playerid]); // destroying pickup after 20 second
}
And this should destroy pickup if time passed. Bat pickup still stay, he doesn't even gone if time is passed


Re: Pickups didn't destroy after time over. - Threshold - 17.03.2017

First of all, why are you calling the timer in OnGameModeInit if it is meant to be executed 20 seconds after the player dies?

Secondly, timers with parameters should be called with SetTimerEx, not SetTimer.

PHP код:
meatDrops[playerid] = CreatePickup(2804,19,Float:x,Float:y,Float:z,0);
SetTimerEx("Destroypickup"20000false"i"playerid); 
PHP код:
forward Destroypickup(playerid);
public 
Destroypickup(playerid)
{
    
DestroyPickup(meatDrops[playerid]);
    
meatDrops[playerid] = -1;

https://sampwiki.blast.hk/wiki/SetTimerEx

EDIT: You also need to remember a player can die more than once in 20 seconds. So you could potentially end up with more than 1 pickup if you're not careful and it won't be removed.


Re: Pickups didn't destroy after time over. - raydx - 17.03.2017

Nothing strange, you are calling settimer instead of settimerex and ongamemodeinit is wrong place.


Re: Pickups didn't destroy after time over. - Toroi - 17.03.2017

This does not belong under OnGameModeInit

Код:
SetTimer("Destroypickup", 20000, false);
From what you want to do, you can use that function (extended) at the same time you create the pickup, it'd be like this:

PHP код:
public OnPlayerDeath(playerid)
{
    
meatDrops[playerid] = CreatePickup(2804,19,Float:x,Float:y,Float:z,0);
    
SetTimerEx("Destroypickup"20000false,"i",playerid); //NOTICE the Ex, means Extended so we can pass the playerid value to the function
    
return 1;

And leave everything else as it is, it should work like that.

The reason for it to not work under OnGameModeInit is that it's only called once the gamemode inits (hence the name of the callback), it wont do anything else after that.

The reason for us to use SetTimerEx is to be able to pass the playerid value to the function Destroypickup, so it'd make sense.

EDIT: Ow, didn't notice the previous posts.


Re: Pickups didn't destroy after time over. - Pokemon64 - 17.03.2017

Och thanks for information now i will know.