@7smiths I have a similar script in SORX an I adapted to fit in your purpose.Or maybe make it so it drains if you do not move, but if you move it stops draining?
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());
}
}
name Axel
type player
health 100
script data/scripts/drain.c
Thanks buddy. I didn't test yet but adapted the script to fit in a global event like level update or updated.c.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)
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());
}
}
}