CMD:heal(playerid, params[])
{
new Float:Health, Float:tbhealedhealth, Float:healprice, Float:healtime, string[128];
GetPlayerHealth(playerid, Float:Health); //Setting the value for health
tbhealedhealth = 100-Health; //Health to be healed
//healprice = tbhealedhealth*10;
//healtime = tbhealedhealth*3000;
/*format(string, sizeof(string), "health: %.4f | tbhealedhealth: %.4f | healprice: %.4f | healtime: %.4f", Health, tbhealedhealth, healprice, healtime);
SendClientMessage(playerid, -1, string);*/
if(IsPlayerInRangeOfPoint(playerid, 5, HealPos1X, HealPos1Y, HealPos1Z))
{
if(Health == 100)
{
SendClientMessage(playerid, GREY, "You already have full health.");
}
else if(Health >= 41)
{
if(Health <= 99)
{
Player[playerid][HealTime] = tbhealedhealth; //Stores the to be healed health as a time in seconds to a player stat
Player[playerid][HealPrice] = tbhealedhealth*3; //Triples the to be healed health, this is the amount they must pay then stores it to a player stat
Player[playerid][BeingHealed] = 1; //Being healed at hospital 1 (Will put in hospital 2 if this can be fixed)
format(string, sizeof(string), "You are now undergoing hospital treatment. You will be released in %.0f seconds.", Player[playerid][HealTime]);
SendClientMessage(playerid, -1, string);
SetPlayerPos(playerid, 1161.2238, -1321.6235, 19); // Everything below is just setting cam pos etc. whilst they are in hospital
SetPlayerVirtualWorld(playerid, playerid);
TogglePlayerControllable(playerid, false);
SetPlayerCameraPos(playerid, 1217.4056, -1321.4524, 31.1270);
SetPlayerCameraLookAt(playerid, 1173.2889, -1322.7111, 19.4345);
}
}
else if(Health <= 40) // Same as above, only difference is the price is doubled here
{
if(Health >= 1)
{
Player[playerid][HealTime] = tbhealedhealth;
Player[playerid][HealPrice] = tbhealedhealth*6;
Player[playerid][BeingHealed] = 1;
format(string, sizeof(string), "You are now undergoing hospital treatment. You will be released in %.0f seconds.", Player[playerid][HealTime]);
SendClientMessage(playerid, -1, string);
SetPlayerPos(playerid, 1161.2238, -1321.6235, 19);
SetPlayerVirtualWorld(playerid, playerid);
TogglePlayerControllable(playerid, false);
SetPlayerCameraPos(playerid, 1217.4056, -1321.4524, 31.1270);
SetPlayerCameraLookAt(playerid, 1173.2889, -1322.7111, 19.4345);
}
}
}
return 1;
}
if(Player[i][BeingHealed] != 0)
{
new string[128], Float: Health;
GetPlayerHealth(i, Health);
if(Health == 100)
{
Player[i][Money] -= Player[i][HealPrice];
format(string, sizeof(string), "You have been released from hospital. Your were billed $%.0f.", Player[i][HealPrice]);
SendClientMessage(i, -1, string);
Player[i][BeingHealed] = 0;
Player[i][HealPrice] = 0;
Player[i][HealTime] = 0;
SetCameraBehindPlayer(i);
SetPlayerVirtualWorld(i, 0);
SetPlayerInterior(i, 0);
TogglePlayerControllable(i, true);
SetPlayerPos(i, 1177.6462, -1323.7413, 14.0810);
}
else
{
SetPlayerHealth(i, Health+1);
format(string, sizeof(string), "~y~Time remaining:~n~~n~~r~%.0f seconds", Player[i][HealTime]);
Player[i][HealTime] -= -1;
GameTextForPlayer(i, string, 1000, 3);
}
}
CMD:heal(playerid,params[])
{
#pragma unused params
new string[128];
new pname[MAX_PLAYER_NAME];
new id;
if(sscanf(params, "u", id))
{
SendClientMessage(playerid,COLOR_ERROR,"Usage: /heal (Player Name/ID)");
return 1;
}
new Float:phealth;
GetPlayerHealth(id,phealth);
/*if(IsFrozen[playerid] == 1)
{
SendClientMessage(playerid,COLOR_RED,"You cannot use this command while you're frozen.");
return 1;
}*/
if(gTeam[playerid] != TEAM_MEDIC)
{
SendClientMessage(playerid,COLOR_RED,"Only medics can heal other players.");
return 1;
}
if(!IsPlayerConnected(id))
{
format(string,sizeof(string),"The Player is not connected to the server.");
SendClientMessage(playerid,COLOR_RED,string);
return 1;
}
if(id == playerid)
{
SendClientMessage(playerid,COLOR_RED,"You cannot heal yourself with this command. use /healme");
return 1;
}
/*if(GetDistanceBetweenPlayers(playerid,id) > 6)
{
format(string,sizeof(string),"%s(%d) is not close enough to heal them.",pname,id);
SendClientMessage(playerid,COLOR_RED,string);
return 1;
}*/
if(phealth == 100)
{
SendClientMessage(playerid,COLOR_RED,"Their health is already full. You don't need to heal them.");
return 1;
}
/*if(GetPlayerMoney(id) < SkillPrice[playerid])
{
SendClientMessage(playerid,COLOR_RED,"That player does not have enough money on them to pay your price.");
return 1;
}*/
format(string,sizeof(string),"You have healed %s(%d) for a price of $%d. Make sure they are happy.",pname,id,SkillPrice[playerid]);
SendClientMessage(playerid,COLOR_PURPLE,string);
GivePlayerMoney(playerid,SkillPrice[playerid]);
format(string,sizeof(string),"You have been healed by %s(%d) for a price of $%d.",pname,playerid,SkillPrice[playerid]);
SendClientMessage(id,COLOR_PURPLE,string);
GivePlayerMoney(id,-SkillPrice[playerid]);
SetPlayerHealth(id,100);
//CalledForMedic[I] =0;
//format(string,sizeof(string),"3[MEDIC ACTION] %s(%d) has restored %s(%d)'s health by using /heal.",PlayerName(playerid),playerid,PlayerName(ID),ID);
//IRC_GroupSay(gGroupID,IRC_CHANNEL,string);
return 1;
}
What is HealPos1X, HealPos1Y, HealPos1Z? Where you use it? GetPlayerPos?
|
if(!IsPlayerConnected(id))
{ GetPlayerName(id,pname,MAX_PLAYER_NAME); format(string,sizeof(string),"The Player %s(%d) is not connected to the server.",pname,id); SendClientMessage(playerid,COLOR_RED,string); return 1; } |
if(!IsPlayerConnected(id))
{
format(string,sizeof(string),"The Player is not connected to the server.");
SendClientMessage(playerid,COLOR_RED,string);
return 1;
}
CMD:heal(playerid, params[])
{
new Float:Health, tbhealedhealth, healprice, healtime, string[128];
GetPlayerHealth(playerid, Health); //There is no need for the Float: tag, that is only when introducing it. (Eg. new Float:)
tbhealedhealth = 100-Health;
if(IsPlayerInRangeOfPoint(playerid, 5, HealPos1X, HealPos1Y, HealPos1Z)) //I'm assuming you have values for these saved somewhere else.
{
if(Health >= 100) return SendClientMessage(playerid, GREY, "You already have full health.");
if(Health > 40)
{
Player[playerid][HealTime] = tbhealedhealth; //Stores the to be healed health as a time in seconds to a player stat
Player[playerid][HealPrice] = tbhealedhealth*3; //Triples the to be healed health, this is the amount they must pay then stores it to a player stat
Player[playerid][BeingHealed] = 1; //Being healed at hospital 1 (Will put in hospital 2 if this can be fixed)
format(string, sizeof(string), "You are now undergoing hospital treatment. You will be released in %d seconds.", Player[playerid][HealTime]);
SendClientMessage(playerid, -1, string);
SetPlayerPos(playerid, 1161.2238, -1321.6235, 19); // Everything below is just setting cam pos etc. whilst they are in hospital
SetPlayerVirtualWorld(playerid, playerid);
TogglePlayerControllable(playerid, false);
SetPlayerCameraPos(playerid, 1217.4056, -1321.4524, 31.1270);
SetPlayerCameraLookAt(playerid, 1173.2889, -1322.7111, 19.4345);
}
else
{
if(Health >= 1)
{
Player[playerid][HealTime] = tbhealedhealth;
Player[playerid][HealPrice] = tbhealedhealth*6;
Player[playerid][BeingHealed] = 1;
format(string, sizeof(string), "You are now undergoing hospital treatment. You will be released in %d seconds.", Player[playerid][HealTime]);
SendClientMessage(playerid, -1, string);
SetPlayerPos(playerid, 1161.2238, -1321.6235, 19);
SetPlayerVirtualWorld(playerid, playerid);
TogglePlayerControllable(playerid, false);
SetPlayerCameraPos(playerid, 1217.4056, -1321.4524, 31.1270);
SetPlayerCameraLookAt(playerid, 1173.2889, -1322.7111, 19.4345);
}
}
}
return 1;
}
pawn Код:
|