SA-MP Forums Archive
[QUESTION/HELP] DCMD Question - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [QUESTION/HELP] DCMD Question (/showthread.php?tid=213048)

Pages: 1 2


Re: [QUESTION/HELP] DCMD Question - Larsey123IsMe - 18.01.2011

Again, THANKS JaTochNietDan

and =/ It is the firt day i script wirh dcmd xD


Re: [QUESTION/HELP] DCMD Question - Alex_Valde - 18.01.2011

You need to watch your coding style. It's a little strange.

pawn Code:
dcmd_setplayerhealth(playerid, params[])
{
    new targetid, amount;
    if(!sscanf(params, "ud", targetid, amount))
    {
        if(IsPlayerConnected(targetid))
        {
            if(amount > 1 && amount < 101)
            {
                new playername[MAX_PLAYER_NAME], targetname[MAX_PLAYER_NAME], string[128];
                GetPlayerName(playerid, playername, sizeof(playername));
                GetPlayerName(targetid, targetname, sizeof(targetname));

                format(string, sizeof(string), "%s(%d) set %s(%d)'s health to %d", targetname, targetid, playername, playerid, amount);
                SendClientMessageToAll(0x50FF05FF, string);

                SetPlayerHealth(playerid, amount);
            }
            else return SendClientMessage(playerid, 0xFFFFFFFF,"Error: Please use |Max|: 100, |Min|: 1");
        }
        else return SendClientMessage(playerid, 0xFF0000AA, "Player not found");
    }
    else return SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/setplayerhealth <playerid> <amount>\"");
    return 1;
}
EDIT: JaTochNietDan already helped you.


Re: [QUESTION/HELP] DCMD Question - JaTochNietDan - 18.01.2011

Quote:
Originally Posted by Larsey123IsMe
View Post
Again, THANKS JaTochNietDan

and =/ It is the firt day i script wirh dcmd xD
Well I recognize the strange syntax, I'm pretty sure I've seen you use it somewhere else before

I've seen you do this:

pawn Code:
if(something != something) SendClientMessage(playerid,color,"Error, can't do that");
{
    print("Can do that!"); // Really can't
}
Those brackets mean nothing, they aren't part of the if statement. This means that the code in them will always be run, even if the if statement is deemed true or false! Proper syntax would be either returning SendClientMessage to stop the rest of the code from running, or using a simple else statement. Like so:

Example #1:

pawn Code:
if(something != something) return SendClientMessage(playerid,color,"Error, can't do that");
print("Can do that!");
Example #2:

pawn Code:
if(something != something) SendClientMessage(playerid,color,"Error, can't do that");
else
{
    print("Can do that!");
}
I hope that helps you with avoiding future syntax problems


Re: [QUESTION/HELP] DCMD Question - Larsey123IsMe - 18.01.2011

Quote:
Originally Posted by JaTochNietDan
View Post
Well I recognize the strange syntax, I'm pretty sure I've seen you use it somewhere else before

I've seen you do this:

pawn Code:
if(something != something) SendClientMessage(playerid,color,"Error, can't do that");
{
    print("Can do that!"); // Really can't
}
Those brackets mean nothing, they aren't part of the if statement. This means that the code in them will always be run, even if the if statement is deemed true or false! Proper syntax would be either returning SendClientMessage to stop the rest of the code from running, or using a simple else statement. Like so:

Example #1:

pawn Code:
if(something != something) return SendClientMessage(playerid,color,"Error, can't do that");
print("Can do that!");
Example #2:

pawn Code:
if(something != something) SendClientMessage(playerid,color,"Error, can't do that");
else
{
    print("Can do that!");
}
I hope that helps you with avoiding future syntax problems
(Y)

You know what? You is AWESOME It helped a lot

And.. Thanks AGAIN! xD ahah :P