Solved Bug with shadow trails

Question that is answered or resolved.

dantedevil

Well-known member
During the final test to share the first demo of my mod, i find a new bug.
This only happend when 2 players are playing.
Never happend when play alone.

4RJkunK.png


Sometimes the shadows of super combo shows bad, like in the picture. Other times the shadows only shows with normal colors, not blue like i set.
I start to have problems when change the update.c script to create a animated menu.
CRxTRDude helpme to solve the problem.
But yesterday , I discovered while playing with my daughter, that the problem is still there. I guess with three players also malfunction.

Here the files:

updated.c:
Code:
#include "data/scripts/anititle.c"
#include "data/scripts/story/story_define.h"
#include "data/scripts/story.c"
#include "data/scripts/gettick.c"


void zoom()
{
   void vscreen = openborvariant("vscreen");
   int maxz=openborvariant("PLAYER_MAX_Z")+1000;
   int zoom_value=getglobalvar("zoomvalue");
   int zoom_x=getglobalvar("zoomx");
   int zoom_y=getglobalvar("zoomy");
   void ent=getglobalvar("zoomentity");
   int px=getentityproperty(ent,"x") +  zoom_x - openborvariant("xpos");
   int py=getentityproperty(ent,"z") + zoom_y - openborvariant("ypos") - getentityproperty(ent,"a");
   void zoom_scr = getglobalvar("zoomscreen");
   if(!zoom_scr){
      zoom_scr = allocscreen(openborvariant("hResolution"),openborvariant("vResolution"));
      setglobalvar("zoomscreen",zoom_scr);
   }
   clearscreen(zoom_scr);

   //draw what we need
   drawspriteq(zoom_scr,0,openborconstant("MIN_INT"),maxz,0,0);
   //setup drawMethod
   changedrawmethod(NULL(),"reset",1);
   changedrawmethod(NULL(),"enabled",1);
   changedrawmethod(NULL(),"scalex",zoom_value);
   changedrawmethod(NULL(),"scaley",zoom_value);
   changedrawmethod(NULL(),"centerx",px);
   changedrawmethod(NULL(),"centery",py);
   //Draw the resized customized screen to main screen.
   drawscreen(zoom_scr,px,py, maxz+1);
   changedrawmethod(NULL(),"enabled", 0);
   drawspriteq(vscreen, 0, maxz+1,maxz+1, 0, 0);
   drawspriteq(vscreen, 0, maxz+2,openborconstant("MAX_INT"), 0, 0);
   clearspriteq();
}


void main(){
   if(getglobalvar("zoomentity"))
   {
      zoom();      
   }
      mainLoop();
}

void mainLoop(){
    void scene=openborvariant("current_scene");
    if(openborvariant("in_level"))
    {
        turnWhite();
        storySystem();
    }
    if(openborvariant("in_titlescreen")){
        if (scene!="data/scenes/intro.txt"){
            inTitleLoop(1);
        }
    }
    else {
        inTitleLoop(0);   
    }
}





Here a example the trailer.c of Raiden :
Code:
#include "data/scripts/trailer.h"

void main()
{
    int i, j, k;
    void spr;
    int facing, cd;
    float a, z, x;
   
    void ent = getlocalvar("self");
    int anim = getentityproperty(ent, "animationid");
    void map;
    int elapsed_time = openborvariant("elapsed_time");

    if(anim == openborconstant("ANI_FREESPECIAL5")){ map = getentityproperty(ent, "colourtable", 0);}
    if(anim == openborconstant("ANI_FOLLOW8")){ map = getentityproperty(ent, "colourtable", 0);}
    if(anim == openborconstant("ANI_FOLLOW9")){ map = getentityproperty(ent, "colourtable", 0);}
    if(anim == openborconstant("ANI_FREESPECIAL14")){ map = getentityproperty(ent, "colourtable", 0);}
    setglobalvar("blahblah.map", map);


    if(elapsed_time%trailerd==0)
    {
        if((anim == openborconstant("ANI_FREESPECIAL5")) || (anim == openborconstant("ANI_FOLLOW8")) || (anim == openborconstant("ANI_FOLLOW9")) || (anim == openborconstant("ANI_FREESPECIAL14")))
        {
        spr = getentityproperty(ent, "sprite");
        x = getentityproperty(ent, "x");
        z = getentityproperty(ent, "z");
        a = getentityproperty(ent, "a");
        facing = !getentityproperty(ent, "direction");
        for(k=1; k<=trailermax; k++) //find an empty trailer slot
        {
            if(getglobalvar("trailer"+k+".s")==NULL())
            {
                setglobalvar("trailer"+k+".s", spr);
                setglobalvar("trailer"+k+".x", x);
                setglobalvar("trailer"+k+".z", z);
                setglobalvar("trailer"+k+".a", a);
                setglobalvar("trailer"+k+".f", facing);
                setglobalvar("trailer"+k+".c", trailerc*trailerd);
                break;
            }
        }
    }
    }
}

