Jump to content

Photo

stdExtra.zh

Header

  • Please log in to reply
37 replies to this topic

#1 MoscowModder

MoscowModder

    Sometimes lurking. Rarely posting.

  • Members
  • Location:Wisconsin

Posted 23 June 2012 - 03:02 PM

Moved to the script DB

 

As I've been scripting for my games, I've made some reusable functions that I thought could be handy for other scripters. I then had the idea of turning this collection of reusable functions and constants into a project for the whole scripting community. Just post your reusable functions and constants here, and I'll add them to the file.

 

Get stdExtra.zh from the script DB


Edited by MoscowModder, 24 July 2014 - 10:28 PM.
Moved to script DB


#2 aaa2

aaa2

    Wizard

  • Banned

Posted 23 June 2012 - 04:33 PM

CODE

const int CMB_FREEZE=2324334545454343463456653;         //these constants are for freezing things on the screen
const int CMB_FREEZEFFC=4324235344356655665325;
int combo0=-1;           //these ints save information about the first and second combo on a screen
int combo0cset=-1;
int combo1=-1;
int combo1cset=-1;
void freeze_screen(){              
            if(combo0==-1&&combo1==-1&&combo0cset==-1&&combo1cset==-1){      //if the first and second combo on the screen were not saved yet save them
                     combo0=Screen->ComboD[0];
                     combo1=Screen->ComboD[1];
                     combo0cset=Screen->ComboC[0];
                     combo1cset=Screen->ComboC[1];
            }
            if(combo0!=-1&&combo1!=-1&&combo0cset!=-1&&combo1cset!=-1){
                    Screen->ComboD[0] = CMB_FREEZE; //after saving combos freeze the screen
                    Screen->ComboD[1] = CMB_FREEZEFFC;
                    Screen->FastCombo( 0, 0, 0,combo0, combo0cset, 128 ); //hide the freeze combos
                    Screen->FastCombo( 0, 16, 0, combo1, combo1cset, 128 );
            }
            
}

void unfreeze_screen(){                  
            if(combo0!=-1&&combo1!=-1&&combo0cset!=-1&&combo1cset!=-1){
                     Screen->ComboD[0]=combo0;   //if there is data saved to restore combos restore them
                     Screen->ComboD[1]=combo1;
                     Screen->ComboC[0]= combo0cset;
                     Screen->ComboC[1]=combo1cset;  
                     combo0=-1;    //restore the slots for saving combos to the initial state
                     combo1=-1;
                     combo0cset=-1;
                     combo1cset=-1;

            }
}


These methods should help you to completely freeze a screen. They should work unless i made a typo. They should also be useful.(i blindcoded it but still i should have taken care of all eventualities). All the ifs and some unnecessary seeming code is used to make sure that the code ONLY operates within the parameters i thought about.

Edited by aaa2, 23 June 2012 - 04:35 PM.


#3 SUCCESSOR

SUCCESSOR

    Apprentice

  • Banned
  • Real Name:TJ

Posted 08 July 2012 - 05:37 AM

Here's a few functions I've made to serve my purposes. I don't know if they'll be useful to anyone else.
 


Edited by SUCCESSOR, 08 March 2015 - 08:50 PM.


#4 Mero

Mero

    Touch Fluffy Tail

  • Banned
  • Real Name:Tamamo No Mae
  • Location:Rainbow Factory

Posted 14 February 2013 - 09:49 PM

CODE
//Screen Dimensions
const int screenWidth = 256;
const int screenHeight = 176;

//Sprite Flips
const int FLIP_H = 1;
const int FLIP_V = 2;
const int FLIP_B = 3;

//Sprite Rotations
const int ROTATE_CW = 4;
const int ROTATE_CCW = 7;

//Sprite Flip+Rotation
const int ROTATE_CW_FLIP = 5;
const int ROTATE_CCW_FLIP = 6;

//NPC Misc Flags
const int NPCMF_DAMAGE          = 0x0001;
const int NPCMF_INVISIBLE       = 0x0002;
const int NPCMF_NOTRETURN       = 0x0004;
const int NPCMF_NOTENEMY        = 0x0008;
const int NPCMF_SPAWNFLICKER    = 0x0010;
const int NPCMF_LENSONLY        = 0x0020;
const int NPCMF_FLASHING        = 0x0040;
const int NPCMF_FLICKERING      = 0x0080;
const int NPCMF_TRANSLUCENT     = 0x0100;
const int NPCMF_SHIELDFRONT     = 0x0200;
const int NPCMF_SHIELDLEFT      = 0x0400;
const int NPCMF_SHIELDRIGHT     = 0x0800;
const int NPCMF_SHIELDBACK      = 0x1000;
const int NPCMF_HAMMERBREAK     = 0x2000;

