• All, I am currently in the process of migrating domain registrations. During this time there may be some intermittent outages or slowdowns. Please contact staff if you have any questions.

CPU Partner: Keep health and MP from previous level if there is no "next" before next level

Steven1985

Active member
Hi,
I'd like to know if there is a way to make it so that if the cpu partner or partners finish the level alive, they will spawn on the next level with the same amount of health and mp as the previous level if the stage was not completed (so without "next" before the next level).
Thank you in advance.
 
@Steven1985,

You will need to record their current health as a global variable when the level ends, then read that variable on spawn, and set the health accordingly.
Have I to do like this?
C-like:
void main()
{
    savePartner();
}

void savePartner()
{//Save CPU partner info when level ends

    void partner    = getglobalvar("currentPartner");
    void pName        = getentityproperty(partner, "defaultname");
    int pHealth        = getentityproperty(partner, "health");
    int pMp            = getentityproperty(partner, "mp");
    int addHealth;
    
    //CPU PARTNER COMPLETED THE LAST LEVEL ALIVE??
    if(getglobalvar("partnerAlive") == 1){
        setglobalvar("partnerName", pName);
        setglobalvar("partnerHealth", pHealth);
        setglobalvar("partnerMp", pMp);
    }
}
C-like:
onspawnscript        data/scripts/onspawn.c
 
@Steven1985 In case you are using my cpu partner template as base, it already was coded exactly on the way you need.

Save process
C:
//CPU PARTNER COMPLETED THE LAST LEVEL ALIVE??
if(getglobalvar("partnerAlive") == 1){
    setglobalvar("partnerName", pName);
    setglobalvar("partnerHealth", pHealth);
    setglobalvar("partnerMp", pMp);
}

Load process
C:
//PARTNER NEEDS TO FULLY REFILL HEALTH AND MP?? EXECUTE ALL STEPS BELOW, OTHERWISE KEEP PREVIOUS VALUES
if(getglobalvar("partnerFull") == 1){
    void partner    = getglobalvar("currentPartner");
    int maxHealth    = getentityproperty(partner, "maxhealth");
    int maxMp        = getentityproperty(partner, "maxmp");

    setglobalvar("partnerMp", maxMp);
    setglobalvar("partnerHealth", maxHealth);
    setglobalvar("partnerFull", 0);
}

changeentityproperty(vSpawn, "health", getglobalvar("partnerHealth")); //SET SPAWN HEALTH
changeentityproperty(vSpawn, "mp", getglobalvar("partnerMp")); //SET SPAWN MP
 
@Steven1985 In case you are using my cpu partner template as base, it already was coded exactly on the way you need.

Save process
C:
//CPU PARTNER COMPLETED THE LAST LEVEL ALIVE??
if(getglobalvar("partnerAlive") == 1){
    setglobalvar("partnerName", pName);
    setglobalvar("partnerHealth", pHealth);
    setglobalvar("partnerMp", pMp);
}

Load process
C:
//PARTNER NEEDS TO FULLY REFILL HEALTH AND MP?? EXECUTE ALL STEPS BELOW, OTHERWISE KEEP PREVIOUS VALUES
if(getglobalvar("partnerFull") == 1){
    void partner    = getglobalvar("currentPartner");
    int maxHealth    = getentityproperty(partner, "maxhealth");
    int maxMp        = getentityproperty(partner, "maxmp");

    setglobalvar("partnerMp", maxMp);
    setglobalvar("partnerHealth", maxHealth);
    setglobalvar("partnerFull", 0);
}

changeentityproperty(vSpawn, "health", getglobalvar("partnerHealth")); //SET SPAWN HEALTH
changeentityproperty(vSpawn, "mp", getglobalvar("partnerMp")); //SET SPAWN MP
I know but what have I do?
 
I didn't understand... Once it's already working, you don't need to do anything.
I wanted to have more than one partner in the next level if they all finished the previous level live, but you wrote that in this moment you don't have time to fix the scripts.
 
I wanted to have more than one partner in the next level if they all finished the previous level live
The code uses globalvariables and, as the name says, they are global - it doesn't matter which entity reads it, its a global value. It's one set of globarvars.

if you want to have, say, 2 partners, you will need to have 2 sets of variables.
or all partners will share the same values.
 
The code uses globalvariables and, as the name says, they are global - it doesn't matter which entity reads it, its a global value. It's one set of globarvars.

if you want to have, say, 2 partners, you will need to have 2 sets of variables.
or all partners will share the same values.
I've tried several times but nothing. I'll wait for @Kratus to do it.
 
Back
Top Bottom