is there a way to shorten this? -
Kitten - 16.10.2010
Solved
Re: is there a way to shorten this? -
MBX97 - 16.10.2010
i don't think so but any way , its cool that way
Re: is there a way to shorten this? -
Las Venturas CNR - 16.10.2010
Shorten as in line count:
pawn Код:
if(cTeam[playerid] == TEAM_SOLIDER || cTeam[playerid] == TEAM_POLICE || cTeam[playerid] == TEAM_ZOMBIE || cTeam[playerid] == TEAM_ZOMBIE2)
{
SendClientMessage(playerid,COLOR_WHITE,"You are not a medic!");
}
return 1;
}
Sorry, forum made indents look awful...
Re: is there a way to shorten this? -
Kitten - 16.10.2010
Solved
Re: is there a way to shorten this? -
JaTochNietDan - 16.10.2010
I find that piece of code very confusing, well a few tips anyway.
pawn Код:
if(cTeam[playerid] == TEAM_SOLIDER) // Doing nothing here?
else if(cTeam[playerid] == TEAM_POLICE) // or here?
else if(cTeam[playerid] == TEAM_ZOMBIE) // or here?
else if(cTeam[playerid] == TEAM_ZOMBIE2) SendClientMessage(playerid,COLOR_WHITE,"You are not a medic!");
Now for one thing, you should be using else if, because you can't be in more than one team, right? So why check the rest if he is in team soldier, police etc.
Then the part where you send the message is just a shorter if statement, no need for brackets unless you need to write multiple functions within the if statement.
Although none of this is actually changing how much code execution per-say, except for the else if changes.
Now about the code itself, if I guess correctly, you want it to see if the person is a medic or not? Well why all of these checks, you could just do
pawn Код:
if(cTeam[playerid] != TEAM_MEDIC) SendClientMessage(playerid,COLOR_WHITE,"You are not a medic!");
!= means not equal to.
Hope that helps
Re: is there a way to shorten this? -
Las Venturas CNR - 16.10.2010
Quote:
Originally Posted by Kitten
thanks i never notice you can do that l l
|
Yeah, || can be used for a lot of stuff.
Ex:
pawn Код:
//add 10x Nitro if the player is in a car. Might be called on a command.
new vehicle;
vehicle = GetPlayerVehicleID(playerid);
if(vehicle == 0 || vehicle == 12 || vehicle == 89)
{
AddVehicleComponent(vehicle, 1010);
}
EDIT:
Oh, yeah, damn forgot about !=
Re: is there a way to shorten this? -
Kitten - 16.10.2010
Solved
Re: is there a way to shorten this? -
Kitten - 16.10.2010
Solved
Re: is there a way to shorten this? -
JaTochNietDan - 16.10.2010
Okay have a look at this:
pawn Код:
if(cTeam[playerid] == TEAM_MEDIC) // Useless line...remove it
if(cTeam[playerid] != TEAM_MEDIC) return SendClientMessage(playerid,COLOR_WHITE,"You are not a medic!");
else
{ // rest of code
Why return? It'll stop the execution of code in OnPlayerCommandText, therefore it won't say Unknown Command unless SendClientMessage returns 0, which it won't.
Re: is there a way to shorten this? -
Ritchie999 - 16.10.2010
Quote:
Originally Posted by Kitten
got a problem here why isnt this working this when other team that is not a medic it says unknown command
pawn Код:
new index, cmd[20]; cmd = strtok(cmdtext, index); if (strcmp(cmd, "/healhim", true) == 0) if(cTeam[playerid] == TEAM_MEDIC) if(cTeam[playerid] != TEAM_MEDIC) SendClientMessage(playerid,COLOR_WHITE,"You are not a medic!"); else { new tmp[20], id; tmp = strtok(cmdtext, index); if (strlen(tmp)) { id = strval(tmp); if (IsPlayerConnected(id)) { SetPlayerHealth(id, 100.0); SendClientMessage(id, 0x00FF00AA, "You have been healed by a Medic Survivor"); SendClientMessage(playerid, 0x00FF00AA, "You Have Healed The player"); } else { SendClientMessage(playerid, 0xFF0000AA, "Player not found"); } } else { SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/heal <playerid>\""); } return 1; }
|
Someone correct me if i am wrong, but you put
pawn Код:
if(cTeam[playerid] != TEAM_MEDIC) SendClientMessage(playerid,COLOR_WHITE,"You are not a medic!")
in the wrong place..
Supposed to be like
pawn Код:
{
else if(cTeam[playerid] != TEAM_MEDIC) SendClientMessage(playerid,COLOR_WHITE,"You are not a medic!");
}
Excuse the sloppy identation