Here trailer.h:

Code:
int trailermax = 50; //total trailers the engine can handle
int trailerc = 5; // totally 5 trailer images for each character
int trailerd = 15; // delay to spawn next trailer, so trailer lasts for trailermax*trailerd


In every Level i must set:

updatescript data/scripts/traileru.c

Here the script:
Code:
#include "data/scripts/trailer.h"

void main()
{
    int i, j, k;
    void spr;
    int facing, cd;
    float a, z, x;
    float sx = 256;
    float sy = 256;
void map = getglobalvar("blahblah.map");
    for(i=1; i<=trailermax; i++)
    {
        spr = getglobalvar("trailer"+i+".s");
        if(spr)
        {
            cd = getglobalvar("trailer"+i+".c");
            if(!cd)
            {
                setglobalvar("trailer"+i+".c", NULL());
                setglobalvar("trailer"+i+".s", NULL());
                setglobalvar("trailer"+i+".x", NULL());
                setglobalvar("trailer"+i+".z", NULL());
                setglobalvar("trailer"+i+".a", NULL());
                setglobalvar("trailer"+i+".sx", NULL());
                setglobalvar("trailer"+i+".sy", NULL());
            }
            else
            {
                if(openborvariant("game_paused")==0)
                {
                    setglobalvar("trailer"+i+".c", cd-1);
                }
                x = getglobalvar("trailer"+i+".x");
                z = getglobalvar("trailer"+i+".z");
                a = getglobalvar("trailer"+i+".a");
                if ( getglobalvar("trailer"+i+".sx") != NULL()) { sx = getglobalvar("trailer"+i+".sx"); }
                if ( getglobalvar("trailer"+i+".sy") != NULL()) { sy = getglobalvar("trailer"+i+".sy"); }
                facing = getglobalvar("trailer"+i+".f");
                                //,entity ,flag ,scalex ,scaley ,flipx ,flipy ,shiftx ,alpha ,colourmap ,fillcolour ,rotate ,rotateflip ,transparencybg
                                //setdrawmethod(NULL(),1, 256,256,facing,0,0,6,0,0,0,0,0,getglobalvar("trailer"+i+".colormap"));
                                setdrawmethod(NULL(),1, sx, sy,facing,0,0,6,0,0,0,0,0,map);
                                //drawsprite(spr, x-openborvariant("xpos"), z-a-openborvariant("ypos"), z-i, 0);

                //setdrawmethod(NULL(), 1, 256, 256, facing, 0, 0, 6, 0);
                //drawsprite(sprite, int x, int y, int z, int sortid)
                drawsprite(spr, x-openborvariant("xpos"), z-a-openborvariant("ypos")-3, z-i, 0);
                                //setdrawmethod(NULL(),0, 256, 256,0,    0,0,0,0,0,0,0,0,NULL());
            }
        }
    }
}
 
Last edited:
Solution
dantedevil said:
OK, thanks.

Last question of this:
Code:
#import "data/scripts/shadowtrail.c"

