PlayerPos in another command... - 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: PlayerPos in another command... (
/showthread.php?tid=218018)
PlayerPos in another command... -
Ihsan-Cingisiz - 29.01.2011
Hello,
I need help with the following code:
pawn Код:
if(strcmp(cmd, "/plantweed", true) == 0)
{
if(PlayerInfo[playerid][pWeedSeeds] > 9)
{
if(PlantedWeed[playerid] == -1)
{
GetPlayerPos(playerid, WeedX, WeedY, WeedZ);
PlayerInfo[playerid][pWeedSeeds] -= 10;
PlantedWeed[playerid] = CreateObject(688, WeedX+1, WeedY+1, WeedZ, 0.0, 0.0, 96.0);
HasPlanted[playerid] = 1;
SendClientMessage(playerid, COLOR_GREEN, " You've planted a weed plant with 10 seeds.");
}
else
{
SendClientMessage(playerid, COLOR_GREY, " There is already a weed plant that belongs to you.");
}
}
else
{
SendClientMessage(playerid, COLOR_GREY, " You don't have enough seeds, you need 10 seeds.");
}
return 1;
}
if(strcmp(cmd, "/pickweed", true) == 0)
{
if(HasPlanted[playerid] == 1)
{
if(IsPlayerInRangeOfPoint(playerid, 3, WeedX, WeedY, WeedZ))
{
DestroyObject(PlantedWeed[playerid]);
PlantedWeed[playerid] = -1;
PlayerInfo[playerid][pWeed] += 50;
SendClientMessage(playerid, COLOR_RED, " You've picked your plant and got 50 grammes of weed.");
}
else
{
SendClientMessage(playerid, COLOR_YELLOW, " You're not near your weed plant.");
}
}
else
{
SendClientMessage(playerid, COLOR_GREY, " You need to plant a weed plant before picking it.");
}
return 1;
}
So I made the new Float:WeedX etc. above the script.
So the command /plantweed gets the playerposition in
the Weed-X, Y, Z., And i wanted to use it in the /pickweed
command but it doesn't know where the position is, so the
position only get saved when the player types /plantweed..
So, what should i do, what's the simplest way to make the
WeedX etc.. a local variable?
Re: PlayerPos in another command... -
JaTochNietDan - 29.01.2011
I don't know why you would want to make it in the local scope, as that only makes your problem worse! You need to have a global scope variable for each players position in order for this to work, you would initialize it like so:
pawn Код:
new Float:WeedX[MAX_PLAYERS], Float:WeedY[MAX_PLAYERS], Float:WeedZ[MAX_PLAYERS];
Then when you're using it in a function for a specific player you would simply insert the playerid as the cell of the array, like so:
pawn Код:
GetPlayerPos(playerid, WeedX[playerid], WeedY[playerid], WeedZ[playerid]);
I hope this helps with your question!