Jump to content

Photo

Periodic reduction to a counter


  • Please log in to reply
49 replies to this topic

#46 justin

justin

    Adept

  • Members

Posted 16 December 2014 - 03:37 PM

here it is, it's pretty hilarious.  can be tweaked to your liking...

import "std.zh"
 
const int DRUNK_TIME = 3600;  // how long to make Link drunk for per beer.
const int DRUNK_EFFECT_CHANCE = 10; // percent chance that Link will be affected by Drunkeness effect that frame.  Multiplied by DRUNK_TIME, so more drunk means more drunk.
 
// set these to whatever you want drawn over Link to indicate the drunk effect.
// they are currently set to draw directly over Link, so most of the tile should be transparent.
 
const int DRUNK_ICON_LAYER = 7; // which layer to draw drunk effect onto.
const int DRUNK_ICON_COMBO = 1536; // which combo to use for drunk effect, can be an animated combo.
const int DRUNK_ICON_CSET = 0; // the cset of the drunk effect combo.
 
const int CR_BEER = 7; //The number of beers counter. This is the Script1 counter. 
const int CR_DRUNKENESS = 8; //The counter to use for confusion. This is the Script2 counter. 
 
const int LM_DRUNKACT = 0; // index to Link->Misc[] array, if any other scripts use this change it accordingly
const int LM_DRUNKACTTIME = 1; // index to Link->Misc[] array, if any other scripts use this change it accordingly
 
global script Init
{
          void run()
          {
                    Game->MCounter[CR_DRUNKENESS]=65535; //Max
                    Game->Counter[CR_DRUNKENESS] = 0;
          }
}
 
 
global script slot2
{
          void run()
          {
                    while(true)
                    {
                              //Waitdraw();
                              UpdateDrunkeness();
                              Waitframe();
                    }
          }
}
 
void UpdateDrunkeness()
{
          int random_act = 0;
 
        if(Game->Counter[CR_DRUNKENESS] == 0 && Game->Counter[CR_BEER] > 0){
                Game->Counter[CR_BEER] = 0;
        }
 
          if(Link->Drunk > 0)
          {
                    Game->Counter[CR_DRUNKENESS]=Link->Drunk;
                    Link->Drunk=0;
          }
 
          if(Game->Counter[CR_DRUNKENESS]>0)
          {
                    Game->Counter[CR_DRUNKENESS]--;
                    Screen->FastCombo(DRUNK_ICON_LAYER, Link->X, Link->Y, DRUNK_ICON_COMBO, DRUNK_ICON_CSET, OP_OPAQUE);
 
                    if(Link->Misc[LM_DRUNKACT] > 0){
                              if(Link->Misc[LM_DRUNKACTTIME] > 0){
                                        Drunk_Action();
                                        Link->Misc[LM_DRUNKACTTIME]--;
                              }else{
                                        Link->Misc[LM_DRUNKACT] = 0;
                              }
                    }
 
                    // Game->Counter[CR_DRUNKENESS]%30 == 0 &&
 
                    if( Drunk_Effect() ) {
                              Link->Misc[LM_DRUNKACT] = Rand(15);
                              if(Link->Misc[LM_DRUNKACT] <= 11) Link->Misc[LM_DRUNKACTTIME] = 30;
                              else Link->Misc[LM_DRUNKACTTIME] = 0;
 
                              Drunk_Action();
                    }
          }
}
 
bool Drunk_Effect(){
    return (Rand(100) <= DRUNK_EFFECT_CHANCE * (Max(1,Game->Counter[CR_DRUNKENESS]/DRUNK_TIME)) );
}
 
