23.10.2012, 10:57
This Command Doesn't work(like all commands like this), I think the reason it because I try to use the command on player, and I do somthing wrong..
The Command:
The Stocks:
What The Problem Please Help Me ..
The Command:
PHP код:
if(strcmp(cmd,"/MakeHelper",true) == 0)
{
if(IsPlayerAdmin(playerid) || PlayerInfo[playerid][Admin] >= 1338 || PlayerInfo[playerid][Helper] >= 5)
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))return SendClientMessage(playerid, -1, "USAGE: /MakeHelper [PlayerID] [HelperLevel]");
id = ReturnUser(tmp);
tmp = strtok(cmdtext, idx);
new level = strval(tmp);
if(id == INVALID_PLAYER_ID)return SendClientMessage(playerid, -1, "Invalid Player ID");
PlayerInfo[id][Helper] = level;
DOF2_SetInt(pFile(id), "Helper", PlayerInfo[id][Helper]);
DOF2_SaveFile();
if(PlayerInfo[playerid][Admin] >= 1338)
{
format(string, sizeof(string), "Admin %s Give To You Helper Level: %d",sendername, level);
SendClientMessage(id, -1, string);
format(string, sizeof(string), "Admin %s Give To %s Helper Level: %d",sendername, giveplayer, level);
ABroadCast(COLOR_YELLOW, string, 1);
}
if(PlayerInfo[playerid][Helper] >= 5)
{
format(string, sizeof(string), "Helper %s Give To You Helper Level: %d",sendername, level);
SendClientMessage(id, -1, string);
format(string, sizeof(string), "Helper %s Give To %s Helper Level: %d",sendername, giveplayer, level);
HBroadCast(COLOR_YELLOW, string, 1);
}
} else { DenyMessage(playerid); }
return 1;
}
PHP код:
#include <a_samp>
strtok(const string[], &index)
{
new length = strlen(string);
while ((index < length) && (string[index] <= ' ')) index++;
new offset = index, result[20];
while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
return result;
}
stock 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))
{
userid = INVALID_PLAYER_ID;
}
else
{
return userid; // A player was found
}
}
}
// 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
}
else // Partial match
{
count++;
userid = i;
}
}
}
}
if (count != 1)
{
if (playerid != INVALID_PLAYER_ID)
{
if (count)
{
SendClientMessage(playerid, 0xFF0000AA, "Multiple users found, please narrow search.");
}
else
{
SendClientMessage(playerid, 0xFF0000AA, "No matching user found.");
}
}
userid = INVALID_PLAYER_ID;
}
return userid; // INVALID_PLAYER_ID for bad return
}
IsNumeric(const string[])
{
for (new i = 0, j = strlen(string); i < j; i++)
{
if (string[i] > '9' || string[i] < '0') return 0;
}
return 1;
}
stock strrest(const string[],index)
{
new length = strlen(string),offset = index,result[256];
while((index < length) && ((index - offset) < (sizeof(result) - 1)) && (string[index] > '\r')) result[index - offset] = string[index],index++;
result[index - offset] = EOS;
if(result[0] == ' ' && string[0] != ' ') strdel(result,0,1);
return result;
}
![Sad](images/smilies/sad.gif)