//Prevents moving in any direction
void NoMovement()
{
    Link->InputUp = false; Link->PressUp = false;
    Link->InputDown = false; Link->PressDown = false;
    Link->InputLeft = false; Link->PressLeft = false;
    Link->InputRight = false; Link->PressRight = false;
}

//Converts velocity into a direction.
int VelocityToDir(float x, float y)
{
    if(x == 0 && y == 0) return -1;
    else return RadianAngleDir8(RadianAngle(0, x, 0, y));
}

//Converts the x component of a velocity into a direction.
int XSpeedToDir(float x)
{
    return VelocityToDir(x, 0);
}


//Converts the y component of a velocity into a direction.
int YSpeedToDir(float y)
{
    return VelocityToDir(0, y);
}

//Takes a direction of movement and gets the xspeed.
float DirToXSpeed(int dir)
{
    if(dir<4)
        return Cond((dir*2)-5 < -1, 0, (dir*2)-5);
    else
        return Cond(dir<6, -1.5, 1.5);
}

//Takes a direction of movement and gets the yspeed.
float DirToYSpeed(int dir)
{
    if(dir>7) dir = toggleBlock(dir);
    if(dir < 2) return 0;
    float ret = 1;
    if(dir>=4) ret += .5;
    return Cond(IsEven(dir), -ret, ret);
}

//Returns the angle in radians of a direction; used for weapon angles
float dirToRad(int dir)
{
    dir = Clamp(dir, 0, 15);
    if(dir<8) dir = toggleBlock(dir);
    dir = (dir+2)%8;
    return PI * dir / 4;
}

//Returns value from 0 to 360 rather than -180 to 180
float AnglePos(int x1, int y1, int x2, int y2)
{
    float angle = ArcTan(x2-x1, y2-y1)*57.2958;
    if(angle < 0)
        angle += 360;
    return angle;
}

//Returns the distance between the given Coordinate and Link's Center.
float DistanceLink(float x, float y)
{
    return Distance(CenterLinkX(), CenterLinkY(), x, y);
}

//Returns the distance between the Link's Center and a pointer.
float DistanceLink(ffc f)
{
    return Distance(CenterLinkX(), CenterLinkY(), CenterX(f), CenterY(f));
}
float DistanceLink(npc n)
{
    return Distance(CenterLinkX(), CenterLinkY(), CenterX(n), CenterY(n));
}
float DistanceLink(lweapon l)
{
    return Distance(CenterLinkX(), CenterLinkY(), CenterX(l), CenterY(l));
}
float DistanceLink(eweapon e)
{
    return Distance(CenterLinkX(), CenterLinkY(), CenterX(e), CenterY(e));
}

//Converts 8-way direction to 4-way
int dir8ToDir4(int dir)
{
    if(dir != Clamp(dir, 0, 15)) return -1;
    dir &= 7;
    if((dir & 4) == 0)
        return dir;
    else
        return Cond(IsEven(dir), DIR_UP, DIR_DOWN);
}

//Returns the reverse of the given direction.
int reverseDir(int dir)
{
    if(dir != Clamp(dir, 0, 15)) return -1;
    return Cond(dir<8, OppositeDir(dir), ((dir+4)%8)+8);
}

//Toggles weapon blockability by adjusting its direction
int toggleBlock (int dir)
{
    if(dir < 8) dir |= 8;
    else dir &= ~8;
    return dir;
}


#5 coolgamer012345

coolgamer012345

    🔸

  • Members
  • Location:Indiana, USA

Posted 14 February 2013 - 09:58 PM

what do these scripts do?

#6 Mero

Mero

    Touch Fluffy Tail

  • Banned
  • Real Name:Tamamo No Mae
  • Location:Rainbow Factory

Posted 14 February 2013 - 09:59 PM

It's a header file. icon_razz.gif

#7 MoscowModder

MoscowModder

    Sometimes lurking. Rarely posting.

  • Members
  • Location:Wisconsin

Posted 14 February 2013 - 10:47 PM

coolgamer012345: They aren't scripts - they're general-purpose functions and constants that scripters can use to save time when writing their own scripts.

LordVolcanon: Copying yours into my first post. Thanks!

#8 aaa2

aaa2

    Wizard

  • Banned

Posted 15 February 2013 - 03:59 AM

ok one that might be particularily useful:
CODE

void real_trigger_secrets(){
    if(Screen->Flags[SF_SECRETS]&2){
        Screen->TriggerSecrets();
    }else{
        Screen->TriggerSecrets();
        Screen->State[ST_SECRET]=true;
    }
}

Triggers secrets like the ingame engine does(its so easy why isnt it in std.zh? or did i miss it?)

#9 Mero

Mero

    Touch Fluffy Tail

  • Banned
  • Real Name:Tamamo No Mae
  • Location:Rainbow Factory

Posted 15 February 2013 - 07:32 PM

