is there a way to shorten this?
#1

Solved
Reply
#2

i don't think so but any way , its cool that way
Reply
#3

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...
Reply
#4

Solved
Reply
#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
#6

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 !=
Reply
#7

Solved
Reply
#8

Solved
Reply
#9

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.
Reply
#10

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
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)