Need help with /playerinfo command
#1

Hello, uhh as you see, I was trying to make a /playerinfo command, that basically, gets the playerinfo that is specified, but I have been unsucessful, because of my bad coding, and not knowing what to do.

This is what it looks like

Код:
 if (strcmp("/playerinfo", cmdtext, true, 10) == 0 && IsPlayerAdmin(playerid))
 {
  tmp = strtok(cmdtext, idx);
	if(!strlen(tmp))
	{
	  SendClientMessage(playerid, 0xFF0000FF, "USAGE : /playerinfo ID");
	  return 1;
	}
	new giveplayerid = ReturnUser(tmp);
	if (giveplayerid != INVALID_PLAYER_ID)
	{
		new pName[MAX_PLAYER_NAME];
		new string[128];
	  new string1[128];
	  new string2[128];
	  new string3[128];
		{
	    SendClientMessage(playerid, 0xFF000A00, "-----------------------------------------------");
			format (string, sizeof(string), "Information of Player : %s",pName);
	    SendClientMessage(playerid, 0xFF0000FF, string);
	    SendClientMessage(playerid, 0xFF000A00, "-----------------------------------------------");
	    format (string1, sizeof(string1), "Armour : %i",GetPlayerArmour(playerid, 100.00);
	    SendClientMessage(playerid, 0xFAFAFAFA, string1);
	    format (string2, sizeof(string2), "Cash : %i",GetPlayerMoney(playerid);
	    SendClientMessage(playerid, 0xFAFAFAFA, string2);
	    format (string3, sizeof(string3), "Health : %i",GetPlayerHealth(playerid, 100.00);
			SendClientMessage(playerid, 0xFAFAFAFA, string3);
  			SendClientMessage(playerid, 0xFF000A00, "-----------------------------------------------");
		}
		else SendClientMessage(playerid, 0xFF0000FF, "This player isnt active !"
	}
	else return 0;
	return 1;
	}
	return 0;
}
for some reason I have a very strong feeling I did something wrong here, because this is what the compiler says :

Код:
C:\Documents and Settings\Justin\Desktop\SAMP\gamemodes\BGB_CLAN_GAMEMODE.pwn(160) : error 017: undefined symbol "idx"
C:\Documents and Settings\Justin\Desktop\SAMP\gamemodes\BGB_CLAN_GAMEMODE.pwn(166) : error 017: undefined symbol "ReturnUser"
C:\Documents and Settings\Justin\Desktop\SAMP\gamemodes\BGB_CLAN_GAMEMODE.pwn(179) : error 035: argument type mismatch (argument 2)
C:\Documents and Settings\Justin\Desktop\SAMP\gamemodes\BGB_CLAN_GAMEMODE.pwn(179) : error 001: expected token: ",", but found ";"
C:\Documents and Settings\Justin\Desktop\SAMP\gamemodes\BGB_CLAN_GAMEMODE.pwn(181) : error 001: expected token: ",", but found ";"
C:\Documents and Settings\Justin\Desktop\SAMP\gamemodes\BGB_CLAN_GAMEMODE.pwn(183) : error 035: argument type mismatch (argument 2)
C:\Documents and Settings\Justin\Desktop\SAMP\gamemodes\BGB_CLAN_GAMEMODE.pwn(183) : error 001: expected token: ",", but found ";"
C:\Documents and Settings\Justin\Desktop\SAMP\gamemodes\BGB_CLAN_GAMEMODE.pwn(187) : error 029: invalid expression, assumed zero
C:\Documents and Settings\Justin\Desktop\SAMP\gamemodes\BGB_CLAN_GAMEMODE.pwn(187 -- 188) : error 001: expected token: ",", but found "}"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


9 Errors.
Also, this is the strtok function :

Код:
stock strtok(const string[], &index,seperator=' ')
{
	new length = strlen(string);
	new offset = index;
	new result[128];
	while ((index < length) && (string[index] != seperator) && ((index - offset) < (sizeof(result) - 1)))
	{
		result[index - offset] = string[index];
		index++;
	}

	result[index - offset] = EOS;
	if ((index < length) && (string[index] == seperator))
	{
		index++;
	}
	return result;
}
any help would be appreciated.
Reply
#2

Add on the start of the command
Код:
new idx;
and and somewhere in the script
pawn Код:
ReturnUser(text[], playerid = INVALID_PLAYER_ID)
{
    new pos = 0;
    while (text[pos] < 0x21) // Strip out leading spaces
    {
        if (text[pos] == 0) return INVALID_PLAYER_ID; // No passed text
        pos++;
    }
    new userid = INVALID_PLAYER_ID;
    if (IsNumeric(text[pos])) // Check whole passed string
    {
        // If they have a numeric name you have a problem (although names are checked on id failure)
        userid = strval(text[pos]);
        if (userid >=0 && userid < MAX_PLAYERS)
        {
            if(!IsPlayerConnected(userid))
            {
                /*if (playerid != INVALID_PLAYER_ID)
                {
                    SendClientMessage(playerid, 0xFF0000AA, "User not connected");
                }*/

                userid = INVALID_PLAYER_ID;
            }
            else
            {
                return userid; // A player was found
            }
        }
        /*else
        {
            if (playerid != INVALID_PLAYER_ID)
            {
                SendClientMessage(playerid, 0xFF0000AA, "Invalid user ID");
            }
            userid = INVALID_PLAYER_ID;
        }
        return userid;*/

        // Removed for fallthrough code
    }
    // They entered [part of] a name or the id search failed (check names just incase)
    new len = strlen(text[pos]);
    new count = 0;
    new name[MAX_PLAYER_NAME];
    for (new i = 0; i < MAX_PLAYERS; i++)
    {
        if (IsPlayerConnected(i))
        {
            GetPlayerName(i, name, sizeof (name));
            if (strcmp(name, text[pos], true, len) == 0) // Check segment of name
            {
                if (len == strlen(name)) // Exact match
                {
                    return i; // Return the exact player on an exact match
                    // Otherwise if there are two players:
                    // Me and MeYou any time you entered Me it would find both
                    // And never be able to return just Me's id
                }
                else // Partial match
                {
                    count++;
                    userid = i;
                }
            }
        }
    }
    if (count != 1)
    {
        if (playerid != INVALID_PLAYER_ID)
        {
            if (count)
            {
                SendClientMessage(playerid, 0xFF0000AA, "Multiple users found, please narrow earch");
            }
            else
            {
                SendClientMessage(playerid, 0xFF0000AA, "No matching user found");
            }
        }
        userid = INVALID_PLAYER_ID;
    }
    return userid; // INVALID_USER_ID for bad return
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)