How to set health
#1

So i got a death system where when you have like 1 health you will need to wait for a medic or /acceptdeath but i dont want it to be like 1 health but more like 9 or 10
Code is here
pawn Код:
#include  <a_samp>
#include  <a_players>

        #define CYAN                                            0x00D2E1FF
        #define WHITE                                           0xFFFFFFAA
        #define PURPLE                      0xC2A2DAAA
        #define AFTERLIFE_SECONDS           120 // 1 Minutes
        #define AUTODEATH_SECONDS           300 // 1 Minutes
        #define SCM                                             SendClientMessage
        #define dcmd(%1,%2,%3)                          if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1

        new Float:DeathPosX                                     [MAX_PLAYERS];
        new Float:DeathPosY                                     [MAX_PLAYERS];
        new Float:DeathPosZ                                     [MAX_PLAYERS];
        new IsDead                                                      [MAX_PLAYERS];
        new SecsToGo                                            [MAX_PLAYERS];
        new IsAfterLifing                                       [MAX_PLAYERS];
        new AfterLifeTimer;

        forward AfterLife(playerid);
        forward AutoDeath(playerid);
        forward ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5);

        public OnPlayerSpawn(playerid)
        {
                IsAfterLifing[playerid] = 0;
                if (IsDead[playerid] == 1)
                {
                    SetPlayerPos(playerid,DeathPosX[playerid],DeathPosY[playerid],DeathPosZ[playerid]);
                    SetPlayerCameraPos(playerid,DeathPosX[playerid],DeathPosY[playerid],DeathPosZ[playerid]+5);
                    SetPlayerCameraLookAt(playerid,DeathPosX[playerid],DeathPosY[playerid],DeathPosZ[playerid]);
                     TogglePlayerControllable(playerid,false);
                    ApplyAnimation(playerid,"PARACHUTE","FALL_skyDive_DIE", 4.0, 0, 0, 0, 1, 0);
                    SetTimerEx("AutoDeath",AUTODEATH_SECONDS * 10,false,"i",playerid);
                    SCM(playerid,CYAN,"------------------ Health Advise -----------------");
                    SCM(playerid,WHITE,"You are now laying death. You are bleeding to death.");
                    SCM(playerid,WHITE,"Remember that the medics can revive you.");
                    SCM(playerid,WHITE,"You can type /acceptdeath, if no medics are available.");
                    SCM(playerid,CYAN,"--------------------------------------------------------");
                    return 1;
                }
                return 1;
        }

        public OnPlayerDeath(playerid, killerid, reason)
        {
            new Float:pX, Float:pY, Float:pZ;
            GetPlayerPos(playerid, pX, pY, pZ);
            DeathPosX[playerid] = pX;
            DeathPosY[playerid] = pY;
            DeathPosZ[playerid] = pZ;
            IsDead[playerid] = 10;
            return 1;
        }

        public OnPlayerCommandText(playerid, cmdtext[])
        {
                dcmd(acceptdeath, 11, cmdtext);
                return 0;
        }

        dcmd_acceptdeath(playerid, params[])
        {
                #pragma unused params
                if (IsDead[playerid] == 0) { return 0; }
                else
                {
                    IsDead[playerid] = 0;
                    SecsToGo[playerid] = AFTERLIFE_SECONDS;
                    CleanPlayerChat(playerid);
                    SCM(playerid,CYAN,"------------------ Health Advise -----------------");
                    SCM(playerid,WHITE,"You are now in the afterlife. You may rest in peace.");
                    SCM(playerid,WHITE,"When you revive, you lost memory of last 30 minutes.");
                    SCM(playerid,WHITE,"If you were non-RPly killed, report the player at the forums.");
                    SCM(playerid,CYAN,"--------------------------------------------------------");
                    SetPlayerPos(playerid,0, 0, 0);
                    SetPlayerCameraPos(playerid,DeathPosX[playerid],DeathPosY[playerid],DeathPosZ[playerid]);
                    SetPlayerCameraLookAt(playerid,DeathPosX[playerid],DeathPosY[playerid],DeathPosZ[playerid]+100);
                    AfterLifeTimer = SetTimerEx("AfterLife",10,true,"i",playerid);
                    return 1;
                 }
        }

        public OnPlayerText(playerid, text[])
        {
                if (IsAfterLifing[playerid] == 10) { return 0; }
                return 1;
        }

        public AfterLife(playerid)
        {
                IsAfterLifing[playerid] = 10;
                SecsToGo[playerid]--;
            new string[128];
                format(string,sizeof(string),"~b~ ~h~ ~h~you are in afterlife~n~ ~b~ ~h~ ~h~you will revive in %d seconds",SecsToGo[playerid]);
                GameTextForPlayer(playerid,string,1100,3);
                if (SecsToGo[playerid] <= 0)
            {
                CleanPlayerChat(playerid);
                KillTimer(AfterLifeTimer);
                SCM(playerid,CYAN,"------------------ Health Advise -----------------");
                    SCM(playerid,WHITE,"You have revived after a long rest.");
                    SCM(playerid,WHITE,"The medics have threated you and now you are healthy.");
                    SCM(playerid,WHITE,"Remember, you have lost memory of recent 30 minutes.");
                    SCM(playerid,CYAN,"--------------------------------------------------------");
                    SpawnPlayer(playerid);
                    return 1;
                }
                return 1;
        }

        public AutoDeath(playerid)
        {
                if (IsDead[playerid] == 0) { return 0; }
                else if (IsDead[playerid] == 1)
                {
                    new saystring[128], deathstring[128], name[28];
                    GetPlayerName(playerid,name,sizeof(name));
                        switch (random(2))
                        {
                        case 0:
                                {
                                        format(saystring,sizeof(saystring),"%s mumbles: I can't hold more..", name);
                                        format(deathstring,sizeof(deathstring),"* %s closes his eyes, falling into death.", name);
                                }
                                case 1:
                                {
                                    format(saystring,sizeof(saystring),"%s mumbles: Aghh.. It's cold.. I feel something.. A light-..",name);
                                    format(deathstring,sizeof(deathstring),"* %s is now inmobilized, and dead.",name);
                                }
                        }
                        ProxDetector(30, playerid, deathstring, PURPLE,PURPLE,PURPLE,PURPLE,PURPLE);
                        ProxDetector(10, playerid, saystring, WHITE,WHITE,WHITE,WHITE,WHITE);

                        IsDead[playerid] = 0;
                    SecsToGo[playerid] = AFTERLIFE_SECONDS;
                    SCM(playerid,CYAN,"------------------ Health Advise -----------------");
                    SCM(playerid,WHITE,"You are now in the afterlife. You may rest in peace.");
                    SCM(playerid,WHITE,"When you revive, you lost memory of last 30 minutes.");
                    SCM(playerid,WHITE,"If you were non-RPly killed, report the player at the forums.");
                    SCM(playerid,CYAN,"--------------------------------------------------------");
                    SetPlayerPos(playerid,0, 0, 0);
                    SetPlayerCameraPos(playerid,DeathPosX[playerid],DeathPosY[playerid],DeathPosZ[playerid]);
                    SetPlayerCameraLookAt(playerid,DeathPosX[playerid],DeathPosY[playerid],DeathPosZ[playerid]+100);
                    AfterLifeTimer = SetTimerEx("AfterLife",10,true,"i",playerid);
                    return 1;
                }
                return 1;
        }




        public ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5)
        {
            if(IsPlayerConnected(playerid))
            {
                new Float:posx, Float:posy, Float:posz;
                new Float:oldposx, Float:oldposy, Float:oldposz;
                new Float:tempposx, Float:tempposy, Float:tempposz;
                GetPlayerPos(playerid, oldposx, oldposy, oldposz);
                for(new i = 0; i < MAX_PLAYERS; i++)
                {
                    if(IsPlayerConnected(i) && (GetPlayerVirtualWorld(playerid) == GetPlayerVirtualWorld(i)))
                    {
                        GetPlayerPos(i, posx, posy, posz);
                        tempposx = (oldposx -posx);
                        tempposy = (oldposy -posy);
                        tempposz = (oldposz -posz);
                        if (((tempposx < radi/16) && (tempposx > -radi/16)) && ((tempposy < radi/16) && (tempposy > -radi/16)) && ((tempposz < radi/16) && (tempposz > -radi/16)))
                        {
                            SendClientMessage(i, col1, string);
                        }
                        else if (((tempposx < radi/8) && (tempposx > -radi/8)) && ((tempposy < radi/8) && (tempposy > -radi/8)) && ((tempposz < radi/8) && (tempposz > -radi/8)))
                        {
                            SendClientMessage(i, col2, string);
                        }
                        else if (((tempposx < radi/4) && (tempposx > -radi/4)) && ((tempposy < radi/4) && (tempposy > -radi/4)) && ((tempposz < radi/4) && (tempposz > -radi/4)))
                        {
                            SendClientMessage(i, col3, string);
                        }
                        else if (((tempposx < radi/2) && (tempposx > -radi/2)) && ((tempposy < radi/2) && (tempposy > -radi/2)) && ((tempposz < radi/2) && (tempposz > -radi/2)))
                        {
                            SendClientMessage(i, col4, string);
                        }
                        else if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
                        {
                            SendClientMessage(i, col5, string);
                        }
                    }
                }
            }
            return 1;
        }

        stock CleanPlayerChat(playerid)
        {
                SCM(playerid,WHITE," ");
                SCM(playerid,WHITE," ");
                SCM(playerid,WHITE," ");
                SCM(playerid,WHITE," ");
                SCM(playerid,WHITE," ");
                SCM(playerid,WHITE," ");
                SCM(playerid,WHITE," ");
                SCM(playerid,WHITE," ");
                SCM(playerid,WHITE," ");
                SCM(playerid,WHITE," ");
                SCM(playerid,WHITE," ");
                SCM(playerid,WHITE," ");
                SCM(playerid,WHITE," ");
                SCM(playerid,WHITE," ");
                SCM(playerid,WHITE," ");
                SCM(playerid,WHITE," ");
                SCM(playerid,WHITE," ");
        }
