ZEP Guidebook (EN)
  • Hello ZEP Script
  • ZEP Script
    • πŸ’»ZEP Script Guide
      • ZEP Script Development Guide
        • JavaScript Development Tips
        • ZEP Script Deployment Guide
        • TypeScript Development Tips
      • Explore ZEP Script
        • Tutorials
          • Displaying a Message
          • Changing Avatar Image
          • Using HTML
          • Communicating with an External API
          • Creating a 2-Second Stun Effect
        • ZEP Script Example Code
          • Timer
          • Zombie Game
          • Paintman Game
          • Hangul Quiz Game
          • Avoid Poop Game
          • Boxing Game
          • Sidebar App
          • Race
      • ZEP Script FAQ
      • Appendix
        • ZEP Script Use Cases
        • Understanding Spaces and Maps
        • JavaScript Keycode List
        • Understanding Sprite Sheets
        • TileEffectType Detailed Explanation
        • What are Reference Coordinates?
        • Communicating with an External API
        • How to Use URL Query Strings
        • How to Change the Mobile Interaction Button
        • Grammar Available for Widgets
        • Object Interaction with ZEP Script
        • Object npcProperty
    • πŸ“˜ZEP Script API
      • API Summary
      • ScriptApp
        • Lifecycle
        • Field
        • Storage
        • Event Listeners
        • Callbacks
        • Methods
      • ScriptMap
        • Field
        • Methods
      • ScriptPlayer
        • Field
        • Methods
      • ScriptWidget
        • Field
        • Event Listeners
        • Methods
  • Others
    • Homepage
    • FAQ
    • Twitter
    • Discord
Powered by GitBook
On this page

Was this helpful?

  1. ZEP Script
  2. ZEP Script Guide
  3. Explore ZEP Script
  4. Tutorials

Creating a 2-Second Stun Effect

Creating a 2-Second Stun Effect

let _players = App.players;

// Event when player enters 
App.onJoinPlayer.Add(function(p) {
  p.tag = {
      stun : false, // Whether stunned, false
      sTime : 2, //Set stun effect to 2 seconds
  };
	_players = App.players;
});

// When the player attacks another player (Z key)
App.onUnitAttacked.Add(function(sender, x, y, target) {
    if(!target.tag.stun)
    {
        target.tag.stun = true; // Change whether stunned to true
        target.moveSpeed = 0; // Change movement speed to 0
        target.sendUpdated();
    }
});

App.onUpdate.Add(function(dt){
	for(let i in _players) {
		let p = _players[i];
		// If whether stunned is true
		if(p.tag.stun)
		{
		    p.tag.sTime -= dt; //Subtract dt for each update until the stun effect duration becomes 0.
		    if(p.tag.sTime <= 0) // When the stun effect duration becomes under 0,
		    {
		        p.tag.stun = false; // Change whether stunned to false
		        p.tag.sTime = 2; // Reset duration to 2 seconds
		        p.moveSpeed = 80; // Normalize movement speed
		        p.sendUpdated();
		    }
		}
	}
});

// Event when player exits
App.onLeavePlayer.Add(function(p) {
    p.moveSpeed = 80; // Normalize movement speed
    p.sendUpdated();
    _players = App.players;
});

Please Note

- For the tutorial, we recommend setting the app type to Mini-Game.

- The JSON file name must be β€œmain.” Please create a new text file and name it β€œmain.js.”



PreviousCommunicating with an External APINextZEP Script Example Code

Last updated 2 years ago

Was this helpful?

- If you do not know how to deploy an app, please refer to the .

πŸ’»
ZEP Script Deployment Guide