mpbar for npc as he is player 2

Steven1985

Active member
Hi, I created this script to have mpbar of npc as he is player2. In the file header of npc I put ondrawscript data/scripts/ondraw/npcmpbar.c.
This is the script:
C:
void main()
{
    createMPBar();
    updateMPBar();
    destroyMPBar();
}



void createMPBar(int target) {
    int x = 201;
    int y = 19;
    int w = getlocalvar("w", 100);
    int h = getlocalvar("h", 2);
    int noborder = getlocalvar("noborder", 0);
    int type = getlocalvar("type", 0);
    int orientation = getlocalvar("orientation", 0);
    int border = getlocalvar("border", 0);
    int shadow = getlocalvar("shadow", 0);
    int graph = getlocalvar("graph", 0);
    int backfill = getlocalvar("backfill", 0);
    int color1 = rgbcolor(0x00, 0xFF, 0xFF); // CYAN BAR, MP REMAINING
    int color2 = rgbcolor(0x00, 0x00, 0xFF); // BLUE BAR, MP LOST

    void bar = bindentity(target);

    if (bar) {
        setentityvar(bar, "mp", 100); // Imposta la quantità di MP iniziale
        setentityvar(bar, "mp_max", 100); // Imposta il massimo numero di MP
        setentityvar(bar, "mp_color1", color1);
        setentityvar(bar, "mp_color2", color2);

        // Crea la barra
        void mpbar = makebar(bar, x, y, w, h, noborder, type, orientation, border, shadow, graph, backfill);
        setentityvar(bar, "mp_bar", mpbar);
    }
}


void updateMPBar(int target, int mp, int mp_max) {
    void bar = bindentity(target);

    if (bar) {
        setentityvar(bar, "mp", mp);
        setentityvar(bar, "mp_max", mp_max);

        // Aggiorna la barra
        updatebar(getentityvar(bar, "mp_bar"));
    }
}

void destroyMPBar(int target) {
    void bar = bindentity(target);

    if (bar) {
        void mpbar = getentityvar(bar, "mp_bar");
        killentity(mpbar); // Distruggi la barra
    }
}

But I have this error: Can't compile script 'ondrawscript' data/chars/players/nick_fury/nick_fury_cpu.txt

Thank you in advance.
 
All three functions in main() have parameters which must be set yet they don't have any set.
C:
void main()
{
    createMPBar(?);
    updateMPBar(?, ?, ?);
    destroyMPBar(?);
}

I only put ?s there to specify missing parameters, Don't actually type those in.
Also I noticed that there are functions I've never seen before. I assume they are imported from other scripts which aren't declared here.
All of these makes me want to ask: where did you get this script? is this how the script set?
 
All three functions in main() have parameters which must be set yet they don't have any set.
C:
void main()
{
    createMPBar(?);
    updateMPBar(?, ?, ?);
    destroyMPBar(?);
}

I only put ?s there to specify missing parameters, Don't actually type those in.
Also I noticed that there are functions I've never seen before. I assume they are imported from other scripts which aren't declared here.
All of these makes me want to ask: where did you get this script? is this how the script set?
I created by ChatGPT.
 
I created by ChatGPT.
That is the problem - ChatGPT isn't good for that. OpenBOR uses a C-like language, not a strict C language.

Also, there are other issues aside the ones BB said above:
- I can't remember, but I think NPC doesn't have a MP setting
- Some stuff the code is talking about can't be accessed by script (for now), like "backfill"
 
Hi, I created this script to have mpbar of npc as he is player2. In the file header of npc I put ondrawscript data/scripts/ondraw/npcmpbar.c.
This is the script:
C:
void main()
{
    createMPBar();
    updateMPBar();
    destroyMPBar();
}



void createMPBar(int target) {
    int x = 201;
    int y = 19;
    int w = getlocalvar("w", 100);
    int h = getlocalvar("h", 2);
    int noborder = getlocalvar("noborder", 0);
    int type = getlocalvar("type", 0);
    int orientation = getlocalvar("orientation", 0);
    int border = getlocalvar("border", 0);
    int shadow = getlocalvar("shadow", 0);
    int graph = getlocalvar("graph", 0);
    int backfill = getlocalvar("backfill", 0);
    int color1 = rgbcolor(0x00, 0xFF, 0xFF); // CYAN BAR, MP REMAINING
    int color2 = rgbcolor(0x00, 0x00, 0xFF); // BLUE BAR, MP LOST

    void bar = bindentity(target);

    if (bar) {
        setentityvar(bar, "mp", 100); // Imposta la quantità di MP iniziale
        setentityvar(bar, "mp_max", 100); // Imposta il massimo numero di MP
        setentityvar(bar, "mp_color1", color1);
        setentityvar(bar, "mp_color2", color2);

        // Crea la barra
        void mpbar = makebar(bar, x, y, w, h, noborder, type, orientation, border, shadow, graph, backfill);
        setentityvar(bar, "mp_bar", mpbar);
    }
}


