Possible?: health draining all the time, get items or defeat enemies to recover

7smiths

New member
Hi, I hope I can ask it here. The idea is... is it possible to make that e.g. that health of player always drains and you need to defeat enemies and/or get items to replenish it? Or maybe make it so it drains if you do not move, but if you move it stops draining?
 
Or maybe make it so it drains if you do not move, but if you move it stops draining?
@7smiths I have a similar script in SORX an I adapted to fit in your purpose.

Create a script named drain.c, put in the scripts folder and copy/paste all the content below inside it.
C:
void main()
{
    void self    = getlocalvar("self");
    void ani    = getentityproperty(self, "animationID");

    if(ani == openborconstant("ANI_IDLE")){
        float time = openborvariant("elapsed_time");
        float rate = 200; //CYCLE RATE, CAN BE FREELY CHANGED ACCORDING TO YOUR PURPOSE
        int health = getentityproperty(self, "health");
        int reduce = 10; //AMOUNT OF HEALTH TO BE REDUCED EACH CYCLE

        //START THE VARIABLE IF NULL
        if(getentityvar(self, "drainTime") == NULL()){
            setentityvar(self, "drainTime", time+rate);
        }

        //DRAIN HEALTH ACCORDING TO CERTAIN CONDITIONS
        if(getentityvar(self, "drainTime") < time){
            if(health > reduce){

                //USED TO REDUCE HEALTH ONLY
                changeentityproperty(self, "health", health-reduce);
            }
            else
            {
                //USED TO KILL THE PLAYER PROPERLY IN THE LAST DRAIN CYCLE
                damageentity(self, self, reduce, 1, openborconstant("ATK_NORMAL"));
            }
           
            //RENEW THE DRAIN RATE
            setentityvar(self, "drainTime", time+rate);
        }
    }
    else
    {
        //CLEAR THE DRAIN CYCLE VARIABLE IF THE CHARACTER IS NOT IN THE IDLE ANIMATION
        setentityvar(self, "drainTime", NULL());
    }
}

Then, call it as a script event at the character header like this:
Code:
name      Axel
type      player
health    100
script    data/scripts/drain.c

This is the result:
 
Last edited:
Nice, this could be used as a survivor stage, where you need to get itens to not die. (Although, on this case, I would adapt the code to be run at stage update script instead)
Thanks buddy. I didn't test yet but adapted the script to fit in a global event like level update or updated.c.

C:
void main()
{
    void player1 = getplayerproperty(0, "entity");
    void player2 = getplayerproperty(1, "entity");
    void player3 = getplayerproperty(2, "entity");
    void player4 = getplayerproperty(3, "entity");
    
    drainFunction(player1, 0);
    drainFunction(player2, 1);
    drainFunction(player3, 2);
    drainFunction(player4, 3);
}

void drainFunction(void player, int pIndex)
{
    if(player != NULL()){
        int exists = getentityproperty(player, "exists");
        void ani = getentityproperty(player, "animationID");

        if(exists && ani == openborconstant("ANI_IDLE")){
            float time = openborvariant("elapsed_time");
            float rate = 200; //CYCLE RATE, CAN BE FREELY CHANGED ACCORDING TO YOUR PURPOSE
            int health = getentityproperty(player, "health");
            int reduce = 10; //AMOUNT OF HEALTH TO BE REDUCED EACH CYCLE

            //START THE VARIABLE IF NULL
            if(getglobalvar("drainTime"+pIndex) == NULL()){
                setglobalvar("drainTime"+pIndex, time+rate);
            }

            //DRAIN HEALTH ACCORDING TO CERTAIN CONDITIONS
            if(getglobalvar("drainTime"+pIndex) < time){
                if(health > reduce){

                    //USED TO REDUCE HEALTH ONLY
                    changeentityproperty(player, "health", health-reduce);
                }
                else
                {
                    //USED TO KILL THE PLAYER PROPERLY IN THE LAST DRAIN CYCLE
                    damageentity(player, player, reduce, 1, openborconstant("ATK_NORMAL"));
                }

                //RENEW THE DRAIN RATE
                setglobalvar("drainTime"+pIndex, time+rate);
            }
        }
        else
        {
            //CLEAR THE DRAIN CYCLE VARIABLE IF THE CHARACTER IS NOT IN THE IDLE ANIMATION
            setglobalvar("drainTime"+pIndex, NULL());
        }
    }
}
 
Back
Top Bottom