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


[QUESTION/HELP] DCMD Question - Larsey123IsMe - 18.01.2011

if someone type:
"/healme 2"
"/healme LoL"
or something with "/healme(SPACE)(RANDOM NUMBER/TEXT)"
then this should return "SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/healme\"");"
is that possible? Yes, i guess xD but how O.o

pawn Code:
dcmd_healme(playerid, params[])
{
    if(sscanf(params, "s", playerid)) return SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/healme\"");
    else
    {
        SetPlayerHealth(playerid, 100.0);
        SendClientMessage(playerid, 0x00FF00AA, "You have been healed");
        return 1;
    }
}



Re: [QUESTION/HELP] DCMD Question - Not available - 18.01.2011

What do you mean? Could this work.
pawn Code:
if(sscanf(params, " s", playerid)) return SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/healme\"");



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

You mean something like this?

pawn Code:
dcmd_heal(playerid, params[])
{
        new id;
    if (strlen(params))
    {
        id = strval(params);
        if (IsPlayerConnected(id))
        {
            SetPlayerHealth(id, 100.0);
            SendClientMessage(id, 0x00FF00AA, "You have been healed");
            SendClientMessage(playerid, 0x00FF00AA, "Player healed");
        }
        else
        {
            SendClientMessage(playerid, 0xFF0000AA, "Player not found");
        }
    }
    else
    {
        SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/heal <playerid>\"");
    }
    return 1;
}



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

But then for yourself?


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

pawn Code:
dcmd_healme(playerid, params[])
{
    new
        id;
    if(sscanf(params, "u", id)) return SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/healme\"");
    else
    {
        SetPlayerHealth(id, 100.0);
        SendClientMessage(id, 0x00FF00AA, "You have been healed");
        return 1;
    }
}
If i understood correct that should do it.

EDIT: Just realised its a healme cmd and not healplayer durr.


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

I think you need to change this line
pawn Code:
if(sscanf(params, "s", playerid)) return SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/healme\"");
to
pawn Code:
if(sscanf(params, "u", playerid)) return SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/healme\"");



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

Or this:
pawn Code:
cmd_healme(playerid, params[])
{
    if(isnull(params))
    {
        SetPlayerHealth(playerid, 100.0);
        SendClientMessage(playerid, 0x00FF00AA, "You have been healed");
    }
    else return SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/healme\"");//if he adds ANYTHING after healme this will come up.
    return 1;
}



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

Quote:
Originally Posted by xir
View Post
I think you need to change this line
pawn Code:
if(sscanf(params, "s", playerid)) return SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/healme\"");
to
pawn Code:
if(sscanf(params, "u", playerid)) return SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/healme\"");
Thats wrong. U needs to be id
and he needs to put new id;


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

Quote:
Originally Posted by alpha500delta
View Post
Thats wrong. U needs to be id
and he needs to put new id;
Correct! but.. still...

i dont mean a "/healme <playerid>" command
i mean "/healme" and if he type like "/healme (random things)"
then return SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/healme\"");

pawn Code:
and.. How to:
If the number is more than 100 and less than 1 then this should return:
"SendClientMessage(playerid, 0xFF0000FF, "ERRROR: Max: 100 Minimum: 1);"

Example: "
/heal 1 1000"
1000 = Over the maximum (100) so then the Message (SendClientMessage(playerid, 0xFF0000FF, "
ERRROR: Max: 100 Minimum: 1);) shuld return...

Something Like:
else if(amount <= 1 && amount >= 100) return SendClientMessage(playerid, 0xFF0000FF, "ERRROR: Max: 100 Minimum: 1");
Sorry for bad english, GRRRR


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

I made it quickly so just try it. Should work perfectly though.

pawn Code:
cmd_healme(playerid, params[])
{
    new pID, pHealth;
    if(!sscanf(params, "ui",pID, pHealth))
    {
        if(IsPlayerConnected(pID))
        {
            if(pHealth > 1 || pHealth < 101)
            {
                SetPlayerHealth(pID, pHealth);
                SendClientMessage(pID, 0x00FF00AA, "You have been healed");
            }
            else return SendClientMessage(playerid, 0xFFFFFFFF,"Error: Please use |Max|: 100, |Min|: 1");
        }
        else return SendClientMessage(playerid, 0xFFFFFFFF,"This player is not online.");
         
    }
    else return SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/healme\"");//if he adds ANYTHING after healme this will come up.
    return 1;
}
Not tested!


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

Thanks, but.. The Max and Min dont work..

Here is my code:
pawn Code:
dcmd_setplayerhealth(playerid, params[])
{
    new targetid, Float:amount;
       
    if(sscanf(params, "uf", targetid, amount)) SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/setplayerhealth <playerid> <amount>\"");
    if(targetid == INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000AA, "Player not found");
    {
        if(amount > 1 || amount < 101)
        {
            new playername[MAX_PLAYER_NAME], targetname[MAX_PLAYER_NAME], string[256];
            GetPlayerName(playerid, playername, sizeof(playername));
            GetPlayerName(targetid, targetname, sizeof(targetname));

            format(string, sizeof(string), "%s(%d) set %s(%d)'s health to %.0f", targetname, targetid, playername, playerid, amount);
            SendClientMessageToAll(0x50FF05FF, string);
       
            SetPlayerHealth(playerid, amount);
        } else return SendClientMessage(playerid, 0xFFFFFFFF,"Error: Please use |Max|: 100, |Min|: 1");
    }
    return 1;
}



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

