Need help with my /shop and /heal
#1

First is my Shop, I'm trying to make it so if they don't have enough money they can't buy from the shop, I tried messing with GetPlayerMoney but to no success.
Код:
#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
	print("Shop System");
	return 1;
}

#endif

public OnFilterScriptExit()
{
	print("Shop System");
	return 1;
}

public OnPlayerText(playerid, text[])
{
	return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
	if (strcmp("/shop", cmdtext, true, 10) == 0)
	{
	 	ShowPlayerDialog(playerid, 1, DIALOG_STYLE_LIST, "Shop Menu", "Deagle($250)\nAK-47($500)\nM4($500)\nGrenade($250)\nSniper($500)\nMP5($500)\nArmor($1000)", "Choose", "Exit");
		return 1;
	}
	return 0;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	if(dialogid == 1) // Menu Help Dialog
	{
		if(!response) return SendClientMessage(playerid, 0xFFFFFFAA, "Selection Canceled!");
		switch(listitem)
		{
	        case 0: // Deagle
	        {
 					GivePlayerWeapon(playerid, 24, 50);
 					GivePlayerMoney(playerid, -250);
				 	return 1;
			}
   			case 1: // AK-47
	        {
                    GivePlayerWeapon(playerid, 30, 200);
                    GivePlayerMoney(playerid, -500);
		 			return 1;
			}
   			case 2: // M4
	        {
         			GivePlayerWeapon(playerid, 31, 150);
         			GivePlayerMoney(playerid, -500);
		 			return 1;
			}
   			case 3: // Grenade
	        {
         			GivePlayerWeapon(playerid, 16, 2);
         			GivePlayerMoney(playerid, -250);
					return 1;
			}
   			case 4: // Sniper
	        {
         			GivePlayerWeapon(playerid, 34, 25);
         			GivePlayerMoney(playerid, -500);
					return 1;
			}
   			case 5: // MP5
	        {
         			GivePlayerWeapon(playerid, 29, 200);
         			GivePlayerMoney(playerid, -500);
      				return 1;
			}
   			case 6: // Armor
	        {
					SetPlayerArmour(playerid, 100.0);
					GivePlayerMoney(playerid, -1000);
					return 1;
		   	}
		}
	}
}
My next question is about my /heal command (sorry I'm a noob)
Код:
{
	if (strcmp("/heal", cmdtext, true, 10) == 0)
	{
        if(GetPlayerMoney(playerid) >= -250)
		SetPlayerHealth(playerid, 100);
		GivePlayerMoney(playerid, -250);
		}
		else
		{
		SendClientMessage(playerid, -1, "You don't have enough money!");

		}
}
Everytime someone types /heal or /shop and buys something, even if they don't have money, it lets them and if they have $0 they go negative. How do you check the players money so it doesn't give it to them if they don't have enough?
Credits to GhostPerk77 for the dialog menu
Reply
#2

pawn Код:
if( GetPlayerMoney( playerid ) < amount )
{
// player hasnt got enough cash
}
else
{
// player has enough cash
}
or with ternary operator:

pawn Код:
GetPlayerMoney( playerid ) < amount ? /* player hasnt got enough cash */ : /* has enough cash*/;
Reply
#3

I come up with two errors now
(151) : error 036: empty statement
(156) : error 029: invalid expression, assumed zero
Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	if (strcmp("/heal", cmdtext, true, 10) == 0)
	{
	if( GetPlayerMoney( playerid ) < 250 ); // line 151
	{
	SetPlayerHealth(playerid, 100);
	GivePlayerMoney(playerid, -250);
	}
	else // line 156
	{
	SendClientMessage(playerid, 0xAA3333AA, "You don't have enough cash!");
	}
	return 1;
	}
}
Also, no idea what ternary operator is.
Reply
#4

try this It should Work
Quote:

public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/heal", cmdtext, true, 10) == 0) //the command
{
if(GetPlayerMoney(playerid) < 1000)
return SendClientMessage(playerid, 0x9EC73DAA, "You don't have enough cash to Heal You Self"); //if player dosen't have enouth money
GivePlayerMoney(playerid, -1000);
SetPlayerHealth(playerid, 100); // health status
SendClientMessage(playerid, 0x2641FEAA, "You have succesfully Healed Your Self"); //after healing
}

Reply
#5

Quote:
Originally Posted by Kells
Посмотреть сообщение
try this It should Work
Thanks! It worked
Reply
#6

and about that code for shopping
For Example You have this
:
Код:
			case 1: // AK-47
	        {
                    GivePlayerWeapon(playerid, 30, 200);
                    GivePlayerMoney(playerid, -500);
		 			return 1;
			}
make it like that
Код:
          case 1: /ak-47
{
if(GetPlayerMoney(playerid) < 500)
return SendClientMessage(playerid, 0x9EC73DAA, "You don't have enough cash to buy this Weapon."); // Message If Player Dosen't Have Enough Cash
Now We Are Ready just type :
Код:
GivePlayerMoney(playerid, -500); 
    GivePlayerWeapon(playerid, 30, 250);
Now After Succefly Buyed a weapon it will show like this
Код:
SendClientMessage(playerid, 0x2641FEAA, "You have succesfully buyed a Shownoff - shotgun");
REVISE:
Код:
case 1: //-ak-47
{
if(GetPlayerMoney(playerid) < 500)
return SendClientMessage(playerid, 0x9EC73DAA, "You don't have enough cash to buy this Weapon.");
GivePlayerMoney(playerid, -500); 
GivePlayerWeapon(playerid, 30, 250);
SendClientMessage(playerid, 0x2641FEAA, "You have succesfully buyed a Shownoff - shotgun");
WARNING : This One Has Colors That have Codes If you don't have it add this at begening :
Код:
//COLOR_WHITE 		0xFFFFFFFF
//COLOR_GREY          0xAFAFAFAA
//COLOR_GREEN         0x9EC73DAA
//COLOR_GROVE         0x00FF00FF
//COLOR_RED           0xAA3333AA
//COLOR_LIGHTRED      0xFF6347AA
//COLOR_LIGHTBLUE     0x33CCFFAA
//LIGHTGREEN          0x9ACD32AA
//COLOR_YELLOW        0xDABB3EAA
//COLOR_YELLOW2       0xF5DEB3AA
//COLOR_PURPLE        0xC2A2DAAA
//COLOR_DBLUE         0x2641FEAA
//COLOR_BLUE          0x2641FEAA
//COLOR_DARKNICERED   0x9D000096
//COLOR_LIGHT_BLUE    0x9FB1EEAA
if i helped You Tell me and thank me
if there is any problem please Be Free To tell me
Reply
#7

so that helped?
Reply
#8

Yes, it worked tyvm! I got it working for the shop as well
Reply
#9

good
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)