/sethp, /setarmour not working
#1

Hello so basically i'm a newbie in scripting i tried making these 2 simple cmd's, but it doesn't work for a reason. When i try to test it on my ID, it says Player is not connected.

Here is the codes for /sethp cmd:

Код:
CMD:sethp(playerid,params[])
{
	if(PlayerInfo[playerid][pAdmin]>1337)
	{
	new Float:Health;
	new PID;
	if(sscanf(params, "ud", PID, Health)) return SendClientMessage(playerid, COLOR_GRAD1, "USAGE: /sethp [playerid] [health]");
	if(!IsPlayerConnected(PID)) return SendClientMessage(playerid, -1, "Player is not connected.");
	SetPlayerHealth(PID, Health);
	}
	else SendClientMessage(playerid, -1, "You are not authorized to use this command!");
	return 1;
}
And codes for /setarmour cmd:

Код:
CMD:setarmour(playerid,params[])
{
	if(PlayerInfo[playerid][pAdmin]>1337)
	{
	new float:Armour;
	new PID;
	if(sscanf(params,"ud",PID,Armour)) return SendClientMessage(playerid,COLOR_GRAD1,"USAGE: /setarmour [playerid] [armor]");
	if(!IsPlayerConnected(PID)) return SendClientMessage(playerid,COLOR_GRAD1,"Player is not connected.");
	SetPlayerArmour(playerid, Armour);
	}
	else SendClientMessage(playerid,-1,"You are not authorized to use this command!");
	return 1;
}
I get the same result for both CMD's, so i'm sure that i made something wrong but i cant find what is it...
Reply
#2

Try removing "Float:Health" & "Float:Armor". You don't need the Float.
Reply
#3

Eh?

PHP код:
CMD:sethp(playerid,params[])
{
    new 
Float:HealthPID;
    if(
PlayerInfo[playerid][pAdmin] > 1337SendClientMessage(playerid, -1"You are not authorized to use this command!");
    if(
sscanf(params"uf"PIDHealth)) return SendClientMessage(playeridCOLOR_GRAD1"USAGE: /sethp [playerid] [health]");
    if(
PID == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1"Player is not connected.");
    
//else
    
SetPlayerHealth(PIDHealth);
    return 
1;
}
CMD:setarmour(playeridparams[])
{
    new 
float:ArmourPID;
    if(
PlayerInfo[playerid][pAdmin] > 1337SendClientMessage(playerid,-1,"You are not authorized to use this command!");
    if(
sscanf(params,"uf"PIDArmour)) return SendClientMessage(playerid,COLOR_GRAD1,"USAGE: /setarmour [playerid] [armor]");
    if(
PID == INVALID_PLAYER_ID)  return SendClientMessage(playerid,COLOR_GRAD1,"Player is not connected.");
    
//else
    
SetPlayerArmour(PIDArmour);
    return 
1;

Reply
#4

PHP код:
if(!IsPlayerConnected(PID)) 
This will display the message if the player is connected.

EDIT:
PHP код:
if(IsPlayerConnectedEx(PID)) return SendClientMessage(playerid,GREY,"Player is not connected"); 
Reply
#5

I tried removing Flaot:health and armour, but nothing. And I thought this code

PHP код:
if(!IsPlayerConnected(PID)) 
will display the message if the player is not connected with this sign "!"?
Reply
#6

Quote:
Originally Posted by LeeXx
Посмотреть сообщение
I tried removing Flaot:health and armour, but nothing. And I thought this code

PHP код:
if(!IsPlayerConnected(PID)) 
will display the message if the player is not connected with this sign "!"?
! sign means NOT.

For example 1 != 2 one is NOT equal to two.

if(!IsPlayerConnected) if IsPlayer NOT connected.
Reply
#7

So that means my codes are correct? Yet I still get the same result, when I try to /sethp [MyID] to test it, it shows the message ''Player is not connected''?
Reply
#8

well, probably you got old sscanf or smth, try replacing "u" with "i" or "d" also its Float: not float:

so
PHP код:
CMD:setarmour(playerid,params[])
{
    if(
PlayerInfo[playerid][pAdmin]>1337)
    {
    new 
float:Armour;
    new 
PID;
    if(
sscanf(params,"ud",PID,Armour)) return SendClientMessage(playerid,COLOR_GRAD1,"USAGE: /setarmour [playerid] [armor]");
    if(!
IsPlayerConnected(PID)) return SendClientMessage(playerid,COLOR_GRAD1,"Player is not connected.");
    
SetPlayerArmour(playeridArmour);
    }
    else 
SendClientMessage(playerid,-1,"You are not authorized to use this command!");
    return 
1;

gotta be
PHP код:
CMD:setarmour(playerid,params[])
{
    if(
PlayerInfo[playerid][pAdmin]>1337)
    {
    new 
Float:Armour;
    new 
PID;
    if(
sscanf(params,"if",PID,Armour)) return SendClientMessage(playerid,COLOR_GRAD1,"USAGE: /setarmour [playerid] [armor]");
    if(!
IsPlayerConnected(PID)) return SendClientMessage(playerid,COLOR_GRAD1,"Player is not connected.");
    
SetPlayerArmour(PIDArmour);
    }
    else 
SendClientMessage(playerid,-1,"You are not authorized to use this command!");
    return 
1;

d,i for integers and u gets playerid by his name or by his id directly [ not supported by old sscanfs or supported but a bit bugged ]. and f for floats. so in your sscanf d has to be f as health and armour are Float values.

also
PHP код:
SetPlayerArmour(playeridArmour); 
had to be
PHP код:
SetPlayerArmour(PIDArmour); 
Reply
#9

Yeah it actually worked, thanks for explaining to me Jlalt. + rep my friend!
Reply
#10

Download the latest version of sscanf from:
https://sampforum.blast.hk/showthread.php?tid=570927

PHP код:
CMD:sethp(playerid,params[])
{
    new 
healthtargetid;
    if(
PlayerInfo[playerid][pAdmin] < 1337) return SendClientMessage(playerid, -1"You are not authorized to use this command!");
    if(
sscanf(params"ui"targetidhealth)) return SendClientMessage(playeridCOLOR_GRAD1"USAGE: /sethp [playerid] [health]");
    if(!
IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1"Player is not connected.");
    
SetPlayerHealth(targetidhealth);
    return 
1;
}
CMD:setarmour(playerid,params[])
{
    new 
armourtargetid;
    if(
PlayerInfo[playerid][pAdmin] < 1337) return SendClientMessage(playerid, -1"You are not authorized to use this command!");
    if(
sscanf(params"ui"targetidhealth)) return SendClientMessage(playeridCOLOR_GRAD1"USAGE: /setarmour [playerid] [armour]");
    if(!
IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1"Player is not connected.");
    
SetPlayerArmour(targetidarmour);
    return 
1;


EDIT: Too Late :))
Reply
#11

Haha it's alright, thanks for your help anyways
I need that link xD
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)