# 2초 스턴 효과 만들어보기

### 2초 스턴 효과 만들어보기

```jsx
let _players = App.players;

// 플레이어가 스페이스에 입장 했을 때 이벤트
App.onJoinPlayer.Add(function(p) {
  p.tag = {
      sturn : false, // 스턴에 걸림 여부, false
      sTime : 2, //스턴 효과 2초로 설정
  };
	_players = App.players;
});

// 플레이어가 다른 플레이어를 공격혔을 때 (Z키)
App.onUnitAttacked.Add(function(sender, x, y, target) {
    if(!target.tag.sturn)
    {
        target.tag.sturn = true; // 스턴에 걸림 여부를 true로 변경
        target.moveSpeed = 0; // 이동속도를 0으로 변경
        target.sendUpdated();
    }
});

App.onUpdate.Add(function(dt){
	for(let i in _players) {
		let p = _players[i];
		// 스턴에 걸림 여부가 true 이면
		if(p.tag.sturn)
		{
		    p.tag.sTime -= dt; //스턴 효과 지속시간이 0이 될 때까지 update마다 dt만큼 빼줌
		    if(p.tag.sTime <= 0) // 스턴 효과 지속시간이 0 이하가 되면,
		    {
		        p.tag.sturn = false; // 스턴에 걸림 여부를 false로 변경
		        p.tag.sTime = 2; // 지속시간 2초로 초기화
		        p.moveSpeed = 80; // 이동속도 정상화
		        p.sendUpdated();
		    }
		}
	}
});

// 플레이어가 스페이스를 나갔을 때 이벤트
App.onLeavePlayer.Add(function(p) {
    p.moveSpeed = 80; // 이동속도 정상화
    p.sendUpdated();
    _players = App.players;
});
```

{% hint style="warning" %}
참고

\- 튜토리얼의 App type은 미니게임(Mini game)을 권장합니다.&#x20;

\- .js파일의 파일이름은 반드시 main 이어야 합니다. main.js 파일을 준비합니다.

\- 배포 방법을 아직 모르신다면, [<mark style="color:purple;">ZEP Script 배포 가이드</mark>](/creator/dev-guide/zep-script.md)를 참고해주세요.
{% endhint %}

***


---

# Agent Instructions: 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:

```
GET https://docs-kr.zep.us/creator/tutor/tutorial/5.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