void main() {
  void player = getlocalvar("self");

  check_shadow_trail(player);



    if ( getentityproperty(player, "defaultmodel") == "CAROLINA" && getentityproperty(player, "animationid") == openborconstant("ANI_FREESPECIAL5")
               && getentityproperty(player, "animpos") < 7 ) {
        set_shad_trail_flag(player,1);
    } else if ( getentityproperty(player, "defaultmodel") == "CAROLINA" && getentityproperty(player, "animationid") == openborconstant("ANI_FREESPECIAL5")
               && getentityproperty(player, "animpos") >= 7 ) {
        set_shad_trail_flag(player,0);
    }   

    else if ( getentityproperty(player, "defaultmodel") ==...
CRxTRDude told me this:

Sadly, I've been in and out of OpenBOR that I've been rusty in scripting.
Try asking others about this. It's basically clearing out the screen after drawing the trails.

So that's the way to fix this.
But I do not know how to do it.
 
I would like to help you, but this is far to hard to understand to me. :-\
Anyway, A lot of people have seen your post but cannot help.

The problem seems advanced.

Perhaps, try to ask directly to better coders of the community.

Also, if the bugs are very small and rare. If they don't make the game unplayable, they are certainly acceptable.

AFAIK, absolutly all openbor mods have a bunch of minor bugs. Mostly some rare visual bugs.

Anyway, good luck. :)
 
Thanks for your words my friend.

I hope can solve this soon.
I think Bloodbane have the key to solve this.

Anyway, soon will share the demo, with or without the bug.
 
You should indeed share the demo (with the bug), it will be easier for us to understand, debug and fix the problem than just reading code. It would also be helpful if you find a way to systematically reproduce the problem.
 
Piccolo said:
You should indeed share the demo (with the bug), it will be easier for us to understand, debug and fix the problem than just reading code. It would also be helpful if you find a way to systematically reproduce the problem.

This. Plus, I suggest you to open a topic with the question, not something generic like that. Most people won't enter on the topic to understand a generic questions.

I already saw this bug. its something related with how fast you need to use that feature.
 
You right my friend, si i change the name of the topic right now.
I think is the best.
You are right friend, I think it is best to rename the topic now.
A name according to the problem.

The bug with shadow trail persist and I have now discovered that the bug can occur when play alone too, when you use several times a super combo and the stage has script dialogues. The portraits of the dialogues look wrong with the blue colors of the shadows trails.
 
Sorry for late reply, I haven't been able to test it

The bug with shadow trail persist and I have now discovered that the bug can occur when play alone too, when you use several times a super combo and the stage has script dialogues. The portraits of the dialogues look wrong with the blue colors of the shadows trails.

Hmmm.... did the bug occur on stage without script dialogues?
 
White Dragon said:
I can suggest you to try my shadow trail script:
http://www.chronocrash.com/forum/index.php?topic=526.0

Well my friend,  i check that thread and still remember all post.  I want use your method at first, but never work for me, and ask for help in that thread, but at the end none show me the way to make it work.
So finally, searching in the forum i find the old method to do it, and work good for me. Until now...
So if you can share and make a fresh example of you method script, showing how use ot and how declare will be great.
 
dantedevil said:
White Dragon said:
I can suggest you to try my shadow trail script:
http://www.chronocrash.com/forum/index.php?topic=526.0

Well my friend,  i check that thread and still remember all post.  I want use your method at first, but never work for me, and ask for help in that thread, but at the end none show me the way to make it work.
So finally, searching in the forum i find the old method to do it, and work good for me. Until now...
So if you can share and make a fresh example of you method script, showing how use ot and how declare will be great.

Ok, man!

1) write a shadowtrail.c file and write in:
Code:
#define MAX_TRAILS 50

/*
Per pulire piano tutta la trail.
Impostare un flag ON come parametro nella func. Poi ad ogni aggiornamento dello sprite cancella la coda (localvar spr) 2 sprites per volta.
Quindi cancella 2 sprites e aggiorna di 1. Si cancellerà uno sprites per volta. Quando sono tutti cancellati pulisci la trail.
Se il flag è on e se tutta la coda è pulita allora non chiamare più il metodo draw_trail.
In alternativa si puà usare updated.c ed eseguire il metodo fintanto che la coda è piena...
*/


int clear_shadowtrail(void ent) {
    int i;

        for( i = 0; i < MAX_TRAILS; ++i) {
            setlocalvar("xpos"+ent+"_"+i, NULL());
            setlocalvar("zpos"+ent+"_"+i, NULL());
            setlocalvar("apos"+ent+"_"+i, NULL());
            setlocalvar("facing"+ent+"_"+i, NULL());
            setlocalvar("spr"+ent+"_"+i, NULL());
            setlocalvar(ent+"_k",NULL());
        }

   return 0;
}

