MAPID=#PARAM1
XPOS=#PARAM2
YPOS=#PARAM3
LIFE=#PARAM4
USERID=#PARAM5
LIFEEND=Floor(GetUserWisdom(USERID)/2)
DAMAGE=Random(0,GetUserStrength(USERID))
DRAW=31
DUR=1000
SPEED=DUR+300

LIFE=LIFE+1

If Life>LifeEnd
	Goto End
Endif

Label FindRoute

XPOS2=XPOS
YPOS2=YPOS

DIR=Random(1,4)

;Go Up
If DIR=1
	DIRC=#DIR_UP
	XPOS2=XPOS
	YPOS2=YPOS-1
Endif
;Go Down
If DIR=2
	DIRC=#DIR_DOWN
	XPOS2=XPOS
	YPOS2=YPOS+1
Endif
;Go Left
If DIR=3
	DIRC=#DIR_LEFT
	XPOS2=XPOS-1
	YPOS2=YPOS
Endif
;Go Right
If DIR=4
	DIRC=#DIR_RIGHT
	XPOS2=XPOS+1
	YPOS2=YPOS
Endif

If GetTileType(MAPID,XPOS2,YPOS2)<>#TILE_DOOR
If GetTileType(MAPID,XPOS2,YPOS2)<>#TILE_WALL
If GetTileType(MAPID,XPOS2,YPOS2)<>#TILE_WARP
If GetTileType(MAPID,XPOS2,YPOS2)<>#TILE_NPC
If GetTileType(MAPID,XPOS2,YPOS2)<>#TILE_GODONLY
If GetTileType(MAPID,XPOS2,YPOS2)<>#TILE_GUILDHALL
Goto RouteGood
Endif
Endif
Endif
Endif
Endif
Endif
Goto FindRoute

Label RouteGood

If XPOS2<0
	If GetMapExit(MAPID,"left")>0
		MAPID2=GetMapExit(MAPID,"left")
		XPOS2=20
		Goto DrawEffect
	Else
		Goto FindRoute
	Endif
Endif
If XPOS2>20
	If GetMapExit(MAPID,"right")>0
		MAPID2=GetMapExit(MAPID,"right")
		XPOS2=0
		Goto DrawEffect
	Else
		Goto FindRoute
	Endif
Endif
If YPOS2<0
	If GetMapExit(MAPID,"up")>0
		MAPID2=GetMapExit(MAPID,"up")
		YPOS2=20
		Goto DrawEffect
	Else
		Goto FindRoute
	Endif
Endif
If YPOS>20
	If GetMapExit(MAPID,"down")>0
		MAPID2=GetMapExit(MAPID,"down")
		YPOS2=0
		Goto DrawEffect
	Else
		Goto FindRoute
	Endif
Endif

MAPID2=MAPID





Label DrawEffect

TARGETID=GetUserAtXY(MAPID,XPOS,YPOS)
MONSTERID=GetMonsterAtXY(MAPID,XPOS,YPOS)

If TargetID>0
	If CanAttack(MAPID,USERID,TARGETID)=1
		If TargetID<>UserID
			CreateEffect(2,250,0,#DIR_UP,MAPID,XPOS,YPOS,0,0,0)
			UserDamageUser(USERID,DAMAGE,TARGETID)
		Endif
	Endif
Endif

If MonsterID>=0
	CreateEffect(2,250,0,#DIR_UP,MAPID,XPOS,YPOS,0,0,0)
	UserDamageMonster(MONSTERID,DAMAGE,USERID)
Endif

CreateEffect(DRAW,DUR,SPEED,DIRC,MAPID,XPOS,YPOS,0,0,0)
Timer5(720,DUR+275,MAPID2,XPOS2,YPOS2,LIFE,USERID)

Label End

Continue = 1