Player's ID 2 - invalid user id -
Qpel - 12.02.2015
Hello, i have problem, that then i call command /givexp and writes id 2, it says: Invalid User id.
With playerID 0 , 1 or 3 - OK. Error calls only with id 2
Code:
Код:
CMD:givexp(playerid, params[])
{
new giveplayerid, ExperienceCount;
giveplayerid = ReturnUser(params);
if(AccountInfo[playerid][AdminLevel] >= 4 || IsPlayerAdmin(playerid) || AccountInfo[playerid][Emigrator] == 1)
{
if(AccountInfo[playerid][AdminOnDuty] == 0)
{
SendClientMessage(playerid, -1, ""#COL_SERVER"* (Admin On Duty)");
return 1;
}
if(sscanf(params, "ud", giveplayerid, ExperienceCount)) return SendClientMessage(playerid, -1, "{F2F2F2}Naudojimas: "#COL_CMD"/givexp [Nick/Player ID] [XP]");
if(!IsPlayerConnected(giveplayerid)) return SendClientMessage(playerid, -1, ""#COL_ERROR"Invalid User ID.");
new String[128];
format(String, sizeof(String), ""#COL_GREEN"You given{AEB404}%s "#COL_GREEN"xp {AEB404}%i", PlayerName(giveplayerid), ExperienceCount);
SendClientMessage(playerid, -1, String);
format(String, sizeof(String), ""#COL_GREEN"{AEB404}%s "#COL_GREEN"gives you {AEB404}%i "#COL_GREEN"xp!", PlayerName(playerid), ExperienceCount);
SendClientMessage(giveplayerid, -1, String);
AccountInfo[giveplayerid][Experience] += ExperienceCount;
SetPlayerScore(giveplayerid, AccountInfo[giveplayerid][Experience]);
}
else
{
OnPlayerCommandText(playerid, "UnknownCommand");
}
return 1;
}
Sorry for my bad english.
Re: Player's ID 2 - invalid user id -
Ryan_Bowe - 12.02.2015
Let me see "ReturnUser(params);".
Re: Player's ID 2 - invalid user id -
Qpel - 12.02.2015
Quote:
Originally Posted by Ryan_Bowe
Let me see "ReturnUser(params);".
|
Код:
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
}
Re: Player's ID 2 - invalid user id -
Qpel - 13.02.2015
any help?
Re: Player's ID 2 - invalid user id -
Qpel - 13.02.2015
ok, i deleted line "giveplayerid = ReturnUser(params);", but it's the same.. I can't givexp if player's id - 2..
Re: Player's ID 2 - invalid user id -
Qpel - 14.02.2015
any help?
Re: Player's ID 2 - invalid user id -
Karan007 - 14.02.2015
If You Want To GiveExp To The ID 2 Simply Tell The Player To Relog And When He Logins Again The PlayerID Will Be Changed And GiveExp To That Player.
Re: Player's ID 2 - invalid user id -
Qpel - 15.02.2015
Relog is not solution to this problem.