Destroy All Object Help
#1

Greeting..

I have problems with destroy object ..

Creates nice, but when I will destroy, just destroya one object why?

Creating three, again destroya only one ..

Code

Код:
#define MAX_BARICADES 200
new baricade[MAX_BARICADES];

//
// creates baricades
//
orgPd_baricade(playerid, modelid) {
	new Float:x,
		Float:y,
		Float:z,
		i;

	game_GetViewPosition(playerid, x, y, z, 4.6);

	baricade[i] = CreateDynamicObject(modelid, x, y, z, 0.00000, 0.00000, 0.00000);

	EditDynamicObject(playerid, baricade[i]);

	INFO("Baricade Created.");
	return 1;
}


//
//DEL baricade
//
CMD:deleteall(playerid, params[]){
	new i;

	for (i = 0; i < MAX_BARICADES; i++) {
		if (baricade[i] == NULL)
			continue;

		DestroyDynamicObject(baricade[i]);
		break;
	}
	INFO("Delete all baricades");
	return 1;
}
How to destroya all?
Reply
#2

remove break from your loop
Reply
#3

Nothing ... Creating 5 barricades, now wiped only last, but not all ..
Reply
#4

Quote:
Originally Posted by Savana221
Посмотреть сообщение
Nothing ... Creating 5 barricades, now wiped only last, but not all ..
thats because you are using variable "i" in the creating function which will be always 0 and on each creation index 0 is getting replaced one solution could be changing this to an iterator or declare variable I in that function as static and on the end of function increment it (which I wont recommend) or loop through indexes as you did in 2nd function find the index having null element and use that index.
Reply
#5

Can an example?
Reply
#6

PHP код:
#define MAX_BARICADES 200
new baricade[MAX_BARICADES];
//
// creates baricades
//
orgPd_baricade(playeridmodelid) {
    new 
Float:x,
        
Float:y,
        
Float:z,
        
i;
    
game_GetViewPosition(playeridxyz4.6);
    for(; 
MAX_BARICADESi++) // Loop to get free index
        
if(!IsValidDynamicObject(baricade[i])) // Check if baricade[i] is valid dynamic object, if it's an invalid object, then create a barricade using this index
        
{
            
baricade[i] = CreateDynamicObject(modelidxyz0.000000.000000.00000);
            
EditDynamicObject(playeridbaricade[i]);
            
INFO("Baricade Created.");
            return 
1;
        }
    
INFO("No more slot for barricade.");
    return 
1;
}
//
//DEL baricade
//
CMD:deleteall(playeridparams[]){
    new 
i;
    for (
0MAX_BARICADESi++) {
        
DestroyDynamicObject(baricade[i]);
        
baricade[i] = 0;
    }
    
INFO("Delete all baricades");
    return 
1;

Reply
#7

Thankkkkkk youuuu <3
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)