SA-MP Forums Archive
Destroy all objects in one time? - 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: Destroy all objects in one time? (/showthread.php?tid=169356)



Destroy all objects in one time? - Nameless303 - 19.08.2010

Hi everybody,

I've got a FS full of objects, and when I unload the FS I wan't all the objects to disapear.
Is there a way to do this without that I have to save every objects' ID?

Thanks!


Re: Destroy all objects in one time? - [NWA]Hannes - 19.08.2010

Quote:
Originally Posted by Nameless303
Посмотреть сообщение
Hi everybody,

I've got a FS full of objects, and when I unload the FS I wan't all the objects to disapear.
Is there a way to do this without that I have to save every objects' ID?

Thanks!
In your fs:
pawn Код:
//Above main
new bool:ScriptObject[MAX_OBJECTS];

//At OnFilterScriptInit
DestroyScriptObjects();
CreateScriptObject(modelid, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ); //This does same thing as CreateObject and are the same params etc.

//At OnFilterScriptExit
DestroyScriptObjects();

//Somewhere in script
stock CreateScriptObject(modelid, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ)
{
    Snew objectid = CreateObject(modelid, X, Y, Z, rX, rY, rZ);
    ScriptObject[objectid] = true;
}

stock DestroyScriptObjects()
{
    for(new o=0; o<sizeof(ScriptObject); o++)
    {
        if(ScriptObject[o])
        {
            DestroyObject(o);
            ScriptObject[o]=false;
        }
    }
}
Use "CreateScriptObject" function instead of CreateObject.


Re: Destroy all objects in one time? - Nameless303 - 19.08.2010

Quote:
Originally Posted by [NWA]Hannes
Посмотреть сообщение
In your fs:
pawn Код:
//Above main
new bool:ScriptObject[MAX_OBJECTS];

//At OnFilterScriptInit
DestroyScriptObjects();
CreateScriptObject(modelid, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ); //This does same thing as CreateObject and are the same params etc.

//At OnFilterScriptExit
DestroyScriptObjects();

//Somewhere in script
stock CreateScriptObject(modelid, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ)
{
    Snew objectid = CreateObject(modelid, X, Y, Z, rX, rY, rZ);
    ScriptObject[objectid] = true;
}

stock DestroyScriptObjects()
{
    for(new o=0; o<sizeof(ScriptObject); o++)
    {
        if(ScriptObject[o])
        {
            DestroyObject(o);
            ScriptObject[o]=false;
        }
    }
}
Use "CreateScriptObject" function instead of CreateObject.
Super! Ty!


Re: Destroy all objects in one time? - Claude - 19.08.2010

Why making it so hard?

pawn Код:
for(new o; o < MAX_OBJECTS; o++)
{
    DestroyObject(o);
}



Re: Destroy all objects in one time? - Nameless303 - 19.08.2010

Quote:
Originally Posted by [NWA]Hannes
Посмотреть сообщение
In your fs:
pawn Код:
//Above main
new bool:ScriptObject[MAX_OBJECTS];

//At OnFilterScriptInit
DestroyScriptObjects();
CreateScriptObject(modelid, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ); //This does same thing as CreateObject and are the same params etc.

//At OnFilterScriptExit
DestroyScriptObjects();

//Somewhere in script
stock CreateScriptObject(modelid, Float:X, Float:Y, Float:Z, Float:rX, Float:rY, Float:rZ)
{
    Snew objectid = CreateObject(modelid, X, Y, Z, rX, rY, rZ);
    ScriptObject[objectid] = true;
}

stock DestroyScriptObjects()
{
    for(new o=0; o<sizeof(ScriptObject); o++)
    {
        if(ScriptObject[o])
        {
            DestroyObject(o);
            ScriptObject[o]=false;
        }
    }
}
Use "CreateScriptObject" function instead of CreateObject.
Only one question, what is Snew?


Re: Destroy all objects in one time? - Nameless303 - 19.08.2010

Quote:
Originally Posted by Claude
Посмотреть сообщение
Why making it so hard?

pawn Код:
for(new o; o < MAX_OBJECTS; o++)
{
    DestroyObject(o);
}
Doesn't that delete ALL objects in my GM? Aswell the ones in my GM and FS'?


Re: Destroy all objects in one time? - Claude - 19.08.2010

You should put only in one file the objects also.. And yes, it does delete all, or try this:

At the top:

pawn Код:
new bool:CreatedObjects[MAX_OBJECTS] = false;
At OnFilterScriptInIt
pawn Код:
CreatedObjects[MAX_OBJECTS] = true;
pawn Код:
for(new o; o < MAX_OBJECTS; o++)
{
    if(CreatedObjects[o] == true)
    {
        DestroyObject(o);
    }
}
Tell me the errors cause I am sure there are


Re: Destroy all objects in one time? - iggy1 - 19.08.2010

I dont think u can make an array false only aray slots.
like,
pawn Код:
new bool:CreatedObjects[MAX_OBJECTS];
CreatedObjects[0] = false;



Re: Destroy all objects in one time? - Nameless303 - 19.08.2010

Quote:
Originally Posted by iggy1
Посмотреть сообщение
I dont think u can make an array false only aray slots.
like,
pawn Код:
new bool:CreatedObjects[MAX_OBJECTS];
CreatedObjects[0] = false;
Indeed.

I'm now trying [NWA]Hannes' script and it gives errors..
Idk how to fix them;

C:\Users\Alex\Desktop\**\filterscripts\bigjump.pwn (50) : error 004: function "AddScriptObject" is not implemented

And I get one of these for every object..

EDIT: Nvm, fixed it.


Re: Destroy all objects in one time? - [NWA]Hannes - 19.08.2010

Quote:
Originally Posted by Nameless303
Посмотреть сообщение
Indeed.

I'm now trying [NWA]Hannes' script and it gives errors..
Idk how to fix them;

C:\Users\Alex\Desktop\**\filterscripts\bigjump.pwn (50) : error 004: function "AddScriptObject" is not implemented

And I get one of these for every object..

EDIT: Nvm, fixed it.
Btw just use CreateScriptObject for the objects you want to remove.
For normal objects, use CreateObject