int get_oldest(void ent, int maxtrails) {
    if ( getlocalvar(ent+"_k") == NULL() ) return NULL();
    else {
        int k,i;

        if ( getlocalvar(ent+"_k") != NULL() ) k = getlocalvar(ent+"_k")-1; else k = 0;
        if (k < 0 ) k = maxtrails-1;

        for( i = k+1; i < maxtrails; ++i) { // dal k+1 c'è possibilità di trovare il k-vecchio
            if ( getlocalvar("spr"+ent+"_"+i) != NULL() ) return i;
        }
        for( i = 0; i <= k; ++i) { // ricominciamo dall'inizio fino a k compreso (evidentemente 1 solo sprite in tutto)
            if ( getlocalvar("spr"+ent+"_"+i) != NULL() ) return i;
        }

        return NULL();
    }
}

int draw_shadowtrail(void ent, int maxtrails, int refresh_frm, int min_transp, int max_transp, int swap_flag, int on_off_switch) {
     int i = 0, k = 0, c = 0;
	 void spr = getentityproperty(ent, "sprite");
	 float x = getentityproperty(ent, "x");
     float z = getentityproperty(ent, "z");
     float a = getentityproperty(ent, "y");
	 int facing = getentityproperty(ent, "direction");
	 int colourmap = getentityproperty(ent, "colourmap");
     int elapsed_time = openborvariant("elapsed_time");
     float xpos, zpos, apos;

	 if ( facing == 1 ) facing = 0;
	 else facing = 1;

	 if ( maxtrails > MAX_TRAILS ) maxtrails = MAX_TRAILS;

     //drawstring( 10,200,0,"k:  "+getlocalvar(ent+"_k")+"  oldk:  "+get_oldest(ent, maxtrails));
     if ( elapsed_time%refresh_frm == 0 && openborvariant("in_level") ) { // memorizziamo sprites e posizioni nel tempo
            if ( getlocalvar(ent+"_k") != NULL() ) k = getlocalvar(ent+"_k"); else k = 0;

            // SPRITES SWAP
            if ( swap_flag && getlocalvar(ent+"_k") != NULL() ) {
                int tk = k;
                void tspr = NULL();

                for( i = 0; i < maxtrails; ++i) {
                    --tk;
                    if ( tk < 0 ) tk = maxtrails-1;
                    tspr = getlocalvar("spr"+ent+"_"+tk);
                    --tk;
                    if ( tk < 0 ) tk = maxtrails-1;
                    setlocalvar("spr"+ent+"_"+tk, tspr); // inseriamo lo sprite precedente nello slot ancora precedente
                }
            }
            // END SPRITES SWAP

            if ( on_off_switch && on_off_switch != NULL() ) {
                setlocalvar("xpos"+ent+"_"+k, x);
                setlocalvar("zpos"+ent+"_"+k, z);
                setlocalvar("apos"+ent+"_"+k, a);
                setlocalvar("facing"+ent+"_"+k, facing);
                setlocalvar("spr"+ent+"_"+k, spr);
                ++k;
                if ( k >= maxtrails ) k = 0;
                setlocalvar(ent+"_k", k); // Impostiamo il k recente
            } else {
                int old_k = get_oldest(ent, maxtrails);

                if ( getlocalvar(ent+"_k") != NULL() ) k = getlocalvar(ent+"_k")-1; else k = 0;
                if (k < 0 ) k = maxtrails-1;

                if ( old_k != NULL() ) setlocalvar("spr"+ent+"_"+old_k, NULL()); // cancelliamo lo sprite più vecchio

                if ( old_k != NULL() && old_k == k ) {
                        clear_shadowtrail(ent); // se abbiamo cancellato anche l'ultimo sprite, puliamo tutto!!
                        return 0;
                }
            } // fine on/off switch
     }

	 if ( openborvariant("in_level") ) { // draw trails

		 for( i = 0; i < maxtrails; ++i) {
                int transp, gradient;
                int layer = getentityproperty(ent, "setlayer");

                if ( getlocalvar("spr"+ent+"_"+i) != NULL() ) {
                     x = getlocalvar("xpos"+ent+"_"+i);
                     z = getlocalvar("zpos"+ent+"_"+i);
                     a = getlocalvar("apos"+ent+"_"+i);
                     facing = getlocalvar("facing"+ent+"_"+i);
                     spr = getlocalvar("spr"+ent+"_"+i);

                     // naturalmente il più recente deve essere il meno trasparente, ecco perchè usiamo k e non i!!
                     if ( getlocalvar(ent+"_k") != NULL() ) k = getlocalvar(ent+"_k")-1; else k = 0;
                     if (k < 0 ) k = maxtrails-1;
                     // Presa la k più recente impostiamo la k corrispondente alla i dalla più recente alla meno recente
                     // Dobbiamo sottrarre quindi maxtrails-i a k
                     /*for ( c = 0; c < i; ++c ) {
                        --k;
                        if ( k < 0 ) k = maxtrails-1;
                     }
                     gradient = maxtrails-1;
                     for ( c = 0; c < k; ++c ) {
                        --gradient;
                        if ( gradient < 0 ) gradient = maxtrails-1;
                     }*/

                     c = maxtrails-1-k;
                     gradient = (i+c)%maxtrails;

                     changedrawmethod(NULL(), "enabled", 1);
                     changedrawmethod(NULL(), "reset", 1);
                     //changedrawmethod(NULL(), "flag", 1);
                     //changedrawmethod(NULL(), "tintmode", 1);
                     //changedrawmethod(NULL(), "tintcolor", 0xFF00FF);
                     transp = ( (max_transp-min_transp)*(gradient+1)/maxtrails )+min_transp;
                     changedrawmethod(NULL(), "channelg", transp);
                     changedrawmethod(NULL(), "channelr", transp);
                     changedrawmethod(NULL(), "channelb", transp);

                     // (entity, int flag, int scalex, int scaley, int flipx, int flipy, int shiftx, int alpha, int remap, int fillcolor, int rotate, int fliprotate, int transparencybg, void* colourmap, int centerx, int centery);
                     setdrawmethod(NULL(), 1, 256, 256, facing, 0, 0, 6, 1, 0, 0, 0, 0, colourmap); // map: -1 = Use entity's colormap.

                     if ( x != NULL() ) drawsprite(spr, x-openborvariant("xpos"), z-a-openborvariant("ypos")-4, z-(maxtrails-1-gradient), layer);
                     changedrawmethod(NULL(), "enabled", 0);
                     changedrawmethod(NULL(), "reset", 1);
                     setdrawmethod(NULL(), 0);
                } // fine if spr != NULL()

		 } // fine for
	 } // if in_level

    return 1;
}

