just an issue with a sethp cmd -
wallen - 13.03.2018
PHP код:
CMD:sethp(playerid, params[])
{
if(connected[playerid] == true) return GameTextForPlayer(playerid, "~r~Spawn First", 5000, 5);
if(pInfo[playerid][Admin] < 2) return SendClientMessage(playerid, -1, "{C3C3C3}(INFO) You don't have the priviliges to use this command.");
{
new amount, str[128], target;
if(!IsPlayerConnected(target)) return SendClientMessage(playerid, -1, "{c3c3c3}(INFO) The player is not connectdd!");
if(sscanf(params, "ui", target, amount)) return SendClientMessage(playerid, -1, "{c3c3c3}(INFO) /sethp [id] [amount]");
format(str, sizeof(str), "{EFB509}(INFO) You have set %s's health to %d", PlayerName[playerid], amount);
SendClientMessage(playerid, -1, str);
format(str, sizeof(str), "{EFB509}(INFO) An admin has set your health to %d", amount);
SendClientMessage(target, -1, str);
SetPlayerHealth(target, amount);
format(str,sizeof(str), "{0066ff}(admin) %s has set player's %s HP to %d", PlayerName[playerid], PlayerName[target], amount);
SendMessageToAdmins(str);
}
return 1;
}
Why when i join in local host and type /sethp 1 100 it gives me (id 0) 100 hp ? lol
Re: just an issue with a sethp cmd -
AdamsLT - 13.03.2018
You should check if the target is connected only AFTER scanning the params.
When formatting the "You have set ... health to ...." you should format it with PlayerName[target] not PlayerName[playerid] since you want the name of the taget, not yourself.
Re: just an issue with a sethp cmd -
wallen - 13.03.2018
still, that's what i got now
PHP код:
CMD:sethp(playerid, params[])
{
if(connected[playerid] == true) return GameTextForPlayer(playerid, "~r~Spawn First", 5000, 5);
if(pInfo[playerid][Admin] < 2) return SendClientMessage(playerid, -1, "{C3C3C3}(INFO) You don't have the priviliges to use this command.");
{
new amount, str[128], target;
if(sscanf(params, "ui", target, amount)) return SendClientMessage(playerid, -1, "{c3c3c3}(INFO) /sethp [id] [amount]");
if(!IsPlayerConnected(target)) return SendClientMessage(playerid, -1, "{c3c3c3}(INFO) The player is not connectdd!");
format(str, sizeof(str), "{EFB509}(INFO) You have set %s's health to %d", PlayerName[target], amount);
SendClientMessage(playerid, -1, str);
format(str, sizeof(str), "{EFB509}(INFO) An admin has set your health to %d", amount);
SendClientMessage(target, -1, str);
SetPlayerHealth(target, amount);
format(str,sizeof(str), "{0066ff}(admin) %s has set player's %s HP to %d", PlayerName[playerid], PlayerName[target], amount);
SendMessageToAdmins(str);
}
return 1;
}
Re: just an issue with a sethp cmd -
AdamsLT - 13.03.2018
Your code seems fine (unless I'm missing something silly).
Oh and SetPlayerHealth uses a Float type for the amount.
Maybe that is the reason. Change it from an integer to a float.
sscanf(params, "ui" ...)
-> sscanf(params, "uf" ...)
new amount
-> new Float:amount;
%d
-> %f
etc.
Re: just an issue with a sethp cmd -
ISmokezU - 13.03.2018
PHP код:
CMD:sethp(playerid, params[])
{
new amount,
target,
str[ 128 ];
if(connected[playerid]) return GameTextForPlayer(playerid, "~r~Spawn First", 5000, 5);
if(pInfo[playerid][Admin] < 2) return SendClientMessage(playerid, -1, "{C3C3C3}(INFO) You don't have the priviliges to use this command.");
if(target == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "{c3c3c3}(INFO) The player is not connected!");
if(sscanf(params, "ui", target, amount)) return SendClientMessage(playerid, -1, "{c3c3c3}(INFO) /sethp [id] [amount]");
format(str, sizeof(str), "{EFB509}(INFO) You have set %s's health to %d", PlayerName[playerid], amount);
SendClientMessage(playerid, -1, str);
format(str, sizeof(str), "{EFB509}(INFO) An admin has set your health to %d", amount);
SendClientMessage(target, -1, str);
printf("Target: %i", target);
printf("Playerid: %i", playerid);
SetPlayerHealth(target, amount);
format(str,sizeof(str), "{0066ff}(admin) %s has set player's %s HP to %d", PlayerName[playerid], PlayerName[target], amount);
SendMessageToAdmins(str);
return 1;
}
I just edited your code, honestly.
Give it a try nonetheless.