Destoy random object
#1

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
Reply
#2

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

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

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);
Reply
#5

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

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

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)]);
Reply
#8

It works ty
Reply
#9

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?
Reply
#10

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


Forum Jump:


Users browsing this thread: 1 Guest(s)