Create- and DestroyObject. -
Ihsan-Cingisiz - 28.01.2011
Hello,
I want to update my weed system with getting a plant on the ground.
So, for example:
pawn Код:
if(strcmp(cmd, "/plant", true) == 0)
{
new Float:X, Float:Y, Float:Z;
GetPlayerPos(playerid, X, Y, Z);
new a = CreateObject(688, X, Y, Z, 0.0, 0.0, 96.0);
}
okay, and now..?
I made that 'a' because when the player types /pickweed, the object
needs to be destroyed.. Okay, what should i do now? Anyone ideas?
PS: Which is the best ObjectID for the drug plant?
Re: Create- and DestroyObject. -
Kwarde - 28.01.2011
You're using the local function 'a'. Make it global. So:
pawn Код:
//In the range of includes:
new PlayerDrugWeed[MAX_PLAYERS] = (-1);
//In the command:
PlayerDrugWeed[playerid] = CreateObject(...);
//To destroy:
DestroyObject(PlayerDrugWeed[playerid]);
PlayerDrugWeed[playerid] = (-1);
And I don't know that fast what the best id for drug plant is. Try looking on samp wiki
Re: Create- and DestroyObject. -
Backwardsman97 - 28.01.2011
Well if you declare the variable a in the command, it's scope will be limited to that command. You would need something like a PVar.
pawn Код:
if(!strcmp(cmd, "/plant", true))
{
if(GetPVarInt(playerid,"WeedID") != -1)
{
//They already planted one
return 1;
}
new
Float:X,
Float:Y,
Float:Z,
Float:A;
GetPlayerFacingAngle(playerid,A);
GetPlayerPos(playerid, X, Y, Z);
X += (4 * floatsin(-A, degrees));
Y += (4 * floatcos(-A, degrees));
SetPVarInt(playerid,"WeedID",CreateObject(688, X, Y, Z, 0.0, 0.0, 96.0));
return 1;
}
if(!strcmp(cmd, "/pickweed", true))
{
if(GetPVarInt(playerid,"WeedID") == -1)
{
//They haven't planted one
return 1;
}
DestroyObject(GetPVarInt(playerid,"WeedID"));
SetPVarInt(playerid,"WeedID",-1);
//Rest of your pick weed code
return 1;
}
Re: Create- and DestroyObject. -
Ihsan-Cingisiz - 28.01.2011
Quote:
Originally Posted by Backwardsman97
Well if you declare the variable a in the command, it's scope will be limited to that command. You would need something like a PVar.
pawn Код:
if(!strcmp(cmd, "/plant", true)) { if(GetPVarInt(playerid,"WeedID") != -1) { //They already planted one return 1; } new Float:X, Float:Y, Float:Z, Float:A; GetPlayerFacingAngle(playerid,A); GetPlayerPos(playerid, X, Y, Z); X += (4 * floatsin(-A, degrees)); Y += (4 * floatcos(-A, degrees)); SetPVarInt(playerid,"WeedID",CreateObject(688, X, Y, Z, 0.0, 0.0, 96.0)); return 1; } if(!strcmp(cmd, "/pickweed", true)) { if(GetPVarInt(playerid,"WeedID") == -1) { //They haven't planted one return 1; } DestroyObject(GetPVarInt(playerid,"WeedID")); SetPVarInt(playerid,"WeedID",-1); //Rest of your pick weed code return 1; }
|
Hmm... I'd like to use this but i never paid attention to PVar, so i don't exactly know how
that works. And what do you exactly mean with the -1, can it just be 10 or something?
Re: Create- and DestroyObject. -
Ihsan-Cingisiz - 28.01.2011
Quote:
Originally Posted by Backwardsman97
Well if you declare the variable a in the command, it's scope will be limited to that command. You would need something like a PVar.
pawn Код:
if(!strcmp(cmd, "/plant", true)) { if(GetPVarInt(playerid,"WeedID") != -1) { //They already planted one return 1; } new Float:X, Float:Y, Float:Z, Float:A; GetPlayerFacingAngle(playerid,A); GetPlayerPos(playerid, X, Y, Z); X += (4 * floatsin(-A, degrees)); Y += (4 * floatcos(-A, degrees)); SetPVarInt(playerid,"WeedID",CreateObject(688, X, Y, Z, 0.0, 0.0, 96.0)); return 1; } if(!strcmp(cmd, "/pickweed", true)) { if(GetPVarInt(playerid,"WeedID") == -1) { //They haven't planted one return 1; } DestroyObject(GetPVarInt(playerid,"WeedID")); SetPVarInt(playerid,"WeedID",-1); //Rest of your pick weed code return 1; }
|
Hmm... I'd like to use this but i never paid attention to PVar, so i don't exactly know how
that works. And what do you exactly mean with the -1, can it just be 10 or something?
Re: Create- and DestroyObject. -
Kasis - 28.01.2011
I am waiting this extra on the server where i am playing! ^.^
sorry for off topic!
Re: Create- and DestroyObject. -
Kwarde - 29.01.2011
Quote:
Originally Posted by Ihsan-Cingisiz
Hmm... I'd like to use this but i never paid attention to PVar, so i don't exactly know how
that works. And what do you exactly mean with the -1, can it just be 10 or something?
|
-1 is mostly an invalid 'integer'. If you make a new variable for an object for a player, make it (-1);
new var[MAX_PLAYERS] = (-1);
CreateObject returns the spawned object ID. The very first object will be ID 0 (everything begins with '0' with counting instead of '1' in script languages).
So when the var is '-1' is means that it's "invalid", so "not spawned".
And about PVars: It's almost the same as normal variables.
Examples:
pawn Код:
new Nothing[MAX_PLAYERS];
Nothing[playerid] = 1;
is the same as
pawn Код:
SetPVarInt(playerid, "Nothing", 1);
With PVar's you don't need to define variables first. PVar's can also hold bigger strings. But they are not faster!
More examples:
pawn Код:
new Float:PosX[MAX_PLAYERS];
PosX[playerid] = 0.0;
is the same as
pawn Код:
SetPVarFloat(playerid, "PosX", 0.0);
And
pawn Код:
new PlayerText[MAX_PLAYERS][50];
strins(PlayerText[playerid], "I am Kwarde!", 0, strlen("I am Kwarde!"));
Is the same as
pawn Код:
SetPVarString(playerid, "PlayerText", "I am Kwarde!");
You can check it with the following functions.
Integer:
GetPVarInt(playerid, {var});
Float:
GetPVarFloat(playerid, {var});
String:
GetPVarString(playerid, {var});]
Example of getting the "Nothing" of the playerid...
The normal one:
pawn Код:
if(Nothing[playerid] == 1) print("OK");
The PVar
pawn Код:
if(GetPVarInt(playerid, "Nothin") == 1) print("OK");
It ain't hard
You can also remove PVars, with normal strings you can't (as far as I know)
DeletePVar(playerid, {var});
So, to remove the "Nothing":
pawn Код:
DeletePVar(playerid, "Nothing");
- Kevin
Re: Create- and DestroyObject. -
Ihsan-Cingisiz - 29.01.2011
Quote:
Originally Posted by Kwarde
-1 is mostly an invalid 'integer'. If you make a new variable for an object for a player, make it (-1);
new var[MAX_PLAYERS] = (-1);
CreateObject returns the spawned object ID. The very first object will be ID 0 (everything begins with '0' with counting instead of '1' in script languages).
So when the var is '-1' is means that it's "invalid", so "not spawned".
And about PVars: It's almost the same as normal variables.
Examples:
pawn Код:
new Nothing[MAX_PLAYERS]; Nothing[playerid] = 1;
is the same as
pawn Код:
SetPVarInt(playerid, "Nothing", 1);
With PVar's you don't need to define variables first. PVar's can also hold bigger strings. But they are not faster!
More examples:
pawn Код:
new Float:PosX[MAX_PLAYERS]; PosX[playerid] = 0.0;
is the same as
pawn Код:
SetPVarFloat(playerid, "PosX", 0.0);
And
pawn Код:
new PlayerText[MAX_PLAYERS][50]; strins(PlayerText[playerid], "I am Kwarde!", 0, strlen("I am Kwarde!"));
Is the same as
pawn Код:
SetPVarString(playerid, "PlayerText", "I am Kwarde!");
You can check it with the following functions.
Integer:
GetPVarInt(playerid, {var});
Float:
GetPVarFloat(playerid, {var});
String:
GetPVarString(playerid, {var});]
Example of getting the "Nothing" of the playerid...
The normal one:
pawn Код:
if(Nothing[playerid] == 1) print("OK");
The PVar
pawn Код:
if(GetPVarInt(playerid, "Nothin") == 1) print("OK");
It ain't hard
You can also remove PVars, with normal strings you can't (as far as I know)
DeletePVar(playerid, {var});
So, to remove the "Nothing":
pawn Код:
DeletePVar(playerid, "Nothing");
- Kevin
|
Thanks for your tutorial!
I'm gonna use this for sure! Thanks again!