ZoriaRPG

Stunlock.zs v0.2

Oct 6th, 2017
104
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Prevents stuniogn weapons from stunlocking npcs.
  2. //v0.2
  3. //7th October, 201
  4. //ZoriaRPG
  5.  
  6. const int SFX_CHINK = 63;
  7.  
  8. const int LW_FLAGS_Z3ENGINE = 4;
  9. const int LW_FLAG_STUNNING = 0000000000001b;
  10. const int HITY_OFFSCREEN = -32768;
  11.  
  12. //Pre-Waitdraw
  13.  
  14. //Master loop for all lweapon set-up.
  15. void DoLWeaponsCheckLoop(){
  16.     lweapon l;
  17.    
  18.     for ( int q = Screen->NumLWeapons(); q > 0; q-- )
  19.     {
  20.         l = Screen->LoadLWeapon(q);
  21.         LWeaponRoutines(l);
  22.         //Add the redundant weapon-only checks here.
  23.     }
  24. }
  25.  
  26. //Master loop for all lweapon and npc collision.
  27. void DoLWeaponNPC_Collision(){
  28.     lweapon l; npc n;
  29.     int npc_count = Screen->NumNPCs();
  30.     int lweapon_count = Screen->NumLWeapons();
  31.     bool npcs_first;
  32.     if ( npc_count < lweapon_count ) {
  33.         //Do npcs first
  34.         for ( ; npc_count > 0; npc_count-- )
  35.         {
  36.             n = Screen->LoadNPC(npc_count);
  37.             for ( ; lweapon_count > 0; lweapon_count-- )
  38.             {
  39.                 l = Screen->LoadLWeapon(lweapon_count);
  40.                 if ( Collision(l,n)
  41.                 {
  42.                     AllNpcLWeaponCollisionRoutines(l,n);
  43.                 }
  44.             }
  45.         }
  46.     }
  47.     else
  48.     {
  49.         for ( ; lweapon_count > 0; lweapon_count-- )
  50.         {
  51.             l = Screen->LoadLWeapon(lweapon_count);
  52.             for ( ; npc_count > 0; npc_count-- )
  53.             {
  54.                 n = Screen->LoadNPC(npc_count);
  55.                 if ( Collision(l,n)
  56.                 {
  57.                     AllNpcLWeaponCollisionRoutines(l,n);
  58.                     //functions in the form of identifier(l,n)
  59.                 }
  60.             }
  61.         }
  62.     }
  63. }      
  64.                
  65.  
  66. //Global active script.
  67. global script Z3_active{
  68.     void run(){
  69.         while(true){
  70.             DoLWeaponsCheckLoop
  71.             DoLWeaponNPC_Collision();
  72.            
  73.             Waitdraw();
  74.            
  75.             //cleanup and verification.
  76.         }
  77.     }
  78. }
  79.            
  80.  
  81. //Sub-routines.
  82.  
  83. //This is a container for all of the lweapon and npc routines that run on collision, after
  84. //the individual lweapon and npc routines.
  85. void NpcLWeaponCollisionRoutines(lweapon l, npc n)
  86. {
  87.     StunCollision(l,n);
  88.     //Add all functions that you want to apply here.
  89. }
  90.  
  91. //This is a container for all of the lweapon routines that occur early, before waitdraw.
  92. void LWeaponRoutines(lweapon l)
  93. {
  94.     //Add all lweapon-only routines here.
  95.     MarkStunningWeapons(l);
  96. }
  97.  
  98. //Moves the hitboix of any weapon on-screen, or off-screen.
  99. //May need to be updated to handle multiple sources, and to do -= or += HITY_OFFSCREEN
  100. //  for weapons with existing hitbox positional changes.
  101. //  e.g. if a weapon has a -8 hitbox position adjustment, we want to preserve that!
  102. void MoveWeaponHitbox(lweapon l, bool offscreen){
  103.     if ( offscreen ) l->HitYOffset = HITY_OFFSCREEN;
  104.     else l->HitYOffset = 0;
  105. }
  106.  
  107. //Corrects the lweapon hotbox position if the weapon can stun an npc.
  108. void StunNPCThisFrame(lweapon l)
  109. {
  110.     MoveWeaponHitbox(l,false);
  111.    
  112. }
  113.  
  114. //Sets a stun flag and adjusts the hitbox position.
  115. void SetStunning(lweapon l, bool canstun){
  116.     if ( canstun )
  117.     {
  118.         l->Misc[LW_FLAGS_Z3ENGINE]|=LW_FLAG_STUNNING;
  119.         MoveWeaponHitbox(l,true);
  120.         }
  121.     else
  122.     {
  123.         l->Misc[LW_FLAGS_Z3ENGINE]&=~LW_FLAG_STUNNING;
  124.         MoveWeaponHitbox(l,false);
  125.     }
  126. }
  127.  
  128.  
  129. //Marks the flags on all weapons that would stun, and can bounce.
  130. void MarkStunningWeapons(lweapon l){
  131.     if ( l->Damage == 0 )
  132.     {
  133.         if ( l->ID == LW_BRANG || l->ID == LW_HOOKSHOT )
  134.         {  
  135.             SetStunning(l,true); //Move the hitbox offscreen and mark the flag.
  136.         }
  137.     }
  138. }
  139.  
  140. //Forces a stunning weapon to not stun,a nd to bounce.
  141. void BlockStun(lweapon l)
  142. {
  143.     MoveWeaponHitbox(l,true);
  144.     Game->PlaySound(SFX_CHINK);
  145.     l->DeadState = WDS_BOUNCE;
  146. }
  147.  
  148. //Sets the correct stun variables to lweapons of the npc is not stunned.
  149. void StunCollision(lweapon l, npc n)
  150. {
  151.     if ( !n->Stun )
  152.     {
  153.         StunNPCThisFrame(l);
  154.     }
  155.    
  156.     else BlockStun(l);
  157. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×