Need some help.
#1

I am making a /heal command and it should be pretty simple but for some reason all of the values are so fucked up.

Here's the code:

pawn Код:
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;
}
And, for reference, what the values are actually used in (this is stored in a one-second timer that repeats)

pawn Код:
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);
                }
            }
No idea why it isn't working. I think it is something to do with the values that are being stored & I don't know why they would be wrong, they just seem to be crazily high numbers. Also... My timer doesn't work, the GameText that counts down the seconds remaining. It worked before I made a few adjustments. Any help on that too?
Reply
#2

Okay
pawn Код:
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;
}
If you need definitions, let me know
Reply
#3

What is HealPos1X, HealPos1Y, HealPos1Z? Where you use it? GetPlayerPos?
Reply
#4

Quote:
Originally Posted by _Khaled_
Посмотреть сообщение
Okay

<snip>

If you need definitions, let me know
Thanks! I'll try this now.

Quote:
Originally Posted by IceMeteor
Посмотреть сообщение
What is HealPos1X, HealPos1Y, HealPos1Z? Where you use it? GetPlayerPos?
HealPos1 etc. is a position that admins can set with another command. If you are familiar with VX-RP 1, it is used in /movelocation. Playeres have to be near it to use /heal.
Reply
#5

Quote:
Originally Posted by _Khaled_
Посмотреть сообщение
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;
}
Can you explain how are you getting the id of a non connected player?
Reply
#6

LMFAO! Newbie fail, lol remove it =D

replace it with this
pawn Код:
if(!IsPlayerConnected(id))
    {
        format(string,sizeof(string),"The Player is not connected to the server.");
        SendClientMessage(playerid,COLOR_RED,string);
        return 1;
    }
Reply
#7

pawn Код:
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;
}
Reply
#8

Quote:
Originally Posted by clarencecuzz
Посмотреть сообщение
pawn Код:
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;
}
This fixes some warnings I had but I still get one from line 3 (tbhealedhealth = 100-Health.

Most of my values are still messed up as well. Here is what I get when I /heal in-game and am released:

http://i.imgur.com/xmkEy.jpg

It releases me after the right amount of time but the amount I am billed & how long it says till I am released is crazy.

I don't know what's causing it to do this.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)