Reply
#2

I don't get what you want us to fix or help you.
Reply
#3

Do you mean when you have 9%/10% of your health remaining?
(9HP - 10HP)?
Reply
#4

Quote:
Originally Posted by Goldino
Посмотреть сообщение
I don't get what you want us to fix or help you.
I want you guys to help me out how to set the health limit where you need to wait for a medic or /acceptdeath instead of it having to be 1 health...-.-
Reply
#5

Quote:
Originally Posted by captainjohn
Посмотреть сообщение
Do you mean when you have 9%/10% of your health remaining?
(9HP - 10HP)?
Yes thats what i want
Reply
#6

I get it. When your health reduces to 1 HP, you need to wait for a 'medic' to be 'revived.' He wants us to help him make the limit of 1HP to 9 - 10HP, seeing as you don't get on 1HP mostly, you either survive or you die.
I didn't see any detection for health in the script you have given. (If it is there, forgive me)
Reply
#7

I think I understand what you are looking for?

You need to Get the players health first.
https://sampwiki.blast.hk/wiki/GetPlayerHealth
Reply
#8

Like Rajat said, the chance is really small to get exactly 1 hp.
You can better us a range of like 1-15 hp, with other words:

Quote:

new Float: health;
GetPlayerHealth(playerid, health);
if(health <= 10)
{
//code
}

