/sethp command not working -
arad55 - 04.08.2014
When I type the command ingame like this "
/sethp" it returns "ERROR: Player is not connected" and when I type an ID it returns "Server: Unknown Command". What is the problem here?
This is my command:
pawn Код:
if(strcmp("/sethp", cmdtext, true) == 0)
{
if(IsPlayerConnected(playerid))
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
return SendClientMessage(playerid, -1, "USAGE: /sethp [playerid/PartOfName] [health]");
new playa;
new health;
playa = ReturnUser(tmp);
tmp = strtok(cmdtext, idx);
health = strval(tmp);
if(IsPlayerConnected(playa))
{
if(playa != INVALID_PLAYER_ID)
{
new playername[MAX_PLAYER_NAME+1];
GetPlayerName(playerid, playername, sizeof(playername));
SetPlayerHealthAM(playa, health);
format(string, sizeof(string), "Your health has been set to %d by %s (%d)", health, playername, playerid);
SendClientMessage(playerid, -1, string);
}
else
return SendClientMessage(playerid, -1, "{FF0000}ERROR: Player is not connected!");
}
else
return SendClientMessage(playerid, -1, "{FF0000}ERROR: Player is not connected!");
}
return 1;
}
Respuesta: /sethp command not working -
Cepillado - 04.08.2014
Why do you have tmp = strtok(cmdtext, idx); twice? I'm pretty sure that you don't need that. Besides from that I really don't know what could it be, why don't you try using sscanf?
Re: /sethp command not working -
ViniBorn - 04.08.2014
Really, is recomended to use sscanf and y_cmd/zcmd,etc
Re: /sethp command not working -
arad55 - 04.08.2014
I don't know how to use sscanf and y_cmd etc..
Okay I deleted one of the strtok's and when not inserting any numbers, it returns the USAGE message I wrote like should. Now the problem is when you insert an id and then it still returns "Server: Unknown Command"
pawn Код:
if(strcmp("/sethp", cmdtext, true) == 0)
{
if(IsPlayerConnected(playerid))
{
if(!strlen(tmp))
return SendClientMessage(playerid, -1, "USAGE: /sethp [playerid/PartOfName] [health]");
new playa;
new health;
playa = ReturnUser(tmp);
tmp = strtok(cmdtext, idx);
health = strval(tmp);
if(IsPlayerConnected(playa))
{
if(playa != INVALID_PLAYER_ID)
{
new playername[MAX_PLAYER_NAME+1];
GetPlayerName(playerid, playername, sizeof(playername));
SetPlayerHealthAM(playa, health);
format(string, sizeof(string), "Your health has been set to %d by %s (%d)", health, playername, playerid);
SendClientMessage(playerid, -1, string);
}
else
return SendClientMessage(playerid, -1, "{FF0000}ERROR: Player is not connected!");
}
else
return SendClientMessage(playerid, -1, "{FF0000}ERROR: Player is not connected!");
}
return 1;
}
Respuesta: /sethp command not working -
Cepillado - 04.08.2014
It'll be a lot more efficient and smaller if you used sscanf and zcmd, dcmd etc... They are not that hard to use and there are many tutorials on how to use them.
Also, you could try removing the INVALID_ID part, playa can't have an INVALID_ID if playa is connected.
Re: /sethp command not working -
arad55 - 04.08.2014
It still doesn't work. Can someone give me a good tutorial for sscanf and download? Thanks!
Re: /sethp command not working -
TLN - 04.08.2014
https://sampforum.blast.hk/showthread.php?tid=120356
Respuesta: /sethp command not working -
Cepillado - 04.08.2014
sscanf:
https://sampforum.blast.hk/showthread.php?tid=120356
zcmd:
https://sampforum.blast.hk/showthread.php?tid=91354
zcmd actually has a /givemoney tutorial in the post, that could help you a lot to make the /sethp command since it's basically the same thing. Good luck!
Re: /sethp command not working -
arad55 - 04.08.2014
removed
Re: /sethp command not working -
Don_Cage - 04.08.2014
This is how a sethp cmd can look like with zcmd and sscanf
pawn Код:
CMD:sethp(playerid, params[])
{
new id,name[MAX_PLAYER_NAME+1],string[128],Float:hp;
if(sscanf(params,"ui",id,hp)) return SentClientMessage(playerid, -1, "SYNTAX: /sethp [player] [health]");
SetPlayerHealth(id, hp);
GetPlayerName(playerid, name, sizeof(name));
format(string, sizeof(string),"%s has set your health to %i",name, hp);
SendClientMessage(id, -1, string);
return true;
}
Looks pretty easy when you think about it right?