get array text
#1

Hello SA:MP Community
I come from Liberty Unleashed ( A Grand Theft Auto III Multiplayer ) I was scripting there in squirrel, and now i see samp ( im new here ), and started to script my very first script in pawn here.

I created an array

Код:
new PlayerHealth[100];
new PlayerArmour[100];
stock MessagePlayer(message[],playerid)
{
	SendClientMessage(playerid,0xFFFFFFFF,message);
}
public OnPlayerCommandText(playerid, cmdtext[])
{
	if ( strcmp("/health" ,cmdtext,true,10)==0)
	{
	    
	    MessagePlayer("Your health in array: "+PlayerHealth[playerid],playerid);  // HERE ERROR expected token string end but found identifier
	}
}
public OnPlayerUpdate(playerid)
{
  PlayerHealth[playerid] = GetPlayerHealth(playerid);
  PlayerArmour[playerid] = GetPlayerArmour(playerid);

}
I'm getting a error while i try to compile (expected token string end but found identifier) in that MessagePlayer line as you can see. The MessagePlayer works normally, the error appears in that PlayerHealth array
What did i do wrong?
Reply
#2

First of all GetPlayerArmour returns value to a float. To use float in pawn, you have to indicate that with a tag:
pawn Код:
new Float:PlayerHealth[100];
new Float:PlayerArmour[100];
Also, use MAX_PLAYERS constant to create array for all players for future proofing:
pawn Код:
new Float:PlayerHealth[MAX_PLAYERS];
new Float:PlayerArmour[MAX_PLAYERS];
You can't concat strings like that in PAWN, unfortunately.
If you want to concat string and anything else than a string, use format:
pawn Код:
new message[64];
format(message, sizeof message, "%s %.2f", "Your health in array", PlayerHealth[playerid]);
MessagePlayer(message);
If you want to join two strings, use strcat:
pawn Код:
new first[32] = "Hello ";
static const second[] = "there";
strcat(first, second); //Now "first" is "Hello there".
pawn is full of surprises and limitations, so watch out and ask in this forum any other questions (I'd also recommend googling for "Your problem site:forum.sa-mp.com" as forum search sucks)
Reply
#3

Add to what Misur said:

There's no need to do this

PHP код:
public OnPlayerUpdate(playerid)
{
  
PlayerHealth[playerid] = GetPlayerHealth(playerid);
  
PlayerArmour[playerid] = GetPlayerArmour(playerid);

As this would be calling too frequent ( https://sampwiki.blast.hk/wiki/OnPlayerUpdate )

Read up some more on http://wiki.sa-mp.com
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)