void updateMPBar(int target, int mp, int mp_max) {
    void bar = bindentity(target);

    if (bar) {
        setentityvar(bar, "mp", mp);
        setentityvar(bar, "mp_max", mp_max);

        // Aggiorna la barra
        updatebar(getentityvar(bar, "mp_bar"));
    }
}

void destroyMPBar(int target) {
    void bar = bindentity(target);

    if (bar) {
        void mpbar = getentityvar(bar, "mp_bar");
        killentity(mpbar); // Distruggi la barra
    }
}

But I have this error: Can't compile script 'ondrawscript' data/chars/players/nick_fury/nick_fury_cpu.txt

Thank you in advance.
@Steven1985 You can adapt the health bar in the cpu partner script I posted to show the mp, like this.

C:
void drawMp()
{//Draw mp bar in the screen for NPCs

    if(openborvariant("in_level")){ //IN ANY LEVEL??
        void self    = getlocalvar("self");
        void type    = getentityproperty(self, "type");
        void sType    = getentityproperty(self, "subtype");

        if(type == openborconstant("TYPE_NPC") && sType == openborconstant("SUBTYPE_FOLLOW")){
            int maxMp        = getentityproperty(self, "maxmp");
            int mp            = getentityproperty(self, "mp");
            int x            = 1; //X POSITION
            int y            = 150; //Y POSITION
            int z            = 1001; //LAYER
            int colorBlue    = rgbcolor(0,0,255);
            int colorBlack    = rgbcolor(0,0,0);
            int colorWhite    = rgbcolor(255,255,255);
            float xSize        = 100; //BAR WIDTH INCREASE FACTOR, MORE VALUE IS MORE SIZE
            float ySize        = 4; //BAR HEIGHT INCREASE FACTOR, MORE VALUE IS MORE SIZE
            
            //DRAW MP BAR
            mp            = (mp*xSize)/maxMp; //CALCULATE REMAINING MP BAR SIZE
            maxMp        = (maxMp*xSize)/maxMp; //CALCULATE MAX MP BAR SIZE
            drawbox(x, y, mp, ySize, z+3, colorBlue, 0); //DRAW MP REMAINING
            drawbox(x, y, maxMp, ySize, z+1, colorBlack, 0); //DRAW BACKFILL
            drawbox(x-1, y-1, maxMp+2, ySize+2, z, colorWhite, 0); //DRAW WHITE BORDER
        }
    }
}

 
@Steven1985 You can adapt the health bar in the cpu partner script I posted to show the mp, like this.

C:
void drawMp()
{//Draw mp bar in the screen for NPCs

    if(openborvariant("in_level")){ //IN ANY LEVEL??
        void self    = getlocalvar("self");
        void type    = getentityproperty(self, "type");
        void sType    = getentityproperty(self, "subtype");

        if(type == openborconstant("TYPE_NPC") && sType == openborconstant("SUBTYPE_FOLLOW")){
            int maxMp        = getentityproperty(self, "maxmp");
            int mp            = getentityproperty(self, "mp");
            int x            = 1; //X POSITION
            int y            = 150; //Y POSITION
            int z            = 1001; //LAYER
            int colorBlue    = rgbcolor(0,0,255);
            int colorBlack    = rgbcolor(0,0,0);
            int colorWhite    = rgbcolor(255,255,255);
            float xSize        = 100; //BAR WIDTH INCREASE FACTOR, MORE VALUE IS MORE SIZE
            float ySize        = 4; //BAR HEIGHT INCREASE FACTOR, MORE VALUE IS MORE SIZE
           
            //DRAW MP BAR
            mp            = (mp*xSize)/maxMp; //CALCULATE REMAINING MP BAR SIZE
            maxMp        = (maxMp*xSize)/maxMp; //CALCULATE MAX MP BAR SIZE
            drawbox(x, y, mp, ySize, z+3, colorBlue, 0); //DRAW MP REMAINING
            drawbox(x, y, maxMp, ySize, z+1, colorBlack, 0); //DRAW BACKFILL
            drawbox(x-1, y-1, maxMp+2, ySize+2, z, colorWhite, 0); //DRAW WHITE BORDER
        }
    }
}

Thank you very much Kratus to make the script work I had to put void main() to the place of void drawMP() :)
 
Back
Top Bottom