SA-MP Forums Archive
respawning objects - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: respawning objects (/showthread.php?tid=179336)



respawning objects - Face9000 - 26.09.2010

Hi all,how to respawn objects after they are destroyed?

I want a respawn after 1 minute..thanks


Re: respawning objects - Libra_PL - 26.09.2010

Do you mean barrels or haystacks?


Re: respawning objects - Mauzen - 26.09.2010

You cannot detect if a object is destroyed or not. So the only way to respawn them woul be to set a 60-seconds-timer that destroys and recreates ALL destroyable objects at once.


Re: respawning objects - Face9000 - 26.09.2010

Yeah,i mean barrels..

@Mauzen..can u explain more?


Re: respawning objects - Mauzen - 26.09.2010

In OnGameModeInit or where you create the objects the first time, use an array to store their ids like this:

pawn Код:
new objects[NUMBER_OF_YOUR_OBJECTS];

public OnGameModeIni()
{
    objects[0] = CreateObject(...);
    objects[1] = CreateObject(...);
    objects[2] = CreateObject(...);
    ...

    SetTimer("RespawnObjects", 60000, 1); //Creates a repeating 60 seconds timer that calls "RespawnObjects"
}
Then you can use the ids in the timer to recreate all the objects:

pawn Код:
forward RespawnObjects();
public RespawnObjects()
{
    for(new i = 0; i < sizeof(objects); i ++)    //This loop destroys all the objects, so there are no double objects
    {
        DestroyObjects(objects[i]);
    }
    //Then recreate them, just use the code you used in OnGameModeInit to create them:
    objects[0] = CreateObject(...);
    objects[1] = CreateObject(...);
    objects[2] = CreateObject(...);
    ...
}



Re: respawning objects - 3ventic - 26.09.2010

If you leave the area and come back, they're "respawned".


Re: respawning objects - Face9000 - 26.09.2010

I've too much objects..how to respawn all?


Re: respawning objects - Cameltoe - 26.09.2010

Use an streamer


Re: respawning objects - Mauzen - 26.09.2010

just replace NUMBER_OF_YOUR_OBJECTS with the number, there will be no limit how many objects you respawn with the code.


Re: respawning objects - Face9000 - 26.09.2010

Thanks