is there a way to shorten this?
#5

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
Reply


Messages In This Thread
is there a way to shorten this? - by Kitten - 16.10.2010, 23:15
Re: is there a way to shorten this? - by MBX97 - 16.10.2010, 23:18
Re: is there a way to shorten this? - by Las Venturas CNR - 16.10.2010, 23:18
Re: is there a way to shorten this? - by Kitten - 16.10.2010, 23:20
Re: is there a way to shorten this? - by JaTochNietDan - 16.10.2010, 23:21
Re: is there a way to shorten this? - by Las Venturas CNR - 16.10.2010, 23:22
Re: is there a way to shorten this? - by Kitten - 16.10.2010, 23:23
Re: is there a way to shorten this? - by Kitten - 16.10.2010, 23:36
Re: is there a way to shorten this? - by JaTochNietDan - 16.10.2010, 23:38
Re: is there a way to shorten this? - by Ritchie999 - 16.10.2010, 23:39

Forum Jump:


Users browsing this thread: 4 Guest(s)