CODE
//Returns the id of the highest level item of the given class that Link has acquired.
int GetCurrentItem(int itemclass)
{
    itemdata id;
    int ret = -1;
    int curlevel = -1000;
    //143 is default max items, increase if you add lots of your own
    for(int i = 0; i < 143; i++)
    {
        if(!Link->Item[i])
            continue;
        id = Game->LoadItemData(i);
        if(id->Family != itemclass)
            continue;
        if(id->Level > curlevel)
            {
                curlevel = id->Level;
                ret = i;
            }
    }
    return ret;
}


#10 aaa2

aaa2

    Wizard

  • Banned

Posted 22 February 2013 - 03:34 PM

Even if you will keep ignoring what i post here
CODE

jumpstart_an_ffc_from_an_item_script(int ffc_slot_number, int d){//jumpstart an ffc script from item script
        int dvariables[8];
                if(d!=NULL){
                     for(int i=0; i<8; i++){
                             dvariables[i]=d[i];
                      }
                }
        if(FindFFCRunning(ffc_slot_number)<=0){
            RunFFCScriptOrQuit(ffc_slot_number, dvariables);
        }
}


item script generic_item_jumpstarter{
    void run(int ffc_id,int d0,int d1,int d2,int d3,int d4,int d5,int d6){
        int d[7] = {d0,d1,d2,d3,d4,d5,d6};
        jumpstart_an_ffc_from_an_item_script(ffc_id,d);
    }
}

This function cleanly starts a ffc script from a weapon script and is useful when making custom items i posted it for tox_von in another thread since he did not seem able to do it.

Edited by aaa2, 22 February 2013 - 06:30 PM.


#11 MoscowModder

MoscowModder

    Sometimes lurking. Rarely posting.

  • Members
  • Location:Wisconsin

Posted 22 February 2013 - 03:52 PM

That's not a complete function, and I don't really see how that could fit in a header file even if it were complete. It's a handy code snippet; it just doesn't fit here.

#12 aaa2

aaa2

    Wizard

  • Banned

Posted 22 February 2013 - 04:03 PM

Oops incompletely pasted my own code from the other thread. I fixed it. sorry
it should have been very obvious though what is missing there was only one undefined variable and the name of a function does not matter anyways.

Edited by aaa2, 22 February 2013 - 04:04 PM.


#13 MoscowModder

MoscowModder

    Sometimes lurking. Rarely posting.

  • Members
  • Location:Wisconsin

Posted 22 February 2013 - 05:05 PM

But it's still just a skeleton item+ffc script, not a function that you can call multiple times in multiple scripts from a header. It doesn't let you adjust the arguments for use in multiple scripts.

#14 aaa2

aaa2

    Wizard

  • Banned

Posted 22 February 2013 - 05:46 PM

I use this same function in every custom item i make just to let you know. It loads an ffc from a slot number actually you dont need any more functions to jumpstart a custom item. So to make a custom item with that function all you have to do is
CODE

const int id_of_your_custom_item_ffc=445; //this is the slot variable
item script some_stupid_item{
     void run(){
         jumpstart_an_ffc_from_an_item_script(id_of_your_custom_item_ffc);
     }
}

because of the code the item ffc will not get started multiple times under any circumstances. I have no idea what you talk about sorry! The ffc then handles all the behaviour of your custom item that most of the time gets handled in global scripts.

#15 aaa2

aaa2

    Wizard

  • Banned

Posted 23 February 2013 - 06:50 PM

CODE

bool Waitframe_check_for_screen_change(){
    bool changed_screen=false;
    int old_screen=Game->GetCurScreen();
    int old_dmap_screen=Game->GetCurDMapScreen();
    int old_dmap=Game->GetCurDMap();
    int old_map=Game->GetCurMap();
    Waitframe();
    if(old_screen!=GetCurScreen()||old_dmap!=Game->GetCurDMap()|| old_map!=Game->GetCurMap()||old_dmap_screen!=Game->GetCurDMapScreen()) changed_screen=true;
    return changed_screen;

}

a Waitframe that is extended by checking for screen changes in a very detailed maybe too detailed manner. Useful if you want to make sure to draw certain things whenever a screen change occurs.

CODE

bool Waitframe_check_if_link_started_warping_screen_change(){
   if( Waitframe_check_for_screen_change()&&!(Link->Action==LA_SCROLLING)) return true;
   else return false;
}

checks if a screen change occurred and if link is scrolling. If he isnt scrolling he must have started warping else a screen change would not have occurred. For some purposes might be equivalent to the non existent LA_WARPING(should be always if you always know how long a warp takes->very simple to keep track of it, however if not consistently enough handled(e.g many warp types which take differing times to complete ) a constant look-up-table might do the trick)



Also tagged with one or more of these keywords: Header

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users