int check_shadow_trail(void player) {
    if ( get_shad_trail_flag(player) != NULL() ) {
        if ( draw_shadowtrail(player, 5, 15, 20, 160, 0, get_shad_trail_flag(player)) == 0 ) set_shad_trail_flag(player,NULL());
    }
}

int get_shad_trail_flag(void player) {
    return getentityvar(player, "shadowtrail");
}

int set_shad_trail_flag(void player, int value) {
    setentityvar(player, "shadowtrail", value);
}

2) write in your character entity text file:
script  data/scripts/player_script.c

and in player_script.c write:

Code:
#import "data/scripts/shadowtrail.c"

void main() {
  void player = getlocalvar("self");

  check_shadow_trail(player);



    if ( getentityproperty(player, "defaultmodel") == "CHARACTER_NAME" && getentityproperty(player, "animationid") == openborconstant("ANI_ATTACK1")
               && getentityproperty(player, "animpos") < 7 ) {
        set_shad_trail_flag(player,1);
    } else if ( getentityproperty(player, "defaultmodel") == "CHARACTER_NAME" && getentityproperty(player, "animationid") == openborconstant("ANI_ATTACK1")
               && getentityproperty(player, "animpos") >= 7 ) {
        set_shad_trail_flag(player,0);
    } else if ( getentityproperty(player, "defaultmodel") == "CHARACTER_NAME" && getentityproperty(player, "animationid") != openborconstant("ANI_ATTACK1")
               && getentityvar(player, "shadowtrail") != 0 ) {
        set_shad_trail_flag(player,0);
    }
}

Now in part 2 change "CHARACTER_NAME" with your charcter name, "ANI_ATTACK1" with your  shadowtrail attack/animation and 7 with your frame where the shadowtrail stops.  ;)
 
Well, i think solve the firts question.
I set like this and works perfect:

Code:
#include "data/scripts/shadowtrail.c"



#import "data/scripts/shadowtrail.c"

