ZoriaRPG icon

LinkHurtTile.zs

ZoriaRPG | PRO | 07/09/18 09:10:29 AM UTC | 0 ⭐ | 642 👁️ | Never ⏰ | []
C++ |

1.7 KB

|

None

|

0 👍

/

0 👎

//A small 2.54 script to use custom tiles when link is hurt. 
//By ZoriaRPG, 9th July, 2018
 
int __G[256];
const int gLINKTILECACHE = 100;
const int lmiscHURTTILE = 17;
const int lmiscflagHURTTILE = 1;
 
int frame; //global frame timer. As this will be called often, I'm making it a base int, not an array. 
 
 
//fake class
ffc script linktile
{
    void run()
    {
    }
    void clear()
    {
        Link->ScriptTile = -1;
    }
    void clearcache(int slot)
    {
        __G[slot] = -1;
    }
    void cache(int slot)
    {
        __G[slot] = Link->ScriptTile;
    }
    void restore(int cache_slot)
    {
        Link->ScriptTile = __G[cache_slot];
    }
    void dohurt()
    {
        if  ( Link->Action == LA_GOTHURTLAND ) 
        { 
            if ( ! (Link->Misc[lmiscHURTTIMER]&lmiscflagHURTTILE ) )
            {
                Link->Misc[lmiscHURTTILE] |= lmiscflagHURTTILE;
                cache(gLINKTILECACHE);
            }
                
            Link->ScriptTile = TILE_LINKHURT + ( 1 * getmodifier()) + animate(); 
            
        }
        else
        {
            if ( Link->Misc[lmiscHURTTIMER]&lmiscflagHURTTILE )
            {
                restore(gLINKTILECACHE);
            }
        }
    }
    int animate() 
    {
        if ( frame < 30 ) 
        {
            if ( frame < 15 ) { return 0; }
            return 20;
        }
        else if ( frame < 45 ) return 0;
        return 20;
    }
 
    int getmodifier()
    {
        itemdata shield = Game->LoadItemData(GetHighestlevelItemOwned(I_SHIELD));
        return ( shield->Level -1 ) * 260;
        
    }
}
 
global script Init
{
    void run()
    {
        linktile.clearcache(gLINKTILECACHE);
    }
 
}
 
global script LinkHurtTiles
{
    void run()
    {
        frame = -1;
        while(1)
        {
            if ( ++frame > 60 ) { frame = 0; }
            linktile.dohurt();
            Waitdraw();
            Waitframe();
        }
    }
}
 
global script onExit
{
    void run()
    {
        linktile.restore(gLINKTILECACHE);
    }
}

Comments