20.05.2012, 05:33
Hello everyone,
I was converting a game mode for a Client from strcmp to zcmd/sscanf. Im almost done with all the command but there was this particular command which got me thinking , how to convert it to zcmd/sscanf. if anyone can convert it and paste the working command. Will highly appreciate it as well as will Rep+6 you for helping me.
Here the CMD:
I was converting a game mode for a Client from strcmp to zcmd/sscanf. Im almost done with all the command but there was this particular command which got me thinking , how to convert it to zcmd/sscanf. if anyone can convert it and paste the working command. Will highly appreciate it as well as will Rep+6 you for helping me.
Here the CMD:
pawn Код:
if(strcmp(cmd,"/irc",true)==0)
{
if(IsPlayerConnected(playerid))
{
new x_nr[128];
x_nr = strtok(cmdtext, idx);
if(!strlen(x_nr)) {
SendClientMessage(playerid, COLOR_WHITE, "USAGE: (/irc join [channelnr] or /irc join [channelnr] [password]) (/irc Leave) (/irc Admins)");
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /irc [name] [channelnr]");
SendClientMessage(playerid, COLOR_WHITE, "Available names: MOTD, Password, NeedPass, Lock, Kick, Status");
return 1;
}
if(strcmp(x_nr,"join",true) == 0)
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /irc join [channelnr] or /irc join [channelnr] [password]");
return 1;
}
new channel = strval(tmp);
if(channel < 1 || channel > SCRIPT_MAXIRC) { SendClientMessage(playerid, COLOR_GREY, " Channel Number can't be below 1 or above the amount !"); return 1; }
channel -= 1;
if(IRCInfo[channel][iLock] == 0)
{
if(IRCInfo[channel][iNeedPass] == 0)
{
JoinChannelNr(playerid, channel);
}
else
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_WHITE, "There's a password required to join this Channel.");
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /irc join [channelnr] [password]");
return 1;
}
JoinChannel(playerid,channel,tmp);
}
}
else
{
SendClientMessage(playerid, COLOR_GREY, " That Channel is Locked, please choose a different one !");
return 1;
}
}
else if(strcmp(x_nr, "create", true) == 0)
{
GetPlayerName(playerid, sendername, sizeof(sendername));
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /irc create [number]");
return 1;
}
new channel;
channel = strval(tmp);
if(channel < 1 || channel > SCRIPT_MAXIRC) { SendClientMessage(playerid, COLOR_GREY, " Channel Number can't be below 1 or above the amount !"); return 1; }
if(PlayerInfo[playerid][pConnectTime] < 50)
{
SendClientMessage(playerid, COLOR_GRAD2, "You must have 50 and over time in FC to use this !");
return 1;
}
for(new i = 0; i < sizeof(IRCInfo); i++)
{
if(strcmp(IRCInfo[i][iAdmin], sendername, true) == 0)
{
format(string, sizeof(string), "You already have control over IRC Channel: %d", i);
SendClientMessage(playerid, COLOR_GRAD2, string);
return 1;
}
}
if(strcmp(IRCInfo[channel][iAdmin], "None", true) == 0)
{
GetPlayerName(playerid, sendername, sizeof(sendername));
format(string, sizeof(string), "you are now an IRC Admin over Channel %d.", channel);
SendClientMessage(playerid, COLOR_WHITE, string);
format(string, sizeof(string), "%s", sendername);
strmid(IRCInfo[channel][iAdmin], string, 0, strlen(string), 255);
IRCInfo[channel][iNeedPass] = 0; IRCInfo[channel][iLock] = 0;
return 1;
}
else
{
SendClientMessage(playerid, COLOR_GRAD2, "This channel is taken already !");
}
return 1;
}
else if(strcmp(x_nr,"status",true) == 0)
{
for(new i = 0; i < sizeof(IRCInfo); i++)
{
if(strcmp(IRCInfo[i][iAdmin], "None", true) == 0)
{
return 1;
}
else
{
format(string, sizeof(string), "Channel %d: %d Players Connected.",i + 1, IRCInfo[i][iPlayers]);
SendClientMessage(playerid, COLOR_WHITE, string);
}
}
return 1;
}
else if(strcmp(x_nr,"password",true) == 0)
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /irc password [channelnr] [password]");
return 1;
}
new channel = strval(tmp);
if(channel < 1 || channel > SCRIPT_MAXIRC) { SendClientMessage(playerid, COLOR_GREY, " Channel Number can't be below 1 or above the amount !"); return 1; }
channel -= 1;
new wstring[128];
GetPlayerName(playerid, sendername, sizeof(sendername));
format(string, sizeof(string), "%s", sendername);
strmid(wstring, string, 0, strlen(string), 255);
if(strcmp(IRCInfo[channel][iAdmin],wstring, true ) == 0 )
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /irc password [channelnr] [password]");
return 1;
}
strmid(IRCInfo[channel][iPassword], tmp, 0, strlen(tmp), 255);
format(string, sizeof(string), "You've changed the IRC Channel's Password to: %s.",IRCInfo[channel][iPassword]);
SendClientMessage(playerid, COLOR_YELLOW, string);
return 1;
}
else
{
SendClientMessage(playerid, COLOR_GREY, " You are not the Admin of that Channel !");
return 1;
}
}
else if(strcmp(x_nr,"needpass",true) == 0)
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /irc needpass [channelnr]");
return 1;
}
new channel = strval(tmp);
if(channel < 1 || channel > SCRIPT_MAXIRC) { SendClientMessage(playerid, COLOR_GREY, " Channel Number can't be below 1 or above the amount !"); return 1; }
channel -= 1;
new wstring[128];
GetPlayerName(playerid, sendername, sizeof(sendername));
format(string, sizeof(string), "%s", sendername);
strmid(wstring, string, 0, strlen(string), 255);
if(strcmp(IRCInfo[channel][iAdmin],wstring, true ) == 0 )
{
if(IRCInfo[channel][iNeedPass] != 0)
{
IRCInfo[channel][iNeedPass] = 0;
SendClientMessage(playerid, COLOR_YELLOW, "Players won't have to fill in a password in order to join the IRC Channel now.");
}
else
{
IRCInfo[channel][iNeedPass] = 1;
SendClientMessage(playerid, COLOR_YELLOW, "Players must fill in a password in order to join the IRC Channel now.");
}
return 1;
}
else
{
SendClientMessage(playerid, COLOR_GREY, " You are not the Admin of that Channel !");
return 1;
}
}
else if(strcmp(x_nr,"lock",true) == 0)
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /irc lock [channelnr]");
return 1;
}
new channel = strval(tmp);
if(channel < 1 || channel > SCRIPT_MAXIRC) { SendClientMessage(playerid, COLOR_GREY, " Channel Number can't be below 1 or above the amount !"); return 1; }
channel -= 1;
new wstring[128];
GetPlayerName(playerid, sendername, sizeof(sendername));
format(string, sizeof(string), "%s", sendername);
strmid(wstring, string, 0, strlen(string), 255);
if(strcmp(IRCInfo[channel][iAdmin],wstring, true ) == 0 )
{
if(IRCInfo[channel][iLock] != 0)
{
IRCInfo[channel][iLock] = 0;
SendClientMessage(playerid, COLOR_YELLOW, "You've unlocked the IRC Channel.");
}
else
{
IRCInfo[channel][iLock] = 1;
SendClientMessage(playerid, COLOR_YELLOW, "You've locked the IRC Channel.");
}
return 1;
}
else
{
SendClientMessage(playerid, COLOR_GREY, " You are not the Admin of that Channel !");
return 1;
}
}
else if(strcmp(x_nr,"motd",true) == 0)
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /irc motd [channelnr] [motdtext]");
return 1;
}
new channel = strval(tmp);
if(channel < 1 || channel > SCRIPT_MAXIRC) { SendClientMessage(playerid, COLOR_GREY, " Channel Number can't be below 1 or above the amount !"); return 1; }
channel -= 1;
new wstring[128];
GetPlayerName(playerid, sendername, sizeof(sendername));
format(string, sizeof(string), "%s", sendername);
strmid(wstring, string, 0, strlen(string), 255);
if(strcmp(IRCInfo[channel][iAdmin],wstring, true ) == 0 )
{
new length = strlen(cmdtext);
while ((idx < length) && (cmdtext[idx] <= ' '))
{
idx++;
}
new offset = idx;
new result[128];
while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
{
result[idx - offset] = cmdtext[idx];
idx++;
}
result[idx - offset] = EOS;
if(!strlen(result))
{
SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /irc motd [motdtext]");
return 1;
}
strmid(IRCInfo[channel][iMOTD], result, 0, strlen(result), 255);
SendClientMessage(playerid, COLOR_YELLOW, "You've adjusted the IRC Channel's MOTD Text.");
return 1;
}
else
{
SendClientMessage(playerid, COLOR_GREY, " You are not the Admin of that Channel !");
return 1;
}
}
else if(strcmp(x_nr,"leave",true) == 0)
{
if(PlayerInfo[playerid][pPlayersChannel] < 999)
{
GetPlayerName(playerid, sendername, sizeof(sendername));
format(string, sizeof(string), "* %s has left the Channel.", sendername);
SendIRCMessage(PlayerInfo[playerid][pPlayersChannel], COLOR_GREEN, string);
IRCInfo[PlayerInfo[playerid][pPlayersChannel]][iPlayers] -= 1;
PlayerInfo[playerid][pPlayersChannel] = 999;
return 1;
}
else
{
SendClientMessage(playerid, COLOR_GREY, " You are not in an IRC Channel !");
return 1;
}
}
else if(strcmp(x_nr,"admins",true) == 0)
{
for(new i = 0; i < sizeof(IRCInfo); i++)
{
format(string, sizeof(string), "Channel %d: %s.", i + 1, IRCInfo[i][iAdmin]);
SendClientMessage(playerid, COLOR_WHITE, string);
}
return 1;
}
else if(strcmp(x_nr,"kick",true) == 0)
{
if(PlayerInfo[playerid][pPlayersChannel] == 999)
{
SendClientMessage(playerid, COLOR_GREY, " You are not in an IRC Channel !");
return 1;
}
new wstring[128];
GetPlayerName(playerid, sendername, sizeof(sendername));
format(string, sizeof(string), "%s", sendername);
strmid(wstring, string, 0, strlen(string), 255);
if(strcmp(IRCInfo[PlayerInfo[playerid][pPlayersChannel]][iAdmin],wstring, true ) == 0 )
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /irc kick [playerid/PartOfName]");
return 1;
}
giveplayerid = ReturnUser(tmp);
if(IsPlayerConnected(giveplayerid))
{
if(giveplayerid != INVALID_PLAYER_ID)
{
if(PlayerInfo[giveplayerid][pPlayersChannel] == PlayerInfo[playerid][pPlayersChannel])
{
GetPlayerName(playerid, sendername, sizeof(sendername));
GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
format(string, sizeof(string), "* You've kicked %s out of your IRC Channel.",giveplayer);
SendClientMessage(playerid, COLOR_YELLOW, string);
format(string, sizeof(string), "* You've been kicked out of the IRC Channel by Channel Admin: %s.",sendername);
SendClientMessage(giveplayerid, COLOR_YELLOW, string);
format(string, sizeof(string), "* %s has left the Channel (Kicked).", sendername);
SendIRCMessage(PlayerInfo[playerid][pPlayersChannel], COLOR_GREEN, string);
IRCInfo[PlayerInfo[giveplayerid][pPlayersChannel]][iPlayers] -= 1;
PlayerInfo[giveplayerid][pPlayersChannel] = 999;
}
else
{
SendClientMessage(playerid, COLOR_GREY, " That player is not in your IRC Channel !");
return 1;
}
}
}
else
{
SendClientMessage(playerid, COLOR_GREY, " That player is Offline !");
return 1;
}
}
else
{
SendClientMessage(playerid, COLOR_GREY, " You are not the Admin of the Channel !");
return 1;
}
}
else
{
SendClientMessage(playerid, COLOR_GREY, " Invalid IRC Channel Number ! ");
return 1;
}
}
return 1;
}