void main() {
  void player = getlocalvar("self");
  int animd_id = getentityproperty(player, "animationid");

  check_shadow_trail(player);



    if ( getentityproperty(player, "defaultmodel") == "CAROLINA" && getentityproperty(player, "animationid") == openborconstant("ANI_FREESPECIAL5")
               && getentityproperty(player, "animpos") < 7 ) {
        set_shad_trail_flag(player,1);
    } else if ( getentityproperty(player, "defaultmodel") == "CAROLINA" && getentityproperty(player, "animationid") == openborconstant("ANI_FREESPECIAL5")
               && getentityproperty(player, "animpos") >= 7 ) {
        set_shad_trail_flag(player,0);
    } else if ( getentityproperty(player, "defaultmodel") == "CAROLINA" && getentityproperty(player, "animationid") != openborconstant("ANI_FREESPECIAL5")
               && getentityvar(player, "shadowtrail") != 0 ) {
        set_shad_trail_flag(player,0);
    }     
    else if ( getentityproperty(player, "defaultmodel") == "CAROLINA" && getentityproperty(player, "animationid") == openborconstant("ANI_FOLLOW4")
               && getentityproperty(player, "animpos") < 9 ) {
        set_shad_trail_flag(player,1);
    } else if ( getentityproperty(player, "defaultmodel") == "CAROLINA" && getentityproperty(player, "animationid") == openborconstant("ANI_FOLLOW4")
               && getentityproperty(player, "animpos") >= 9 ) {
        set_shad_trail_flag(player,0);
    } else if ( getentityproperty(player, "defaultmodel") == "CAROLINA" && getentityproperty(player, "animationid") != openborconstant("ANI_FOLLOW4")
               && getentityvar(player, "shadowtrail") != 0 ) {
        set_shad_trail_flag(player,0);
    }     
    else if ( getentityproperty(player, "defaultmodel") == "CAROLINA" && getentityproperty(player, "animationid") == openborconstant("ANI_FOLLOW5")
               && getentityproperty(player, "animpos") < 56 ) {
        set_shad_trail_flag(player,1);
    } else if ( getentityproperty(player, "defaultmodel") == "CAROLINA" && getentityproperty(player, "animationid") == openborconstant("ANI_FOLLOW5")
               && getentityproperty(player, "animpos") >= 56 ) {
        set_shad_trail_flag(player,0);
    } else if ( getentityproperty(player, "defaultmodel") == "CAROLINA" && getentityproperty(player, "animationid") != openborconstant("ANI_FOLLOW5")
               && getentityvar(player, "shadowtrail") != 0 ) {
        set_shad_trail_flag(player,0);
    }     
   else if ( getentityproperty(player, "defaultmodel") == "CAROLINA" && getentityproperty(player, "animationid") == openborconstant("ANI_FREESPECIAL11")
               && getentityproperty(player, "animpos") < 26 ) {
        set_shad_trail_flag(player,1);
    } else if ( getentityproperty(player, "defaultmodel") == "CAROLINA" && getentityproperty(player, "animationid") == openborconstant("ANI_FREESPECIAL11")
               && getentityproperty(player, "animpos") >= 26 ) {
        set_shad_trail_flag(player,0);
    } else if ( getentityproperty(player, "defaultmodel") == "CAROLINA" && getentityproperty(player, "animationid") != openborconstant("ANI_FREESPECIAL11")
               && getentityvar(player, "shadowtrail") != 0 ) {
        set_shad_trail_flag(player,0);
    }
}

But I still do not know how set the color for remap.
 
@Dante, does it give off the bug now with recent changes? I see that WD's method is far better than your original one.

BTW, to add remapping, you change the shadowtrail.c to this:


Code:
#define MAX_TRAILS 50

/*
Per pulire piano tutta la trail.
Impostare un flag ON come parametro nella func. Poi ad ogni aggiornamento dello sprite cancella la coda (localvar spr) 2 sprites per volta.
Quindi cancella 2 sprites e aggiorna di 1. Si cancellerà uno sprites per volta. Quando sono tutti cancellati pulisci la trail.
Se il flag è on e se tutta la coda è pulita allora non chiamare più il metodo draw_trail.
In alternativa si puà usare updated.c ed eseguire il metodo fintanto che la coda è piena...
*/


