23.10.2010, 23:17
Using this system you would need to make a variable in OnPlayerCommandText and store the first part of the string there.
Here you go, I also suggest you change the fight ID variable to an integer, as a large array is quite pointless and a waste of memory. I've made a few other changes to your code also in order to improve it. There's also no need for an IsPlayerConnected check in a command is there? Since a player can't send a command to a server without being connected to it.
You should compare both versions and see what was done differently, and look more into the functions being used to understand it better.
Here you go, I also suggest you change the fight ID variable to an integer, as a large array is quite pointless and a waste of memory. I've made a few other changes to your code also in order to improve it. There's also no need for an IsPlayerConnected check in a command is there? Since a player can't send a command to a server without being connected to it.
pawn Код:
public OnPlayerCommandText(playerid,cmdtext[])
{
new idx,cmd[128];
cmd = strtok(cmdtext,idx);
if(strcmp(cmd, "/fight", true) == 0)
{
new fight_id;
fight_id = strval(strtok(cmdtext, idx));
if(fight_id < 1 || fight_id > 5)
{
SendClientMessage(playerid, COLOR_RED, "ПРИМЕНЕНИЕ: /fight [1-5]");
SendClientMessage(playerid, COLOR_YELLOW2, "Стили: 1-konfu, 2-boxer, 3-gangster, 4-elbow, 5-normal");
return 1;
}
else if(fight_id == 1)
{
SetPlayerFightingStyle(playerid, FIGHT_KARATE);
SendClientMessage(playerid, COLOR_GREEN, "Теперь у вас стиль рукапашного боя 'Конфу'");
}
else if(fight_id == 2)
{
SetPlayerFightingStyle(playerid, FIGHT_BOXING);
SendClientMessage(playerid, COLOR_GREEN, "Теперь у вас стиль рукапашного боя 'Бокс'");
}
else if(fight_id == 3)
{
SetPlayerFightingStyle(playerid, FIGHT_GANGSTER);
SendClientMessage(playerid, COLOR_GREEN, "Теперь у вас стиль рукапашного боя 'Гангстер'");
}
else if(fight_id == 4)
{
SetPlayerFightingStyle(playerid, FIGHT_STYLE_ELBOW);
SendClientMessage(playerid, COLOR_GREEN, "Теперь у вас стиль рукапашного боя 'Бить локтём'");
}
else if(fight_id == 5)
{
SetPlayerFightingStyle(playerid, FIGHT_NORMAL);
SendClientMessage(playerid, COLOR_GREEN, "Теперь у вас стиль рукапашного боя 'Стандартный'");
}
PlayerPlaySound(playerid, 1139, 0.0, 0.0, 0.0);
return 1;
}
return 0;
}

