#include <a_samp>
strtok(const string[], &index)
{
new length = strlen(string);
while ((index < length) && (string[index] <= ' '))
{
index++;
}
new offset = index;
new result[20];
while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
return result;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if(strcmp(cmdtext, "/getip", true) == 0)
{
if(IsPlayerAdmin(playerid))
{
new text[128];
new index;
text = strtok(cmdtext, index);
if(!strlen(text))
{
SendClientMessage(playerid, 0xFFFFFFFF,"Usage: /getip [playerid]");
return 1;
}
new player;
player = strval(text);
if(IsPlayerConnected(player))
{
new string[128];
new name[MAX_PLAYER_NAME];
new IP[20];
GetPlayerName(player, name, sizeof(name));
GetPlayerIp(player, IP, sizeof(IP));
format(string, sizeof(string), "%s's IP: %s", name, IP);
SendClientMessage(playerid, 0xFFFFFFFF, string);
return 1;
}
else return SendClientMessage(playerid, 0xFFFFFFFF,"Player is not connected");
}
else return 0;
}
return 0;
}
Originally Posted by еddy
Ok, I was bored, so I made you the whole filterscript. You must be logged in RCON to use the command. Command = "/getip", script:
pawn Код:
|
strtok(const string[], &index)
{
new length = strlen(string);
while ((index < length) && (string[index] <= ' '))
{
index++;
}
new offset = index;
new result[20];
while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
return result;
}
C:\Documents and Settings\Mario\AT\doc\gamemodes\gm.pwn(14725) : warning 219: local variable "string" shadows a variable at a preceding level C:\Documents and Settings\Mario\AT\doc\gamemodes\gm.pwn(14741) : warning 225: unreachable code C:\Documents and Settings\Mario\AT\doc\gamemodes\gm.pwn(29479) : error 021: symbol already defined: "strtok" |
public OnPlayerCommandText(playerid, cmdtext[]) { new cmd[128],index; cmd = strtok(cmdtext, index); if(strcmp(cmd, "/getip", true) == 0) { if(IsPlayerAdmin(playerid)) { new text[128]; text = strtok(cmdtext, index); if(!strlen(text)) return SendClientMessage(playerid, 0xFFFFFFFF,"Usage: /getip [playerid]"); new player = strval(text); if(IsPlayerConnected(player)) { new string[128]; new name[MAX_PLAYER_NAME]; new IP[20]; GetPlayerName(player, name, sizeof(name)); GetPlayerIp(player, IP, sizeof(IP)); format(string, sizeof(string), "%s's IP: %s", name, IP); SendClientMessage(playerid, 0xFFFFFFFF, string); }else SendClientMessage(playerid, 0xFFFFFFFF,"Player is not connected"); }else SendClientMessage(playerid, 0xFFFFFFFF,"Only for admins !"); return 1; } return 0; }