int clear_shadowtrail(void ent) {
    int i;

        for( i = 0; i < MAX_TRAILS; ++i) {
            setlocalvar("xpos"+ent+"_"+i, NULL());
            setlocalvar("zpos"+ent+"_"+i, NULL());
            setlocalvar("apos"+ent+"_"+i, NULL());
            setlocalvar("facing"+ent+"_"+i, NULL());
            setlocalvar("spr"+ent+"_"+i, NULL());
            setlocalvar(ent+"_k",NULL());
        }

   return 0;
}

int get_oldest(void ent, int maxtrails) {
    if ( getlocalvar(ent+"_k") == NULL() ) return NULL();
    else {
        int k,i;

        if ( getlocalvar(ent+"_k") != NULL() ) k = getlocalvar(ent+"_k")-1; else k = 0;
        if (k < 0 ) k = maxtrails-1;

        for( i = k+1; i < maxtrails; ++i) { // dal k+1 c'è possibilità di trovare il k-vecchio
            if ( getlocalvar("spr"+ent+"_"+i) != NULL() ) return i;
        }
        for( i = 0; i <= k; ++i) { // ricominciamo dall'inizio fino a k compreso (evidentemente 1 solo sprite in tutto)
            if ( getlocalvar("spr"+ent+"_"+i) != NULL() ) return i;
        }

        return NULL();
    }
}