Actually its < 100 and not < 101 because it'll count 101 to. You have to add <= 101 for that
Also I dont think amount needs to be a float


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

Quote:
Originally Posted by alpha500delta
View Post
Actually its < 100 and not < 101 because it'll count 101 to. You have to add <= 101 for that
Also I dont think amount needs to be a float
If you mean like this:
pawn Code:
if(amount >= 1 || amount <= 100)
then, It dont work =/


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

Quote:
Originally Posted by alpha500delta
View Post
Actually its < 100 and not < 101 because it'll count 101 to. You have to add <= 101 for that
Also I dont think amount needs to be a float
That's actually not correct. Think about what you're saying there, he wants the limit to be 100. Which means what he's written is correct.

< 100 means less than 100, which means it'll work up to 99
<= 101 means less than or equal to 101, which means it'll work up to 101.

The reason it's not working is because of your logic, you're saying this currently:

pawn Code:
if(amount > 1 || amount < 101)
This means if amount is greater than 1 OR less than 101, execute code. Which means it will always be executed, you need to change your logic to this:

pawn Code:
if(amount > 1 && amount < 101)
This means if amount is greater than 1 AND less than 101, then the code will be executed, which is what you're looking for.


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

THANKS! JaTochNietDan

And O.o my code just stopped working.
when i type "/setplayerhealth" then it returns:

Usage: "setplayerhealth <playerid> <amount>"
Error: Please use |Max|: 100, |Min|: 1
(Hover the last line)

pawn Code:
dcmd_setplayerhealth(playerid, params[])
{
    new targetid, Float:amount;

    if(sscanf(params, "uf", targetid, amount)) SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/setplayerhealth <playerid> <amount>\"");
    else if(targetid == INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000AA, "Player not found");
    {
        if(amount > 1 && amount < 101)
        {
            new playername[MAX_PLAYER_NAME], targetname[MAX_PLAYER_NAME], string[256];
            GetPlayerName(playerid, playername, sizeof(playername));
            GetPlayerName(targetid, targetname, sizeof(targetname));

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

            SetPlayerHealth(playerid, amount);
            return 1;
        } else return SendClientMessage(playerid, 0xFFFFFFFF,"Error: Please use |Max|: 100, |Min|: 1");
    }
}



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

Because you declared your "amount" as a Float. So it has to be a decimal number and 20 is not decimal.
So just don't use floats in this command, it's much simpler.


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

Quote:
Originally Posted by Alex_Valde
View Post
Because you declared your "amount" as a Float. So it has to be a decimal number and 20 is not decimal.
So just don't use floats in this command, it's much simpler.
Could you please fix it for me? so i can see where i did the mistake? O.o


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

pawn Code:
dcmd_setplayerhealth(playerid, params[])
{
    new targetid,/*Float: - This you dont need*/ amount;

    if(sscanf(params, "ui", targetid, amount)) SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/setplayerhealth <playerid> <amount>\"");
    else if(!IsPlayerConnected(targetid)/*targetid == INVALID_PLAYER_ID - I suggest you to use IsPlayerConnected since there InvalidPlayerID can be bugged*/) SendClientMessage(playerid, 0xFF0000AA, "Player not found");
    {
        if(amount > 1 && amount < 101)
        {
            new playername[MAX_PLAYER_NAME], targetname[MAX_PLAYER_NAME], string[256];
            GetPlayerName(playerid, playername, sizeof(playername));
            GetPlayerName(targetid, targetname, sizeof(targetname));

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

            SetPlayerHealth(playerid, amount);
            return 1;
        } else return SendClientMessage(playerid, 0xFFFFFFFF,"Error: Please use |Max|: 100, |Min|: 1");
    }
}



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

Hmm. I still get the same message when i type "/setplayerhealth" (without the ID and amount)

1. /setplayerhealth
2. I get these messages:
/setplayerhealth <playerid> <amount>
Error: Please use |Max|: 100, |Min|: 1


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

Your coding syntax is a little strange. Those brackets for example after the else if check do absolutely nothing except make it look pretty, they aren't part of any statement. Here is how I would code it:

pawn Code:
dcmd_setplayerhealth(playerid, params[])
{
    new targetid, Float:amount;

    if(sscanf(params, "uf", targetid, amount)) return SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/setplayerhealth <playerid> <amount>\"");
    if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid, 0xFF0000AA, "Player not found");
    if(amount > 1 && amount < 101)
    {
        new playername[MAX_PLAYER_NAME], targetname[MAX_PLAYER_NAME], string[256];
        GetPlayerName(playerid, playername, sizeof(playername));
        GetPlayerName(targetid, targetname, sizeof(targetname));

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

        SetPlayerHealth(playerid, amount);
    }
    else SendClientMessage(playerid, 0xFFFFFFFF,"Error: Please use |Max|: 100, |Min|: 1");
    return 1;
}