SA-MP Forums Archive
Destoy random 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: Destoy random object (/showthread.php?tid=298426)



Destoy random object - Stefano.R - 20.11.2011

Hi

I just wanted to know if it was possible by using the random function to destroy randomly defined objetcs and how?
PS: No, i didn't found any tutorial.

Thank you for your help


Re: Destoy random object - Tanush123 - 20.11.2011

Works on 0.3d https://sampwiki.blast.hk/wiki/RemoveBuildingForPlayer


Re : Destoy random object - Stefano.R - 20.11.2011

No, i want to destroy randomly ADDED objects:

I've got a defined CreateObject list and i want by a command destroy (with DestroyObject) one of them xD


Re: Destoy random object - Tanush123 - 20.11.2011

sorry in a rush so if you wanna destroy ur object you create do
pawn Код:
new obj;
then beside ur object
pawn Код:
obj = CreateObject...
Then in your command add the line DestroyObject(obj);


Re : Destoy random object - Stefano.R - 20.11.2011

Yeah, i know that but it's not random. I've got a list like that:

object1 = CreateObject (...)
object2 = CreateObject (...)
object3 = CreateObject (...)
object4 = CreateObject (...)
object5 = CreateObject (...)
.
.
.
(etc.. i've got 64 objects)


Then by a command (or timer I will see) I want destroy ONE of thoose object. But randomly.


Re: Destoy random object - [WSF]ThA_Devil - 20.11.2011

do
pawn Код:
DestroyObject(random(63));
//63 because all object ids start from 0!


Re: Destoy random object - MP2 - 20.11.2011

Use an array.

pawn Код:
#define OBJ_COUNT 5 // How many objects you're going to create (must be correct.)
new oArray[OBJ_COUNT];

oArray[0] = CreateObject( ... );
oArray[1] = CreateObject( ... );
oArray[2] = CreateObject( ... );
oArray[3] = CreateObject( ... );
oArray[4] = CreateObject( ... );

DestroyObject(oArray[random(OBJ_COUNT)]);



Re : Destoy random object - Stefano.R - 20.11.2011

It works ty


Re: Destoy random object - MrCong - 24.04.2013

pawn Код:
#define OBJ_COUNT 5 // How many objects you're going to create (must be correct.)
new oArray[OBJ_COUNT];

oArray[0] = CreateObject( ... );
oArray[1] = CreateObject( ... );
oArray[2] = CreateObject( ... );
oArray[3] = CreateObject( ... );
oArray[4] = CreateObject( ... );

DestroyObject(oArray[random(OBJ_COUNT)]);

how to destroy all these objects at once?


Re: Destoy random object - Babul - 24.04.2013

pawn Код:
for(new o=0;o<sizeof(oArray);o++)
{
 if(IsValidObject(oArray[o])
 {
  DestroyObject(oArray[o]);
 }
}