Problem with DestroyObject - 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: Problem with DestroyObject (
/showthread.php?tid=402259)
Problem with DestroyObject -
ZackBoolaro - 25.12.2012
Hey there guys i'm making my Courier job script but i have a problem here.
pawn Код:
CMD:loadpackages(playerid, params[])
{
if(Courier[playerid] == 1 && IsPlayerInAnyVehicle(playerid))
{
new objectid = CreateObject(2973, 0, 0.9, -0.2, 0, 0, 0);
new vehicleid = GetPlayerVehicleID(playerid);
AttachObjectToVehicle(objectid, vehicleid, 0, 0.9, -0.2, 0, 0, 0);
} else {
SendClientMessage(playerid, COLOR_LIGHTRED, "You are either not courier or not in any vehicle !");
}
return 1;
}
CMD:deliverpackages(playerid, params[])
{
if(Courier[playerid] == 1)
{
DestroyObject(objectid);
GivePlayerMoney(playerid, 10);
SendClientMessage(playerid, COLOR_LIGHTRED, "You unloaded a package successfuly and received 10$ for it !");
}
return 1;
}
The deliverpackages command should remove the the object i'm attaching to the vehicle in the loadpackages command. How to DestroyObject from the loadpackages command when i trype deliverpackages ?
Re: Problem with DestroyObject -
Vince - 25.12.2012
Use a global variable. Local variables (i.e. variables declared within a function) are destroyed when the function exits.
Re: Problem with DestroyObject -
JaKe Elite - 25.12.2012
Do what Vince saids.
Example only, it won't work
pawn Код:
new Object; //put at the top of script
//loadpackages command
Object = CreateObject(2973, 0, 0.9, -0.2, 0, 0, 0);
//deliverpackages command
DestroyObject(Object);
Re: Problem with DestroyObject -
Joe Staff - 26.12.2012
Just to reiterate what
Romel and
Vince said, here's you're current code updated.
pawn Код:
new packageObjectID=-1;
CMD:loadpackages(playerid, params[])
{
if(Courier[playerid] == 1 && IsPlayerInAnyVehicle(playerid))
{
if(packageObjectID!=-1)DestroyObject(packageObjectID);
packageObjectID= CreateObject(2973, 0, 0.9, -0.2, 0, 0, 0);
new vehicleid = GetPlayerVehicleID(playerid);
AttachObjectToVehicle(objectid, vehicleid, 0, 0.9, -0.2, 0, 0, 0);
} else {
SendClientMessage(playerid, COLOR_LIGHTRED, "You are either not courier or not in any vehicle !");
}
return 1;
}
CMD:deliverpackages(playerid, params[])
{
if(Courier[playerid] == 1)
{
DestroyObject(packageObjectID);
packageObjectID=-1;
GivePlayerMoney(playerid, 10);
SendClientMessage(playerid, COLOR_LIGHTRED, "You unloaded a package successfuly and received 10$ for it !");
}
return 1;
}