void Drunk_Action(){
          int temp = 0;
 
          if(Link->Misc[LM_DRUNKACT] <= 3){
                    Link->Dir = Link->Misc[LM_DRUNKACT];
          }else if(Link->Misc[LM_DRUNKACT] <= 7){
                    if(Link->Misc[LM_DRUNKACT] == 4){
                              Link->InputDown = false;
                              Link->InputLeft = false;
                              Link->InputRight = false;
 
                              Link->InputUp = true;
                    }else if(Link->Misc[LM_DRUNKACT] == 5){
                              Link->InputUp = false;
                              Link->InputLeft = false;
                              Link->InputRight = false;
 
                              Link->InputDown = true;
                    }else if(Link->Misc[LM_DRUNKACT] == 6){
                              Link->InputUp = false;
                              Link->InputDown = false;
                              Link->InputRight = false;
 
                              Link->InputLeft = true;
                    }else{
                              Link->InputUp = false;
                              Link->InputDown = false;
                              Link->InputLeft = false;
 
                              Link->InputRight = true;
                    }
 
                    Link->Dir = Link->Misc[LM_DRUNKACT]-4;
          }else if(Link->Misc[LM_DRUNKACT] == 8){
                    Link->InputDown = false;
                    Link->InputLeft = false;
                    Link->InputRight = false;
 
                    temp = Link->Dir;
                    Link->InputUp;
                    Link->Dir = temp;
          }else if(Link->Misc[LM_DRUNKACT] == 9){
                    Link->InputUp = false;
                    Link->InputLeft = false;
                    Link->InputRight = false;
 
                    temp = Link->Dir;
                    Link->InputDown;
                    Link->Dir = temp;
          }else if(Link->Misc[LM_DRUNKACT] == 10){
                    Link->InputUp = false;
                    Link->InputDown = false;
                    Link->InputRight = false;
 
                    temp = Link->Dir;
                    Link->InputLeft;
                    Link->Dir = temp;
          }else if(Link->Misc[LM_DRUNKACT] == 11){
                    Link->InputUp = false;
                    Link->InputDown = false;
                    Link->InputLeft = false;
 
                    temp = Link->Dir;
                    Link->InputRight;
                    Link->Dir = temp;
          }else if(Link->Misc[LM_DRUNKACT] == 12){
                    Link->InputA = true;
          }else if(Link->Misc[LM_DRUNKACT] == 13){
                    Link->InputB = true;
          }else if(Link->Misc[LM_DRUNKACT] == 14){
                    Link->InputL = true;
          }else if(Link->Misc[LM_DRUNKACT] == 15){
                    Link->InputR = true;
          }
}
 
item script Remove_Drunkeness
{
          void run()
          {
                    Game->Counter[CR_DRUNKENESS]=NULL;
          }
}
 
item script Beer{
    void run (int num_beer){
        Game->Counter[CR_BEER] += num_beer;
        Game->Counter[CR_DRUNKENESS] += DRUNK_TIME * num_beer;
          Link->MP = Link->MaxMP;
    }
}

and a demo

https://drive.google...iew?usp=sharing

 

 

edit:  my code formatting was all screwed up, after fixing that the demo quest had disappeared.  all good now.


Edited by justin, 16 December 2014 - 03:45 PM.


#47 Binx

Binx

    Formerly Lineas

  • Members
  • Real Name:Brian
  • Location:Lancaster, CA

Posted 16 December 2014 - 05:31 PM

Ah, it works :)



#48 justin

justin

    Adept

  • Members

Posted 16 December 2014 - 07:14 PM

Good! My first version was a tamer drunk effect Link just kinda stumbled around as he walked, and did some random things. The drunker he was the worse the effect would be.

Then I read your post about giving infinite magic and making him go berserk, so I made a really extreme version of the built in drunk effect. If it's not what you want I can tone it down.

I'm still going work the kinks outta my stumble around drunk version, and post/submit that too, as another alternative to the standard drunk effect.

#49 Binx

Binx

    Formerly Lineas

  • Members
  • Real Name:Brian
  • Location:Lancaster, CA

Posted 16 December 2014 - 07:34 PM

actually, I'd probably prefer the first version, the idea of a berserker Link would honestly work just as well using the built-in effect.



#50 justin

justin

    Adept

  • Members

Posted 17 December 2014 - 12:48 AM

alright, here's the stagger version. i quite like the effect. much better than the berserk effect in the previous version. it doesn't do anything with weapons. it only affects movement. when walking you'll stagger back and forth (more so when drunker) but mostly walk in the direction you're going. when standing still you'll occasionally (more so when drunker) stumble to the side, or turn around for no apparent reason.

 

import "std.zh"
 
const int DRUNK_TIME = 3600;  // how long to make Link drunk for per beer.
const int DRUNK_EFFECT_CHANCE = 10; // percent chance that Link will be affected by Drunkeness effect that frame.  Multiplied by DRUNK_TIME, so more drunk means more drunk.
 
// set these to whatever you want drawn over Link to indicate the drunk effect.
// they are currently set to draw directly over Link, so most of the tile should be transparent.
 
const int DRUNK_ICON_LAYER = 7; // which layer to draw drunk effect onto.
const int DRUNK_ICON_COMBO = 1536; // which combo to use for drunk effect, can be an animated combo.
const int DRUNK_ICON_CSET = 0; // the cset of the drunk effect combo.
 
const int CR_BEER = 7; //The number of beers counter. This is the Script1 counter. 
const int CR_DRUNKENESS = 8; //The counter to use for confusion. This is the Script2 counter. 
 
 
global script Init
{
          void run()
          {
                    Game->MCounter[CR_DRUNKENESS]=65535; //Max
                    Game->Counter[CR_DRUNKENESS] = 0;
          }
}
 
 
global script slot2
{
          void run()
          {
                    while(true)
                    {
                              //Waitdraw();
                              UpdateDrunkeness();
                              Waitframe();
                    }
          }
}
 
