Performing a check before giving the player a gun. -
whereschris - 13.01.2010
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.
Re: Performing a check before giving the player a gun. -
Grim_ - 13.01.2010
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.
Re: Performing a check before giving the player a gun. -
jameskmonger - 13.01.2010
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;
}
Re: Performing a check before giving the player a gun. -
Babul - 13.01.2010
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;
}
Re: Performing a check before giving the player a gun. -
Grim_ - 13.01.2010
jameskmonger : That wouldn't even work. You're checking if the players money is NOT less than 40,000.
Re: Performing a check before giving the player a gun. -
whereschris - 13.01.2010
Ahh. I never knew pawno read from top to bottom.
Thanks guys
These fast replys are crazy
Re: Performing a check before giving the player a gun. -
jameskmonger - 13.01.2010
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;
}