Create a timer to respawn a object - 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: Create a timer to respawn a object (
/showthread.php?tid=632450)
Create a timer to respawn a object -
jasperschellekens - 14.04.2017
Hello there,
For a woodcutting script i need to create something which respawns the tree after a certain period of time when it has been cut down. So there has to be some kind of timer for each tree, i am really stuck on this.
The timer needs to activate at the moment the tree gets cut down.
How can i do this?
Current code:
PHP код:
g_Object_Woodcutting[0] = CreateTree(-1975.4630, -2465.3850, 29.7474, 0, 0, 700);
stock CreateTree(Float:X, Float:Y, Float:Z, world,interior,modelid)
{
for(new i = 0; i < sizeof(TreeInfo); i++)
{
if(TreeInfo[i][TreePosX] == 0.0 && TreeInfo[i][TreePosY] == 0.0 && TreeInfo[i][TreePosZ] == 0.0)
{
TreeInfo[i][TreePosX] = X;
TreeInfo[i][TreePosY] = Y;
TreeInfo[i][TreePosZ] = Z;
TreeInfo[i][TreeVWorld] = world;
TreeInfo[i][TreeInterior] = interior;
TreeInfo[i][TreeModelID] = modelid;
Label3[i] = Create3DTextLabel("Tree (Use chainsaw)", ORANGE,X,Y,Z+2.0, 10.0,world, 0);
Tree[i] = CreateDynamicObject(modelid, X, Y, Z,0,0,0, world);
return 1;
}
}
return 1;
}
//cutting down a tree:
TreeInfo[i][Toggled] = 1;
Delete3DTextLabel(Label3[i]);
DestroyDynamicObject(Tree[i]);
Re: Create a timer to respawn a object -
LEOTorres - 14.04.2017
Something of this nature should do the job:
Код:
forward RespawnTree (treeid);
public RespawnTree (treeid)
{
//code to respawn tree//
return 1;
}
When a tree gets cut down:
Код:
SetTimerEx("RespawnTree", 60000, false, "i", treeid); //tree will respawn after 60 seconds