SA-MP Forums Archive
expected token - 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)
+--- Thread: expected token (/showthread.php?tid=649585)



expected token - ivndosos - 11.02.2018

Код:
	   if(response)
	   {
		   switch(listitem)
		   {
			  case 0:SellWeapon(playerid, 15, 24, 100);
			  case 1:SellWeapon(playerid, 10, 25, 40);
			  case 2:SellWeapon(playerid, 40, 27,  100);
			  case 3:SellWeapon(playerid, 10, 31,  90);
			  case 4:SellWeapon(playerid, 30, 34, 30);
			  case 5:SellWeapon(playerid, SetPlayerHealth(playerid, 100);
		   }
	   }
	}
    return 1;
}
line
Код:
case 5:SellWeapon(playerid, SetPlayerHealth(playerid, 100);
error
Код:
C:\Users\yan\Desktop\LS DM\gamemodes\DBv1.pwn(1740) : error 001: expected token: ",", but found ";"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.



Re: expected token - Mugala - 11.02.2018

wait, what is this? this code in case 5 is totally wrong, u must only use SetPlayerHealth(playerid, 100); or you can use this code after SellWeapon.


Re: expected token - ivndosos - 11.02.2018

this seems to work out

Код:
			  case 5:SetPlayerHealth(playerid, 100);
but since its different i dont know how to set the price with points


Re: expected token - Mugala - 11.02.2018

can u show me a SellWeapon script?


Re: expected token - XxBaDxBoYxX - 11.02.2018

from this line
Код:
case 4:SellWeapon(playerid, 30, 34, 30);
Your "SellWeapon" function requires 4 parameters.

Код:
Sellweapon(playerid, parameter 2, parameter 3, parameter 4)
In case 5, you are trying to issue it with 2 parameters only.


Using SetPlayerHealth within another function is not a problem since it would execute then return a value
(either 1 for success or 0 for failure)

What do you need to do?

Fix that case and fill it with enough parameters. then try to compile.
That should make your script compile but there's still a possibility for a runtime error


Re: expected token - ivndosos - 11.02.2018

Код:
stock SellWeapon(playerid, points, weapon, ammo)
{
   new ppoints = GetPlayerPoints(playerid);
   if(ppoints>=points)
   {
	  new string[80], weaponname[32];
	  GivePlayerPoints(playerid, -points);
	  GetPlayerPoints(playerid);
	  GivePlayerWeapon(playerid, weapon,ammo);
	  
	  GetWeaponName(weapon, weaponname, sizeof(weaponname));
	  format(string, sizeof(string), "{c3c3c3}* You have bought %s with %i ammo for %i points", weaponname, ammo, points);
	  return SendClientMessage(playerid, -1, string);
    }
  	else
	{
	SendClientMessage(playerid, -1,"{c3c3c3}* You don't have enough points to buy this item !");
  	ShowPlayerDialog(playerid, 8, DIALOG_STYLE_TABLIST_HEADERS, "Market",
	"Weapon \tPrice \tAmmo \tSlots\n\
	Desert Eagle\t{4286f4}15 Points\t100 \tInfinite\n\
	Shotgun\t{4286f4}10 Points\t40\tInfinite\n\
	Spas\t{4286f4}40 Points\t100\tInfinite\n\
	M4\t{4286f4}10 Points\t90\tInfinite\n\
	Sniper\t{4286f4}30 Points\t30\tInfinite\n\
	Full Health\t{4286f4}150 Points\t-\tInfinite",
	"Buy", "Leave");
	return 1;
}
}



Re: expected token - Mugala - 11.02.2018

okay I have added a weaponid 100, which gives a player health with this code.

SellWeapon(playerid, 5, 100, 50); // for 5 points, 50hp
SellWeapon(playerid, 10, 100, 100); // for 10 points, 100hp
PHP код:
stock SellWeapon(playeridpointsweaponammo)
{
   new 
ppoints GetPlayerPoints(playerid);
   if(
ppoints>=points)
   {
        if(
weapon == 100)
        {
            new 
string[80];
            
GivePlayerPoints(playerid, -points);
            
GetPlayerPoints(playerid);
            
SetPlayerHealth(playerid,ammo);
            
format(stringsizeof(string), "{c3c3c3}* You have bought a %d% health for %i points",ammo,points);
            return 
SendClientMessage(playerid, -1string);
        }
        else
        {
            new 
string[80], weaponname[32];
            
GivePlayerPoints(playerid, -points);
            
GetPlayerPoints(playerid);
            
GivePlayerWeapon(playeridweapon,ammo);
            
GetWeaponName(weaponweaponnamesizeof(weaponname));
            
format(stringsizeof(string), "{c3c3c3}* You have bought %s with %i ammo for %i points"weaponnameammopoints);
            return 
SendClientMessage(playerid, -1string);
        }    
    }
    else
    {
        
SendClientMessage(playerid, -1,"{c3c3c3}* You don't have enough points to buy this item !");
        
ShowPlayerDialog(playerid8DIALOG_STYLE_TABLIST_HEADERS"Market",
        
"Weapon \tPrice \tAmmo \tSlots\n\
        Desert Eagle\t{4286f4}15 Points\t100 \tInfinite\n\
        Shotgun\t{4286f4}10 Points\t40\tInfinite\n\
        Spas\t{4286f4}40 Points\t100\tInfinite\n\
        M4\t{4286f4}10 Points\t90\tInfinite\n\
        Sniper\t{4286f4}30 Points\t30\tInfinite\n\
        Full Health\t{4286f4}150 Points\t-\tInfinite"
,
        
"Buy""Leave");
        return 
1;
    }




Re: expected token - Dayrion - 11.02.2018

You missed a ')', that's why you got «error 001: expected token: ",", but found ";"».


Re: expected token - Mugala - 11.02.2018

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
You missed a ')', that's why you got «error 001: expected token: ",", but found ";"».
yeah actually he missed it but look at this code, it's totally wrong, fixing this one error doesn't helps him.


Re: expected token - ivndosos - 11.02.2018

Quote:
Originally Posted by Mugala
Посмотреть сообщение
okay I have added a weaponid 100, which gives a player health with this code.

SellWeapon(playerid, 5, 100, 50); // for 5 points, 50hp
SellWeapon(playerid, 10, 100, 100); // for 10 points, 100hp
PHP код:
stock SellWeapon(playeridpointsweaponammo)
{
   new 
ppoints GetPlayerPoints(playerid);
   if(
ppoints>=points)
   {
        if(
weapon == 100)
        {
            new 
string[80];
            
GivePlayerPoints(playerid, -points);
            
GetPlayerPoints(playerid);
            
SetPlayerHealth(playerid,ammo);
            
format(stringsizeof(string), "{c3c3c3}* You have bought a %d% health for %i points",ammo,points);
            return 
SendClientMessage(playerid, -1string);
        }
        else
        {
            new 
string[80], weaponname[32];
            
GivePlayerPoints(playerid, -points);
            
GetPlayerPoints(playerid);
            
GivePlayerWeapon(playeridweapon,ammo);
            
GetWeaponName(weaponweaponnamesizeof(weaponname));
            
format(stringsizeof(string), "{c3c3c3}* You have bought %s with %i ammo for %i points"weaponnameammopoints);
            return 
SendClientMessage(playerid, -1string);
        }    
    }
    else
    {
        
SendClientMessage(playerid, -1,"{c3c3c3}* You don't have enough points to buy this item !");
        
ShowPlayerDialog(playerid8DIALOG_STYLE_TABLIST_HEADERS"Market",
        
"Weapon \tPrice \tAmmo \tSlots\n\
        Desert Eagle\t{4286f4}15 Points\t100 \tInfinite\n\
        Shotgun\t{4286f4}10 Points\t40\tInfinite\n\
        Spas\t{4286f4}40 Points\t100\tInfinite\n\
        M4\t{4286f4}10 Points\t90\tInfinite\n\
        Sniper\t{4286f4}30 Points\t30\tInfinite\n\
        Full Health\t{4286f4}150 Points\t-\tInfinite"
,
        
"Buy""Leave");
        return 
1;
    }

wow that's a nice way detect that, however I'm sitting for about 20 minutes trying to figure out how to do so (I've tried few codes didn't really work)

so your code works perfectly it's just that doesn't matter of how much points I have I can still buy it even if its -20