Fast help
#1

Hello,just need a fast help with this /heal command:

pawn Код:
CMD:heal(playerid, params[])
{
    new giveplayerid,Float:heal,Float:X, Float:Y, Float:Z;
    new pname[MAX_PLAYER_NAME];
    GetPlayerName(playerid,pname,sizeof(pname));
        if(sscanf(params), "f", > 90) return SendClientMessage(playerid,0xFF0000FF, "You can't offer at this player health more than 90 hp.");
    if(sscanf(params, "df", giveplayerid, heal))return SendClientMessage(playerid, COLOR_YELLOW, "Usage: /heal (playerid) (health 1-90)");
    {
        if(!IsPlayerConnected(giveplayerid) || giveplayerid == playerid)
        {
            SendClientMessage(playerid, red, "Invalid player id.");
            return true;
        }

        GetPlayerPos(playerid, X, Y, Z);
        if(!IsPlayerInRangeOfPoint(giveplayerid, 5.0, X, Y, Z))
        {
            SendClientMessage(playerid, red, "This player is too far from you, you can't offer him health.");
            return true;
        }

        new string[128];
        format(string, sizeof(string), "You've received an offer to heal you by %s (%d) of %2.1f hp.", pname,playerid,heal);
        SendClientMessage(giveplayerid, -1, string);
        SendClientMessage(giveplayerid, -1, "Type in the chat \"Yes\" or \"No\" to reply the offer.");
        pOffersHeal[giveplayerid] = true;
        HealthAmount = heal;
    }
    return true;
}
}
The error line is this:

pawn Код:
if(sscanf(params), "f", > 90) return SendClientMessage(playerid,0xFF0000FF, "You can't offer at this player health more than 90 hp.");
I don't want a player can offer more than 90 hp,thanks.

EDIT: This is onplayertext:

pawn Код:
if(pOffersHeal[playerid])
    {
        if(strcmp(text, "Yes", true) == 0)
        {
            SetPlayerHealth(playerid, HealthAmount);
            GameTextForPlayer(playerid, "~r~Health ~g~refill ~w~accepted!", 5000, 4);
            SendClientMessage(playerid,COLOR_PINK,"You have accepted the health refill.");
        }

        else if(strcmp(text, "No", true) == 0)
        {
            GameTextForPlayer(playerid, "Health offer denied.", 3000, 3);
            GameTextForPlayer(playerid, "~r~Health ~g~refill ~w~denied!", 5000, 4);
            SendClientMessage(playerid,COLOR_PINK,"You have denied the health refill.");
            pOffersHeal[playerid] = false;
        }
        return true;
    }
I need to show how much health the player has accepted and who sent it,how i can?
Reply
#2

Код:
CMD:heal(playerid, params[])
{
	new giveplayerid,Float:heal,Float:X, Float:Y, Float:Z;
	new pname[MAX_PLAYER_NAME];
	GetPlayerName(playerid,pname,sizeof(pname));
	if(sscanf(params, "uf", giveplayerid, heal))return SendClientMessage(playerid, COLOR_YELLOW, "Usage: /heal (playerid) (health 1-90)");
        if(heal > 90) return SendClientMessage(playerid,0xFF0000FF, "You can't offer at this player health more than 90 hp.");

	if(!IsPlayerConnected(giveplayerid) || giveplayerid == playerid) return SendClientMessage(playerid, red, "Invalid player id.");

	GetPlayerPos(playerid, X, Y, Z);
	if(!IsPlayerInRangeOfPoint(giveplayerid, 5.0, X, Y, Z)) return SendClientMessage(playerid, red, "This player is too far from you, you can't offer him health.");

	new string[128];
	format(string, sizeof(string), "You've received an offer to heal you by %s (%d) of %2.1f hp.", pname,playerid,heal);
	SendClientMessage(giveplayerid, -1, string);
	SendClientMessage(giveplayerid, -1, "Type in the chat \"Yes\" or \"No\" to reply the offer.");
	pOffersHeal[giveplayerid] = true;
	HealthAmount = heal;
	return true;
}
Reply
#3

Thank you HuSs3n, it works. Now i need the last help with OnPlayerText, can you?
Reply
#4

On Top
Код:
new pOffersHeal[MAX_PLAYERS];  // This is the ID of the player that offered the heal , its equal to INVALID_PLAYER_ID by default;
new Float:HealthAmount[MAX_PLAYERS]; // This is the health amount
On Player Connect
Код:
public OnPlayerConnect(playerid)
{
    pOffersHeal[playerid]=INVALID_PLAYER_ID;
    HealthAmount[playerid]=0;
}
The Command
Код:
CMD:heal(playerid, params[])
{
	new giveplayerid,Float:heal,Float:X, Float:Y, Float:Z;
	new pname[MAX_PLAYER_NAME];
	GetPlayerName(playerid,pname,sizeof(pname));
	if(sscanf(params, "uf", giveplayerid, heal))return SendClientMessage(playerid, COLOR_YELLOW, "Usage: /heal (playerid) (health 1-90)");
    if(heal > 90) return SendClientMessage(playerid,0xFF0000FF, "You can't offer at this player health more than 90 hp.");

	if(!IsPlayerConnected(giveplayerid) || giveplayerid == playerid) return SendClientMessage(playerid, red, "Invalid player id.");

	GetPlayerPos(playerid, X, Y, Z);
	if(!IsPlayerInRangeOfPoint(giveplayerid, 5.0, X, Y, Z)) return SendClientMessage(playerid, red, "This player is too far from you, you can't offer him health.");

	new string[128];
	format(string, sizeof(string), "You've received an offer to heal you by %s (%d) of %2.1f hp.", pname,playerid,heal);
	SendClientMessage(giveplayerid, -1, string);
	SendClientMessage(giveplayerid, -1, "Type in the chat \"Yes\" or \"No\" to reply the offer.");
	pOffersHeal[giveplayerid] = playerid;
	HealthAmount[giveplayerid] = heal;
	return true;
}
On Player Text
Код:
 	if(pOffersHeal[playerid] != INVALID_PLAYER_ID)
	{
		new str[128],Float:h,pname[MAX_PLAYER_NAME];
		GetPlayerName(pOffersHeal[playerid],pname,sizeof(pname));
		GetPlayerHealth(playerid,h);

		if(strcmp(text, "Yes", true) == 0)
		{
		    SetPlayerHealth(playerid, h + HealthAmount[playerid]);
		    GameTextForPlayer(playerid, "~r~Health ~g~refill ~w~accepted!", 5000, 4);
		    format(str,sizeof(str),"You have accepted the health refill from %s (%f HP).",pname,HealthAmount[playerid]);
		    SendClientMessage(playerid,COLOR_PINK,str);
			pOffersHeal[playerid] = INVALID_PLAYER_ID;
		}

		else if(strcmp(text, "No", true) == 0)
		{
			GameTextForPlayer(playerid, "Health offer denied.", 3000, 3);
			GameTextForPlayer(playerid, "~r~Health ~g~refill ~w~denied!", 5000, 4);
		    format(str,sizeof(str),"You have accepted the health refill from %s (%f HP).",pname,HealthAmount[playerid]);
			SendClientMessage(playerid,COLOR_PINK,str);
			pOffersHeal[playerid] = INVALID_PLAYER_ID;
		}
		return true;
	}
Reply
#5

You are awesome, really thanks!

+rep.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)