respawning objects
#1

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

I want a respawn after 1 minute..thanks
Reply
#2

Do you mean barrels or haystacks?
Reply
#3

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.
Reply
#4

Yeah,i mean barrels..

@Mauzen..can u explain more?
Reply
#5

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(...);
    ...
}
Reply
#6

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

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

Use an streamer
Reply
#9

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

Thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)