int draw_shadowtrail(void ent, int maxtrails, int refresh_frm, int min_transp, int max_transp, int swap_flag, int on_off_switch) {
     int i = 0, k = 0, c = 0;
	 void spr = getentityproperty(ent, "sprite");
	 float x = getentityproperty(ent, "x");
     float z = getentityproperty(ent, "z");
     float a = getentityproperty(ent, "y");
	 int facing = getentityproperty(ent, "direction");
	 int colourmap = getglobalvar("entityshadowmap");
     int elapsed_time = openborvariant("elapsed_time");
     float xpos, zpos, apos;

	 if ( facing == 1 ) facing = 0;
	 else facing = 1;

	 if ( maxtrails > MAX_TRAILS ) maxtrails = MAX_TRAILS;

     //drawstring( 10,200,0,"k:  "+getlocalvar(ent+"_k")+"  oldk:  "+get_oldest(ent, maxtrails));
     if ( elapsed_time%refresh_frm == 0 && openborvariant("in_level") ) { // memorizziamo sprites e posizioni nel tempo
            if ( getlocalvar(ent+"_k") != NULL() ) k = getlocalvar(ent+"_k"); else k = 0;

            // SPRITES SWAP
            if ( swap_flag && getlocalvar(ent+"_k") != NULL() ) {
                int tk = k;
                void tspr = NULL();

                for( i = 0; i < maxtrails; ++i) {
                    --tk;
                    if ( tk < 0 ) tk = maxtrails-1;
                    tspr = getlocalvar("spr"+ent+"_"+tk);
                    --tk;
                    if ( tk < 0 ) tk = maxtrails-1;
                    setlocalvar("spr"+ent+"_"+tk, tspr); // inseriamo lo sprite precedente nello slot ancora precedente
                }
            }
            // END SPRITES SWAP

            if ( on_off_switch && on_off_switch != NULL() ) {
                setlocalvar("xpos"+ent+"_"+k, x);
                setlocalvar("zpos"+ent+"_"+k, z);
                setlocalvar("apos"+ent+"_"+k, a);
                setlocalvar("facing"+ent+"_"+k, facing);
                setlocalvar("spr"+ent+"_"+k, spr);
                ++k;
                if ( k >= maxtrails ) k = 0;
                setlocalvar(ent+"_k", k); // Impostiamo il k recente
            } else {
                int old_k = get_oldest(ent, maxtrails);

                if ( getlocalvar(ent+"_k") != NULL() ) k = getlocalvar(ent+"_k")-1; else k = 0;
                if (k < 0 ) k = maxtrails-1;

                if ( old_k != NULL() ) setlocalvar("spr"+ent+"_"+old_k, NULL()); // cancelliamo lo sprite più vecchio

                if ( old_k != NULL() && old_k == k ) {
                        clear_shadowtrail(ent); // se abbiamo cancellato anche l'ultimo sprite, puliamo tutto!!
                        return 0;
                }
            } // fine on/off switch
     }

	 if ( openborvariant("in_level") ) { // draw trails

		 for( i = 0; i < maxtrails; ++i) {
                int transp, gradient;
                int layer = getentityproperty(ent, "setlayer");

                if ( getlocalvar("spr"+ent+"_"+i) != NULL() ) {
                     x = getlocalvar("xpos"+ent+"_"+i);
                     z = getlocalvar("zpos"+ent+"_"+i);
                     a = getlocalvar("apos"+ent+"_"+i);
                     facing = getlocalvar("facing"+ent+"_"+i);
                     spr = getlocalvar("spr"+ent+"_"+i);

                     // naturalmente il più recente deve essere il meno trasparente, ecco perchè usiamo k e non i!!
                     if ( getlocalvar(ent+"_k") != NULL() ) k = getlocalvar(ent+"_k")-1; else k = 0;
                     if (k < 0 ) k = maxtrails-1;
                     // Presa la k più recente impostiamo la k corrispondente alla i dalla più recente alla meno recente
                     // Dobbiamo sottrarre quindi maxtrails-i a k
                     /*for ( c = 0; c < i; ++c ) {
                        --k;
                        if ( k < 0 ) k = maxtrails-1;
                     }
                     gradient = maxtrails-1;
                     for ( c = 0; c < k; ++c ) {
                        --gradient;
                        if ( gradient < 0 ) gradient = maxtrails-1;
                     }*/

                     c = maxtrails-1-k;
                     gradient = (i+c)%maxtrails;

                     changedrawmethod(NULL(), "enabled", 1);
                     changedrawmethod(NULL(), "reset", 1);
                     //changedrawmethod(NULL(), "flag", 1);
                     //changedrawmethod(NULL(), "tintmode", 1);
                     //changedrawmethod(NULL(), "tintcolor", 0xFF00FF);
                     transp = ( (max_transp-min_transp)*(gradient+1)/maxtrails )+min_transp;
                     changedrawmethod(NULL(), "channelg", transp);
                     changedrawmethod(NULL(), "channelr", transp);
                     changedrawmethod(NULL(), "channelb", transp);

                     // (entity, int flag, int scalex, int scaley, int flipx, int flipy, int shiftx, int alpha, int remap, int fillcolor, int rotate, int fliprotate, int transparencybg, void* colourmap, int centerx, int centery);
                     setdrawmethod(NULL(), 1, 256, 256, facing, 0, 0, 6, 1, 0, 0, 0, 0, colourmap); // map: -1 = Use entity's colormap.

                     if ( x != NULL() ) drawsprite(spr, x-openborvariant("xpos"), z-a-openborvariant("ypos")-4, z-(maxtrails-1-gradient), layer);
                     changedrawmethod(NULL(), "enabled", 0);
                     changedrawmethod(NULL(), "reset", 1);
                     setdrawmethod(NULL(), 0);
                } // fine if spr != NULL()

		 } // fine for
	 } // if in_level

    return 1;
}

int check_shadow_trail(void player) {
    if ( get_shad_trail_flag(player) != NULL() ) {
        if ( draw_shadowtrail(player, 5, 15, 20, 160, 0, get_shad_trail_flag(player)) == 0 ) set_shad_trail_flag(player,NULL());
    }
}

int get_shad_trail_flag(void player) {
    return getentityvar(player, "shadowtrail");
}

int set_shad_trail_flag(void player, int value) {
    setentityvar(player, "shadowtrail", value);
}

and add the following on your player_script.c before check_shadow_trail:

Code:
	void entityshadowmap;

And add the rest of the similar code like this:

Code:
	entityshadowmap = getentityproperty(player, "colourtable", 0);

Example:

Code:
    if ( getentityproperty(player, "defaultmodel") == "CHARACTER_NAME" && getentityproperty(player, "animationid") == openborconstant("ANI_ATTACK1")
               && getentityproperty(player, "animpos") < 7 ) {
        set_shad_trail_flag(player,1);
        entityshadowmap = getentityproperty(player, "colourtable", 0);
    }

Finally add to the last bit:

Code:
	setglobalvar("entityshadowmap", entityshadowmap);

I think it's something like that. Needs verification though. If you get any problems with it, just copy back WD's original code.
 
Back
Top Bottom