SA-MP Forums Archive
I need help with /sethealth - 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)
+--- Thread: I need help with /sethealth (/showthread.php?tid=533595)



I need help with /sethealth - AleckRP - 25.08.2014

This is how it looks but when i got in game it says that the player isn't connected. Somehow it stops there. Could someone help me out?
This also happened with my other commands.
Thank you.

Код:
CMD:sethealth(playerid, params[])
{
    new id;
    new hp;
    if(PlayerInfo[playerid][pAdmin] >= 6)
            {
                        if(!sscanf(params, "ui", id, hp))
                        {
                					if(!IsPlayerConnected(id))
									{
                                        SendClientMessage(playerid, -1, "SERVER: The player isn't connected.");
								     	return 1;
									}
                                    new string[64];
                                    new name[MAX_PLAYER_NAME], PlayerName[MAX_PLAYER_NAME];
                                    GetPlayerName(playerid, name, sizeof(name));
                                    GetPlayerName(id, PlayerName, sizeof(PlayerName));
                                    format(string, sizeof(string), "SERVER: Administrator %s has set your health to %d", name, hp);
                                    SendClientMessage(id, BLUE, string);
                                    format(string, sizeof(string), "SERVER: You have Set %s health to %d.", PlayerName, hp);
                                    SendClientMessage(playerid, BLUE, string);
                                    SetPlayerHealth(id, hp);
                                    return 1;
                        }
                        else return SendClientMessage(playerid, -1, "SERVER: /sethealth [PlayerId/PartOfName] [Hp]");
            }
			else
			{
                SendClientMessage(playerid, RED, "You cannot use this command.");
		     	return 1;
			}
}



Re: I need help with /sethealth - NewbieTester - 25.08.2014

Try This

pawn Код:
CMD:sethealth(playerid, params[])
{
    new string[128], playa, health;
    if(sscanf(params, "ud", playa, health))
    {
        SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /sethealth [playerid/partofname] [hp]");
        return 1;
    }
    if(PlayerInfo[playerid][pAdmin] >= 6)
    {
        if(AdminDuty[playerid] != 1 && PlayerInfo[playerid][pAdmin] < 6)
        {
            SendClientMessage(playerid,COLOR_WHITE, "You're not on-duty as admin. To access your admin commands you must be on-duty. Type /aduty to go on-duty.");
            return 1;
        }
        if(IsPlayerConnected(playa)) {
            if(playa != INVALID_PLAYER_ID)
            {
                SetPlayerHealth(playa, health);
                format(string, sizeof(string), "You have set %s's health to %d.", GetPlayerNameEx(playa), health);
                SendClientMessage(playerid, COLOR_WHITE, string);
                format(string, sizeof(string), "AdmCmd: %s has set %s's health to %d.", GetPlayerNameEx(playerid), GetPlayerNameEx(playa), health);
                ABroadCast(COLOR_LIGHTRED,string, 4);
                format(string, sizeof(string), "Admin %s had set your health to %d.", GetPlayerNameEx(playerid), health);
                SendClientMessage(playa, COLOR_WHITE, string);
            }
        }
        else SendClientMessage(playerid, COLOR_GRAD1, "Invalid player specified.");
    }
    else {
        SendClientMessage(playerid, COLOR_GRAD1, "You're not authorized to use that command!");
    }
    return 1;
}



Re: I need help with /sethealth - AleckRP - 25.08.2014

This way i will have few problems with GetPlayerNameEx need to add that stock.
I will try to see if it will work.



Re: I need help with /sethealth - AleckRP - 25.08.2014

I have edited it abit and still doesn't work says:


Re: I need help with /sethealth - NewbieTester - 25.08.2014

Did you do this CMD just foryourself ?


Re: I need help with /sethealth - AleckRP - 25.08.2014

Yes i have tested it only on myself.


Re: I need help with /sethealth - Stinged - 25.08.2014

Health is a float not an integer.


Re: I need help with /sethealth - AleckRP - 25.08.2014

Can anyone show me something because everything i made with this kind of commands and actions it's still the same problem. Don't know if i got bug somewhere else.


Re: I need help with /sethealth - IceCube! - 25.08.2014

You've already been told by Stinged, all you had to do was ****** the SCCANF - Floats. Utter laziness.

Here:
pawn Код:
CMD:sethealth(playerid, params[])
{
    new id;
    new Float:hp;
    if(PlayerInfo[playerid][pAdmin] >= 6)
            {
                        if(!sscanf(params, "uf", id, hp))
                        {
                                    if(!IsPlayerConnected(id))
                                    {
                                        SendClientMessage(playerid, -1, "SERVER: The player isn't connected.");
                                        return 1;
                                    }
                                    new string[64];
                                    new name[MAX_PLAYER_NAME], PlayerName[MAX_PLAYER_NAME];
                                    GetPlayerName(playerid, name, sizeof(name));
                                    GetPlayerName(id, PlayerName, sizeof(PlayerName));
                                    format(string, sizeof(string), "SERVER: Administrator %s has set your health to %f", name, hp);
                                    SendClientMessage(id, BLUE, string);
                                    format(string, sizeof(string), "SERVER: You have Set %s health to %f.", PlayerName, hp);
                                    SendClientMessage(playerid, BLUE, string);
                                    SetPlayerHealth(id, hp);
                                    return 1;
                        }
                        else return SendClientMessage(playerid, -1, "SERVER: /sethealth [PlayerId/PartOfName] [Hp]");
            }
            else
            {
                SendClientMessage(playerid, RED, "You cannot use this command.");
                return 1;
            }
}



Re: I need help with /sethealth - AleckRP - 25.08.2014

Thank you alot!