just an issue with a sethp cmd
#1

PHP код:
CMD:sethp(playeridparams[])
{
   if(
connected[playerid] == true) return GameTextForPlayer(playerid"~r~Spawn First"50005);
   if(
pInfo[playerid][Admin] < 2) return SendClientMessage(playerid, -1"{C3C3C3}(INFO) You don't have the priviliges to use this command.");
   {
     new 
amountstr[128], target;
     if(!
IsPlayerConnected(target)) return SendClientMessage(playerid, -1"{c3c3c3}(INFO) The player is not connectdd!");
     if(
sscanf(params"ui"targetamount)) return SendClientMessage(playerid, -1"{c3c3c3}(INFO) /sethp [id] [amount]");
     
format(strsizeof(str), "{EFB509}(INFO) You have set %s's health to %d"PlayerName[playerid], amount);
     
SendClientMessage(playerid, -1str);
     
format(strsizeof(str), "{EFB509}(INFO) An admin has set your health to %d"amount);
     
SendClientMessage(target, -1str);
     
SetPlayerHealth(targetamount);
     
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
Reply
#2

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

still, that's what i got now

PHP код:
CMD:sethp(playeridparams[])
{
   if(
connected[playerid] == true) return GameTextForPlayer(playerid"~r~Spawn First"50005);
   if(
pInfo[playerid][Admin] < 2) return SendClientMessage(playerid, -1"{C3C3C3}(INFO) You don't have the priviliges to use this command.");
   {
     new 
amountstr[128], target;
     if(
sscanf(params"ui"targetamount)) return SendClientMessage(playerid, -1"{c3c3c3}(INFO) /sethp [id] [amount]");
     if(!
IsPlayerConnected(target)) return SendClientMessage(playerid, -1"{c3c3c3}(INFO) The player is not connectdd!");
     
format(strsizeof(str), "{EFB509}(INFO) You have set %s's health to %d"PlayerName[target], amount);
     
SendClientMessage(playerid, -1str);
     
format(strsizeof(str), "{EFB509}(INFO) An admin has set your health to %d"amount);
     
SendClientMessage(target, -1str);
     
SetPlayerHealth(targetamount);
     
format(str,sizeof(str), "{0066ff}(admin) %s has set player's %s HP to %d"PlayerName[playerid], PlayerName[target], amount);
     
SendMessageToAdmins(str);
   }
   return 
1;

Reply
#4

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

PHP код:
CMD:sethp(playeridparams[]) 

    new 
amount,
        
target,
        
str128 ]; 
    if(
connected[playerid]) return GameTextForPlayer(playerid"~r~Spawn First"50005); 
    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"targetamount)) return SendClientMessage(playerid, -1"{c3c3c3}(INFO) /sethp [id] [amount]"); 
   
    
format(strsizeof(str), "{EFB509}(INFO) You have set %s's health to %d"PlayerName[playerid], amount); 
    
SendClientMessage(playerid, -1str); 
   
    
format(strsizeof(str), "{EFB509}(INFO) An admin has set your health to %d"amount); 
    
SendClientMessage(target, -1str); 

    
printf("Target: %i"target);
    
printf("Playerid: %i"playerid);
   
    
SetPlayerHealth(targetamount); 
    
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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)