> For the complete documentation index, see [llms.txt](https://docs.zep.us/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zep.us/zep-script/zep-script-guide/explore-zep-script/tutorials/creating-a-2-second-stun-effect.md).

# Creating a 2-Second Stun Effect

### Creating a 2-Second Stun Effect

```jsx
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;
});
```

{% hint style="warning" %}
Please Note&#x20;

\- For the tutorial, we recommend setting the app type to Mini-Game.&#x20;

\- The JSON file name must be “main.” Please create a new text file and name it “main.js.”&#x20;

\- If you do not know how to deploy an app, please refer to the [<mark style="color:purple;">**ZEP Script Deployment Guide**</mark>](/zep-script/zep-script-guide/zep-script-development-guide/zep-script-deployment-guide.md)<mark style="color:purple;">.</mark>
{% endhint %}

***

***


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.zep.us/zep-script/zep-script-guide/explore-zep-script/tutorials/creating-a-2-second-stun-effect.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
