open.mp forum
[Pawn] command usage limit - Printable Version

+- open.mp forum (https://forum.open.mp)
+-- Forum: SA-MP (https://forum.open.mp/forumdisplay.php?fid=3)
+--- Forum: Pawn Scripting (https://forum.open.mp/forumdisplay.php?fid=10)
+--- Thread: [Pawn] command usage limit (/showthread.php?tid=684)



command usage limit - unbelievable_10 - 2019-07-01

So I made command /medkit use and buy, when player types /medkit buy, his tokens gets in -, while 1 medkit gets in , problem is that I put limit that they can use /medkit buy max 3 times and so that they cannot abuse it, but when they buy all 3 medkits, it will say "You can't buy more medkits this round!", when they use /medkit use, they will get Medkit -1, and they will have 2 medkits, which will make them to be ABLE to buy the medkit again and again and again if you understand, so I want to make that they can only write /medkit buy 3 times and when they spend third medkit that they cannot again buy it, how to fix? thanks[/size][/color]
Code:
CMD:medkit(playerid, params[]) { ? ?new Float:HP; ? ?GetPlayerHealth(playerid, HP); ? ?if(playerTazed[playerid] == true || playerCuffed[playerid] == true || !IsPlayerSpawned(playerid) || playerWounded[playerid] > 0) return SFM(playerid, COLOR_ACMD, "[!] You cannot use this right now!"); ? ?if(PlayerInfo[playerid][inGame] == false) return SFM(playerid, COLOR_ACMD, "[!] {FFFFFF}You're not in the copchase!"); ? ?new option[256]; ? ?if(sscanf(params, "s[256]", option)) return SFM(playerid, COLOR_USAGE, "[USAGE] medkit <mymedkits/buy/use/help>"); ? ?if(!strcmp(option, "mymedkits")) ? ?{ ? ?SFM(playerid, COLOR_ACMD, "[!] {FFFFFF}You currently have {FF6347}[{FFFFFF}%d{FF6347}] {FFFFFF}medkits!", PlayerInfo[playerid][MedKit]); ? ?} ? ?else if(!strcmp(option, "buy")) ? ?{ ? ?if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER && GetPlayerState(playerid) != PLAYER_STATE_PASSENGER) return SFM(playerid, COLOR_ACMD, "[!] {FFFFFF}You can only buy medkits as a driver/passenger!"); ? ?if(PlayerInfo[playerid][Tokens] < 250) return SFM(playerid, COLOR_ACMD, "[!] {FFFFFF}You dont have enough tokens!"); ? ?if(PlayerInfo[playerid][MedKit] >= 3) return SFM(playerid, COLOR_ACMD, "[!] {FFFFFF}You can buy max 3 med kits per chase!"); ? ?PlayerInfo[playerid][Tokens] -= 250; ? ?PlayerInfo[playerid][MedKit] = 1; ? ?cmd_me(playerid, "grabs some bandages from the vehicle"); ? ?SFM(playerid, COLOR_ACMD, "[!] {FFFFFF}You've sucessfully bought one medkit for 250 tokens!"); ? ?} ? ?else if(!strcmp(option, "use")) ? ?{ ? ?if(GetPlayerState(playerid) != PLAYER_STATE_ONFOOT) return SFM(playerid, COLOR_ACMD, "[!] {FFFFFF}You can only use medkits while onfoot!"); ? ?if(gettime() < Cooldown[playerid]) return SFM(playerid, COLOR_ACMD, "[!] {FFFFFF}Please wait before using a medkit again!"); ? ?if(HP >= 100.0) return SFM(playerid, COLOR_ACMD, "[!] {FFFFFF}You can only use med kits if your health is below 100%!"); ? ?if(PlayerInfo[playerid][MedKit] == 0) return SFM(playerid, COLOR_ACMD, "[!] {FFFFFF}You have no medkits!"); ? ?PlayerInfo[playerid][MedKit] -= 1; ? ?SetPlayerHealth(playerid, HP); ? ?ApplyAnimation(playerid,"MEDIC","CPR",4.1, 0, 1, 1, 1, 5000, 1); ? ?SetTimerEx("Unfreeze", 5000, false, "d", playerid); ? ?cmd_me(playerid, "bandages himself up."); ? ?Cooldown[playerid] = gettime() 30 * 2; ? ?SFM(playerid, COLOR_ACMD, "[!] {FFFFFF}You've used one medkit and you've fixed your health for %! You've {FF6347}[{FFFFFF}%d{FF6347}] {FFFFFF}medkits left!", PlayerInfo[playerid][MedKit]); } else if(!strcmp(option, "help")) { ? ?return cmd_medkithelp(playerid); } ? ?return 1; }



RE: command usage limit - Cada - 2019-07-01

you need two variables to do that.



one(A) is to check amount of buying medkit, and the other(B) is to check amount of using medkit

if A become 3, player can`t buy more medkit. and so on, if B is not equal to A, player can`t buy more medkit.

if player can buy new medkit, A should be changed to new value.



try it!


RE: command usage limit - unbelievable_10 - 2019-07-01

i tried it yesterday, one guy helped me, but thanks anyways! thats how i made it!