SA-MP Forums Archive
command that only works if you picked up something? - 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: command that only works if you picked up something? (/showthread.php?tid=174108)



command that only works if you picked up something? - WillyP - 04.09.2010

say you picked up a object...

then typed a command

then it went

and you tried again, but you didnt pick up the object, so the command didnt work.

would it be something like

pawn Код:
pickedup =1;

maybe?


Re: command that only works if you picked up something? - Calgon - 04.09.2010

You would need to create a PVar or an array/enum.

pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid) {
    if(pickupid == 204) { // Use a variable to hold the pickup ID. But for this example, I've set a random number.
        SetPVarInt(playerid, "pickedUpPickup", 1); // As a PVar.
        playerPickedUpPickup[playerid] = 1; // As an array, this is faster than using a PVar. To declare it, use 'new playerPickedUpPickup[MAX_PLAYERS];'
    }
   
    return 1;
}
And in your command code to check whether your pickup was picked up:

pawn Код:
if(GetPVarInt(playerid, "pickedUpPickup") == 1) { // As a PVar
print("Hello World");
SetPVarInt(playerid, "pickedUpPickup", 0); // They need to pickup the pickup... again!
}
if(playerPickedUpPickup[playerid] == 1) { // As an array
print("Hello World");
playerPickedUpPickup[playerid] = 0; // They need to pickup the pickup... again!
}
"Hello World" would print if the pickup had been picked up.


Re: command that only works if you picked up something? - pmk1 - 04.09.2010

and if you want it in a cmd, here is how it works:
Код:
	if (strcmp("/cmd", cmdtext, true, 10) == 0)
	{
	if(playerPickedUpPickup[playerid] == 0)
	{
	SendClientMessage(playerid, COLOR_BRIGHTRED, "You Didn't Pick up the Pick-Up! Take it to use this cmd");
	}
	else
	{
               // rest of ur command
	playerPickedUpPickup[playerid] = 0;
	}



Re: command that only works if you picked up something? - WillyP - 04.09.2010

thanks guys :P