You can use something like this in OnPlayerTakeDamage or in a timer, in OnPlayerTakeDamage it's better, since you will use less memory then...

At the part of //code you can use SetPlayerHealth(playerid, 999999), so the player gets godmode. Apart from that you can then use the rest of your code, like: /acceptdeath etc.

Good luck
Reply
#9

Quote:
Originally Posted by Strawhats
Посмотреть сообщение
Like Rajat said, the chance is really small to get exactly 1 hp.
You can better us a range of like 1-15 hp, with other words:



You can use something like this in OnPlayerTakeDamage or in a timer, in OnPlayerTakeDamage it's better, since you will use less memory then...

At the part of //code you can use SetPlayerHealth(playerid, 999999), so the player gets godmode. Apart from that you can then use the rest of your code, like: /acceptdeath etc.

Good luck
im getting errors

C:\Users\Humi\Desktop\REVO-RP\PR-RP\filterscripts\death.pwn(20) : error 021: symbol already defined: "GetPlayerHealth"
C:\Users\Humi\Desktop\REVO-RP\PR-RP\filterscripts\death.pwn(21) : error 010: invalid function or declaration
C:\Users\Humi\Desktop\REVO-RP\PR-RP\filterscripts\death.pwn(34) : warning 217: loose indentation
C:\Users\Humi\Desktop\REVO-RP\PR-RP\filterscripts\death.pwn(35) : warning 217: loose indentation
C:\Users\Humi\Desktop\REVO-RP\PR-RP\filterscripts\death.pwn(96) : warning 217: loose indentation
C:\Users\Humi\Desktop\REVO-RP\PR-RP\filterscripts\death.pwn(97) : warning 217: loose indentation
C:\Users\Humi\Desktop\REVO-RP\PR-RP\filterscripts\death.pwn(104) : warning 217: loose indentation
C:\Users\Humi\Desktop\REVO-RP\PR-RP\filterscripts\death.pwn(121) : warning 217: loose indentation
C:\Users\Humi\Desktop\REVO-RP\PR-RP\filterscripts\death.pwn(13 : warning 217: loose indentation
C:\Users\Humi\Desktop\REVO-RP\PR-RP\filterscripts\death.pwn(21 : warning 203: symbol is never used: "health
Reply
#10

I think you are missing a bracket?


Show us the code you have used.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)