void UpdateDrunkeness()
{
        if(Game->Counter[CR_DRUNKENESS] == 0 && Game->Counter[CR_BEER] > 0){
                Game->Counter[CR_BEER] = 0;
        }
 
          if(Link->Drunk > 0)
          {
                    Game->Counter[CR_DRUNKENESS]=Link->Drunk;
                    Link->Drunk=0;
          }
 
          if(Game->Counter[CR_DRUNKENESS]>0)
          {
                    Screen->FastCombo(DRUNK_ICON_LAYER, Link->X, Link->Y, DRUNK_ICON_COMBO, DRUNK_ICON_CSET, OP_OPAQUE);
 
                        if(Game->Counter[CR_DRUNKENESS]%4 == 0 && Drunk_Effect() ) Stagger();
                    Game->Counter[CR_DRUNKENESS]--;
          }
}
 
bool Drunk_Effect(){
    return (Rand(100) <= DRUNK_EFFECT_CHANCE * (Max(1,Game->Counter[CR_DRUNKENESS]/DRUNK_TIME)) );
}
 
void Stagger(){
          if(Link->InputUp){
                    Link->InputUp = false;
 
                    if(Rand(2)==1){
                              Link->InputLeft = true;
                    }else{
                              Link->InputRight = true;
                    }
 
                    Link->Dir = DIR_UP;
          }else if(Link->InputDown){
                    Link->InputDown = false;
 
                    if(Rand(2)==1){
                              Link->InputLeft = true;
                    }else{
                              Link->InputRight = true;
                    }
 
                    Link->Dir = DIR_DOWN;
          }else if(Link->InputLeft){
                    Link->InputLeft = false;
 
                    if(Rand(2)==1){
                              Link->InputUp = true;
                    }else{
                              Link->InputDown = true;
                    }
 
                    Link->Dir = DIR_LEFT;
          }else if(Link->InputRight){
                    Link->InputRight = false;
 
                    if(Rand(2)==1){
                              Link->InputUp = true;
                    }else{
                              Link->InputDown = true;
                    }
 
                    Link->Dir = DIR_RIGHT;
          }else if(Rand(100) <= DRUNK_EFFECT_CHANCE){
                    int random_act = Rand(3);
                    int temp = 0;
 
                    if(random_act == 1){   // change direction to right
                              if(Link->Dir == DIR_UP){
                                        Link->InputRight = true;
                              }else if(Link->Dir== DIR_DOWN){
                                        Link->InputLeft = true;
                              }else if(Link->Dir == DIR_LEFT){
                                        Link->InputUp = true;
                              }else if(Link->Dir == DIR_RIGHT){
                                        Link->InputDown = true;
                              }
                    }else if(random_act == 2){  // change direction to left
                              if(Link->Dir == DIR_UP){
                                        Link->InputLeft = true;
                              }else if(Link->Dir == DIR_DOWN){
                                        Link->InputRight = true;
                              }else if(Link->Dir == DIR_LEFT){
                                        Link->InputDown = true;
                              }else if(Link->Dir == DIR_RIGHT){
                                        Link->InputUp = true;
                              }
                    }else{  // suddenly move in random direction
 
                              temp = Link->Dir;
                              random_act = Rand(2);
 
                              for(int i = 0; i < 2; i++){
                                        if(temp == 0 || temp == 1){
                                                  if(random_act==1){
                                                            Link->InputLeft = true;
                                                  }else{
                                                            Link->InputRight = true;
                                                  }
                                        }else if(temp==2 || temp == 3){
                                                  if(random_act==1){
                                                            Link->InputUp = true;
                                                  }else{
                                                            Link->InputDown = true;
                                                  }
                                        }
                                        Link->Dir = temp;
 
                                    Game->Counter[CR_DRUNKENESS]--;
                                        Waitframe();
                              }
                    }                              
          }
}
 
 
// Can apply this item script as a Pickup or Action script for an item to remove the drunk effect.
 
item script Remove_Drunkeness
{
          void run()
          {
                    Game->Counter[CR_DRUNKENESS]=NULL;
          }
}
 
// the item that makes Link drunk.  D0 is the number of them picked up.
 
item script Beer{
    void run (int num_beer){
        Game->Counter[CR_BEER] += num_beer;
        Game->Counter[CR_DRUNKENESS] += DRUNK_TIME * num_beer;
    }
}
 

Edited by justin, 17 December 2014 - 12:49 AM.



1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users