SA-MP Forums Archive
CMD not working - 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: CMD not working (/showthread.php?tid=661610)



CMD not working - ddiioonn123 - 09.12.2018

Hi, i started scripting SA-MP yesterday, and i wanted to make a command called: "heal", but it's not working!
Code:


CMD:heal(playerid, params[]){
new targetid;
if(sscanf(params, "ud", targetid)) return SendClientMessage(playerid, 0xFF0000AA, "Perdorimi: /heal [ID]");
else {
new Float:currentHp;
new Float:hpmomentale = GetPlayerHealth(playerid, currentHp);
SetPlayerHealth(playerid, 100-hpmomentale);
return 1;
}
}

Any help?


Re: CMD not working - Mike861 - 09.12.2018

Quote:
Originally Posted by ddiioonn123
Посмотреть сообщение
Hi, i started scripting SA-MP yesterday, and i wanted to make a command called: "heal", but it's not working!
Code:


CMD:heal(playerid, params[]){
new targetid;
if(sscanf(params, "ud", targetid)) return SendClientMessage(playerid, 0xFF0000AA, "Perdorimi: /heal [ID]");
else {
new Float:currentHp;
new Float:hpmomentale = GetPlayerHealth(playerid, currentHp);
SetPlayerHealth(playerid, 100-hpmomentale);
return 1;
}
}

Any help?
Код:
CMD:heal(playerid, params[])
{
	new targetid,amount;
	if(sscanf(params, "ud", targetid,amount)) return  SendClientMessage(playerid, 0xFF0000AA, "Perdorimi: /heal [ID]");
        if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, 0xFF0000AA,  "Error: Invalid player ID.");
	SetPlayerHealth(targetid, amount);
	return 1;
}
Improved it a bit, you can translate the error message to your language if you want, you can also limit the amount by doing:
Код:
if(amount > 100) return SendClientMessage(playerid, 0x0xFF0000AA, "Error: Maximum amount is 100.");



Re: CMD not working - SlBIH - 09.12.2018

Код:
CMD:heal(playerid, params[])
{
	new targetid;
	if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, 0xFF0000AA, "Perdorimi: /heal [ID]");
	SetPlayerHealth(targetid, 100);
	return 1;
}
Enjoy


Re: CMD not working - ddiioonn123 - 09.12.2018

Hi, i didn't say that Command is not working(function of it), but it's saying: UNKNOWN Command in both codes.


Re: CMD not working - Mike861 - 09.12.2018

Quote:
Originally Posted by ddiioonn123
Посмотреть сообщение
Hi, i didn't say that Command is not working(function of it), but it's saying: UNKNOWN Command in both codes.
Show OnPlayerCommandPerformed callback (if you have it).
Otherwise im not sure what the issue might be.


Re: CMD not working - Kraeror - 09.12.2018

You forgot the return for the command and you added 2 params in the sscanf's quotes and only one after them (targetid)! Also you don't need to check the player's health in your case!
Try this:
CMD:heal(playerid, params[])
{
new targetid;
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, 0xFF0000AA, "Perdorimi: /heal [ID]");
else SetPlayerHealth(playerid, 100-hpmomentale);
return 1;
}