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 truetarget.moveSpeed =0; // Change movement speed to 0target.sendUpdated(); }});App.onUpdate.Add(function(dt){for(let i in _players) {let p = _players[i];// If whether stunned is trueif(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 falsep.tag.sTime =2; // Reset duration to 2 secondsp.moveSpeed =80; // Normalize movement speedp.sendUpdated(); } } }});// Event when player exitsApp.onLeavePlayer.Add(function(p) {p.moveSpeed =80; // Normalize movement speedp.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.”