Performing a check before giving the player a gun.
#1

Here is my command.

Код:
			if(strcmp(cmd, "/buyspas", true) == 0)
			{
		    if(IsPlayerInRangeOfPoint(playerid, 2, 2497.49,-1703.31,1014.74))
		    {
				GivePlayerWeapon(playerid, 27, 25000);
  			GivePlayerMoney(playerid, -40000);
  			SendClientMessage(playerid, 0xF0F8FFAA, "You bought a spas for $40,000.");
			  }
			  	if(GetPlayerMoney(playerid) < 40000)
				{
				SendClientMessage(playerid, 0xF0F8FFAA, "You do not have enough money to purchase this gun.");
				}
  					if(!IsPlayerInRangeOfPoint(playerid, 2, 2497.49,-1703.31,1014.74))
		    {
				SendClientMessage(playerid, 0xF0F8FFAA, "You can not purchase a weapon from here.");
			  }
			return 1;
		}
It works but for some reason, when I do /buyspas it gives me a gun, takes away $40,000 and puts me into the NEGATIVES, and also sends the message "You do not have enough money to purchase this gun". I don't want it to give them the gun if it will put them into the negatives. I don't know why my check does not work.
Reply
#2

Because you're putting the check AFTER you're giving them the weapon.
pawn Код:
if(GetPlayerMoney(playerid) < 40000)
Move that to the top of the command.
Reply
#3

Try this:
pawn Код:
if(strcmp(cmd, "/buyspas", true) == 0)
            {
            if(IsPlayerInRangeOfPoint(playerid, 2, 2497.49,-1703.31,1014.74))
            {
                if(GetPlayerMoney(playerid) < 40000) {
                GivePlayerWeapon(playerid, 27, 25000);
            GivePlayerMoney(playerid, -40000);
            SendClientMessage(playerid, 0xF0F8FFAA, "You bought a spas for $40,000.");
                }
              }
                if(!GetPlayerMoney(playerid) < 40000) {
                SendClientMessage(playerid, 0xF0F8FFAA, "You do not have enough money to purchase this gun.");
                }
                    if(!IsPlayerInRangeOfPoint(playerid, 2, 2497.49,-1703.31,1014.74))
            {
                SendClientMessage(playerid, 0xF0F8FFAA, "You can not purchase a weapon from here.");
              }
            return 1;
        }
Reply
#4

this should fix it:
Код:
		if(strcmp(cmd, "/buyspas", true) == 0)
		{
			if(GetPlayerMoney(playerid) < 40000)
			{
				SendClientMessage(playerid, 0xF0F8FFAA, "You do not have enough money to purchase this gun.");
				return 1;
			}
			if(IsPlayerInRangeOfPoint(playerid, 2, 2497.49,-1703.31,1014.74))
			{
				GivePlayerWeapon(playerid, 27, 25000);
				GivePlayerMoney(playerid, -40000);
				SendClientMessage(playerid, 0xF0F8FFAA, "You bought a spas for $40,000.");
			}
			else
			{
				SendClientMessage(playerid, 0xF0F8FFAA, "You can not purchase a weapon from here.");
			}
		return 1;
		}
Reply
#5

jameskmonger : That wouldn't even work. You're checking if the players money is NOT less than 40,000.
Reply
#6

Ahh. I never knew pawno read from top to bottom.

Thanks guys


These fast replys are crazy
Reply
#7

Fixed:
pawn Код:
if(strcmp(cmd, "/buyspas", true) == 0)
            {
            if(IsPlayerInRangeOfPoint(playerid, 2, 2497.49,-1703.31,1014.74))
            {
                if(GetPlayerMoney(playerid) > 40000) {
                GivePlayerWeapon(playerid, 27, 25000);
            GivePlayerMoney(playerid, -40000);
            SendClientMessage(playerid, 0xF0F8FFAA, "You bought a spas for $40,000.");
                }
              }
                if(!GetPlayerMoney(playerid) > 40000) {
                SendClientMessage(playerid, 0xF0F8FFAA, "You do not have enough money to purchase this gun.");
                }
                    if(!IsPlayerInRangeOfPoint(playerid, 2, 2497.49,-1703.31,1014.74))
            {
                SendClientMessage(playerid, 0xF0F8FFAA, "You can not purchase a weapon from here.");
              }
            return 1;
        }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)