-- LUA Script - precede every function and global member with lowercase name of script + '_main' -- Default script - does nothing. local maxheightachieved = {} local flying = {} local soaring = {} local landing = {} local walking = {} local state = {} local aggressive = {} local animationcomplete = {} local init_flight = {} local ascending = {} local soarcomplete = {} local huntcomplete = {} local ascentcomplete = {} local descentcomplete = {} local started = {} local started2 = {} local descending = {} local hunting = {} local groundattack = {} local airattack = {} local attacking = {} local attacktype = {} local hitting = {} local attackstarted = {} local starthealth = {} local setpos = {} local xpos = {} local ypos = {} local zpos = {} local timer = {} local timed = {} local outofbounds = {} local direction = {} local wyvernpos = {} local nvolume = {} local maxvolume = {} local minvolume = {} local death = {} local dead = {} local startedbiting = {} local wyvrandom = {} local randomset = {} local rotaterandom = {} local rotateset = {} local terrainheight = {} function wyvern_init(e) maxheightachieved[e] = 0 soaring[e] = 0 flying[e] = 0 landing[e] = 0 walking[e] = 0 state[e] = "" animationcomplete[e] = 0 aggressive[e] = 0 init_flight[e] = 0 ascending[e] = 0 soarcomplete[e] = 0 huntcomplete[e] = 0 ascentcomplete[e] = 0 started[e] = 0 started2[e] = 0 descending[e] = 0 descentcomplete[e] = 0 hunting[e] = 0 groundattack[e] = 0 airattack[e] = 0 attacking[e] = 0 attacktype[e] = 0 hitting[e] = 0 attackstarted[e] = 0 setpos[e] = 0 xpos[e] = 0 ypos[e] = 0 zpos[e] = 0 timer[e] = 0 timed[e] = 0 outofbounds[e] = 0 direction[e] = 0 wyvernpos[e] = 0 nvolume[e] = 0 maxvolume[e] = 100 minvolume[e] = 1 death[e] = 0 dead[e] = 0 startedbiting[e] = 0 wyvrandom[e] = 0 randomset[e] = 0 rotaterandom[e] = 0 rotateset[e] = 0 terrainheight[e] = 600 end function wyvern_main(e) Prompt(g_PlayerPosY) --terrainheight[e] = GetTerrainHeight(g_Entity[e]['x'],g_Entity[e]['z']) if randomset[e] == 0 then wyvrandom[e] = math.random(0,10000) randomset[e] = 1 end if rotateset[e] == 0 then rotaterandom[e] = math.random(0,1) rotateset[e] = 1 end if rotaterandom[e] == 0 then rotaterandom[e] = -1 end --stops death animation if GetAnimationFrame(e) == 807 then dead[e] = 1 StopAnimation(e) end --keeps health above a certain level during flight if g_Entity[e]['health'] < 500 and g_Entity[e]['y'] > (terrainheight[e]+10) then SetEntityHealth(e,490) end -- sets sound volume nvolume[e] = maxvolume[e] - ( GetPlayerDistance(e) / 300.0 ) if nvolume[e] < minvolume[e] then StopSound(e,0) end SetSoundVolume(nvolume[e]) --gets initial position if setpos[e] == 0 then xpos[e] = g_Entity[e]['x'] zpos[e] = g_Entity[e]['z'] ypos[e] = g_Entity[e]['y'] setpos[e] = 1 end -- play wing flapping sound if GetAnimationFrame(e) == 165 or GetAnimationFrame(e) == 750 then PlaySound(e,0) end --play screeching sound if GetAnimationFrame(e) == 480 then PlaySound(e,1) end --checks for out of bounds if WyvernDistance(e) > 10000 then outofbounds[e] = 1 timer[e] = 20 elseif WyvernDistance(e) < 10000 then outofbounds[e] = 0 end if outofbounds[e] == 0 then direction[e] = math.random(0,1) if direction[e] == 0 then direction[e] = -1 end end --returns to original area of out of bounds if outofbounds[e] == 1 then if started2[e] == 0 then StartTimer(e) wyvernpos[e] = WyvernDistance(e) started2[e] = 1 end if GetTimer(e) > timer[e] then if WyvernDistance(e) > wyvernpos[e] then RotateY(e,(60*direction[e])) end started[e] = 0 end end --sets initial flight if g_Entity[e]['y'] > (terrainheight[e] + 2500) then init_flight[e] = 1 end --gets initial entity health if starthealth[e] == nil then starthealth[e] = g_Entity[e]['health'] end --if entity is damaged, change behaviour if g_Entity[e]['health'] < starthealth[e] then aggressive[e] = 1 ascending[e] = 0 end --checks if descent is complete if descending[e] == 1 and g_Entity[e]['y'] < (terrainheight[e]+400) then descentcomplete[e] = 1 elseif descending[e] == 1 and g_Entity[e]['y'] > (terrainheight[e]+400) then descentcomplete[e] = 0 end --checks if ascent is complete if ascending[e] == 1 and g_Entity[e]['y'] > (terrainheight[e]+2500) then ascentcomplete[e] = 1 soarcomplete[e] = 0 elseif ascending[e] == 1 and g_Entity[e]['y'] < (terrainheight[e]+2500) then ascentcomplete[e] = 0 end --if hunting and player close, changes behaviour if hunting[e] == 1 and GetPlayerDistance(e) < 3000 then if state[e] ~= "aggressive" then g_Entity[e]['animating'] = 0 state[e] = "aggressive" end aggressive[e] = 1 hunting[e] = 0 end if death[e] == 0 then if g_Entity[e]['health'] > 500 then if aggressive[e] == 0 then --returns to original area of out of bounds if outofbounds[e] == 1 then if started2[e] == 0 then StartTimer(e) wyvernpos[e] = WyvernDistance(e) started2[e] = 1 end if GetTimer(e) > timer[e] then if WyvernDistance(e) > wyvernpos[e] then RotateY(e,(60*direction[e])) end started[e] = 0 end elseif outofbounds[e] == 0 then --starts ascent if init_flight[e] == 0 then if state[e] ~= "ascending" then g_Entity[e]['animating'] = 0 state[e] = "ascending" end ascending[e] = 1 flying[e] = 1 walking[e] = 0 landing[e] = 0 aggressive[e] = 0 elseif init_flight[e] == 1 then --set to soaring if ascent is complete if soarcomplete[e] == 0 then if state[e] ~= "soaring" then g_Entity[e]['animating'] = 0 state[e] = "soaring" end hunting[e] = 0 soaring[e] = 1 ascending[e] = 0 flying[e] = 0 walking[e] = 0 landing[e] = 0 --sets to descent if soar is complete elseif soarcomplete[e] == 1 and descentcomplete[e] == 0 then if state[e] ~= "descending" then g_Entity[e]['animating'] = 0 state[e] = "descending" end descending[e] = 1 hunting[e] = 0 soaring[e] = 0 ascending[e] = 0 flying[e] = 0 walking[e] = 0 landing[e] = 0 --sets to hunting is descent is complete elseif soarcomplete[e] == 1 and descentcomplete[e] == 1 and huntcomplete[e] == 0 then if state[e] ~= "hunting" then g_Entity[e]['animating'] = 0 state[e] = "hunting" end hunting[e] = 1 descending[e] = 0 soaring[e] = 0 ascending[e] = 0 flying[e] = 0 walking[e] = 0 landing[e] = 0 -- sets to ascent if hunt is complete elseif soarcomplete[e] == 1 and descentcomplete[e] == 1 and huntcomplete[e] == 1 then if state[e] ~= "ascending" then g_Entity[e]['animating'] = 0 state[e] = "ascending" end hunting[e] = 0 descending[e] = 0 soaring[e] = 0 ascending[e] = 1 flying[e] = 0 walking[e] = 0 landing[e] = 0 end end end --sets behaviour once wyvern is aggressive elseif aggressive[e] == 1 then airattack[e] = 1 groundattack[e] = 0 end --behaviour if wyvern is badly injured elseif g_Entity[e]['health'] < 500 then --wyvern descends if g_Entity[e]['y'] > (terrainheight[e]+70) then if state[e] ~= "descending" then g_Entity[e]['animating'] = 0 state[e] = "descending" end hunting[e] = 0 descending[e] = 1 soaring[e] = 0 flying[e] = 0 walking[e] = 0 ascending[e] = 0 landing[e] = 0 airattack[e] = 0 groundattack[e] = 0 end --if wyvern is close to the ground then it lands if g_Entity[e]['y'] > (terrainheight[e]+60) and g_Entity[e]['y'] < (terrainheight[e]+70) then if state[e] ~= "landing" then g_Entity[e]['animating'] = 0 state[e] = "landing" end hunting[e] = 0 descending[e] = 0 soaring[e] = 0 flying[e] = 0 ascending[e] = 0 walking[e] = 0 landing[e] = 1 airattack[e] = 0 groundattack[e] = 0 end --sets to attack if on the ground if g_Entity[e]['y'] < (terrainheight[e]+2) then hunting[e] = 0 descending[e] = 0 soaring[e] = 0 flying[e] = 0 ascending[e] = 0 walking[e] = 0 landing[e] = 0 airattack[e] = 0 groundattack[e] = 1 end end --hunting behaviour if hunting[e] == 1 then if g_Entity[e]['animating'] == 0 then SetAnimationFrames(161,261) LoopAnimation(e) g_Entity[e]['animating'] = 1 end if started[e] == 0 then StartTimer(e) started[e] = 1 end if GetTimer(e) > (20000 + wyvrandom[e]) then huntcomplete[e] = 1 started[e] = 0 end MoveForward(e,200) RotateY(e,(5*rotaterandom[e])) end --descent behaviour if descending[e] == 1 then if g_Entity[e]['animating'] == 0 then SetAnimationFrames(7,107) LoopAnimation(e) g_Entity[e]['animating'] = 1 end MoveForward(e,250) MoveUp(e,-50) if g_Entity[e]['health'] < starthealth[e] then RotateToPlayerSlowly(e,5) end end --soaring behaviour if soaring[e] == 1 then if g_Entity[e]['animating'] == 0 then SetAnimationFrames(7,107) LoopAnimation(e) g_Entity[e]['animating'] = 1 end if started[e] == 0 then StartTimer(e) started[e] = 1 end if GetTimer(e) > (20000 + wyvrandom[e]) then soarcomplete[e] = 1 started[e] = 0 end MoveForward(e,100) RotateY(e,(5*rotaterandom[e])) ascentcomplete[e] = 0 descentcomplete[e] = 0 huntcomplete[e] = 0 end --ascent behaviour if ascending[e] == 1 then if g_Entity[e]['animating'] == 0 then SetAnimationFrames(161,261) LoopAnimation(e) g_Entity[e]['animating'] = 1 end MoveForward(e,100) MoveUp(e,50) end --flying behaviour if flying[e] == 1 then ModulateSpeed(e,2) if g_Entity[e]['animating'] == 0 then SetAnimationFrames(161,261) LoopAnimation(e) g_Entity[e]['animating'] = 1 end MoveForward(e,40) MoveUp(e,20) if GetAnimationFrame(e) == 161 then animationcomplete[e] = 0 end if GetAnimationFrame(e) == 261 then animationcomplete[e] = 1 end end --landing behaviour if landing[e] == 1 then ModulateSpeed(e,1.5) if g_Entity[e]['animating'] == 0 then SetAnimationFrames(300,400) PlayAnimation(e) g_Entity[e]['animating'] = 1 end MoveForward(e,100) if g_Entity[e]['y'] > terrainheight[e] then MoveUp(e,-30) end if GetAnimationFrame(e) == 300 then animationcomplete[e] = 0 end if GetAnimationFrame(e) == 400 then animationcomplete[e] = 1 end end --approaches player from the air if airattack[e] == 1 and GetPlayerDistance(e) > 400 then if state[e] ~= "airattack" then g_Entity[e]['animating'] = 0 state[e] = "airattack" end if g_Entity[e]['y'] > (terrainheight[e]+50) then MoveUp(e,-50) end ModulateSpeed(e,3) if g_Entity[e]['animating'] == 0 then SetAnimationFrames(652,752) LoopAnimation(e) g_Entity[e]['animating'] = 1 end MoveForward(e,300) RotateToPlayerSlowly(e,5) --aerial attack behaviour elseif airattack[e] == 1 and GetPlayerDistance(e) < 400 then if state[e] ~= "attacking" then g_Entity[e]['animating'] = 0 state[e] = "attacking" end if g_Entity[e]['y'] > (terrainheight[e]+100) then MoveUp(e,-100) end if animationcomplete[e] == 1 then attacktype[e] = math.random(0,1) animationcomplete[e] = 0 g_Entity[e]['animating'] = 0 end MoveForward(e,200) RotateToPlayerSlowly(e,8) --chooses between attack types if attacktype[e] == 0 then if g_Entity[e]['animating'] == 0 then SetAnimationFrames(451,551) PlayAnimation(e) g_Entity[e]['animating'] = 1 end if GetAnimationFrame(e) > 500 and GetAnimationFrame(e) < 502 then hitting[e] = 1 elseif GetAnimationFrame(e) < 500 or GetAnimationFrame(e) > 502 then hitting[e] = 0 end if GetAnimationFrame(e) == 451 then animationcomplete[e] = 0 end if GetAnimationFrame(e) == 551 then animationcomplete[e] = 1 end if hitting[e] == 1 and GetPlayerDistance(e) < 300 then HurtPlayer(e,10) end end if attacktype[e] == 1 then if g_Entity[e]['animating'] == 0 then SetAnimationFrames(551,651) PlayAnimation(e) g_Entity[e]['animating'] = 1 end if GetAnimationFrame(e) > 608 and GetAnimationFrame(e) < 610 then hitting[e] = 1 end if GetAnimationFrame(e) < 608 and GetAnimationFrame(e) > 610 then hitting[e] = 0 end if GetAnimationFrame(e) == 551 then animationcomplete[e] = 0 end if GetAnimationFrame(e) == 651 then animationcomplete[e] = 1 end if hitting[e] == 1 and GetPlayerDistance(e) < 300 then HurtPlayer(e,10) end end end --approaches player on the ground if GetAnimationFrame(e) > 448 and GetAnimationFrame(e) < 451 then startedbiting[e] = 0 end if groundattack[e] == 1 then if g_Entity[e]['y'] > (terrainheight[e] + 2) then MoveUp(e,-50) end if g_Entity[e]['y'] < (terrainheight[e] - 2) then MoveUp(e,50) end if GetPlayerDistance(e) < 200 then attacking[e] = 1 end if GetAnimationFrame(e) > 430 and GetAnimationFrame(e) < 433 then hitting[e] = 1 end if GetAnimationFrame(e) < 430 or GetAnimationFrame(e) > 433 then hitting[e] = 0 end if GetAnimationFrame(e) > 400 and GetAnimationFrame(e) < 403 then animationcomplete[e] = 0 startedbiting[e] = 1 end if GetAnimationFrame(e) > 448 and GetAnimationFrame(e) < 451 then animationcomplete[e] = 1 startedbiting[e] = 0 attacking[e] = 0 end if hitting[e] == 1 and GetPlayerDistance(e) < 300 then HurtPlayer(e,10) end -- if GetAnimationFrame(e) > 108 and GetAnimationFrame(e) < 111 then -- animationcomplete[e] = 0 -- end -- if GetAnimationFrame(e) > 157 and GetAnimationFrame(e) < 160 then -- animationcomplete[e] = 1 -- end end if groundattack[e] == 1 and GetPlayerDistance(e) > 200 and startedbiting[e] == 0 and attacking[e] == 0 then if attackstarted[e] == 0 then SetEntityHealth(e,490) attackstarted[e] = 1 end if state[e] ~= "groundattack" then g_Entity[e]['animating'] = 0 state[e] = "groundattack" end ModulateSpeed(e,2) if g_Entity[e]['animating'] == 0 then SetAnimationFrames(109,159) LoopAnimation(e) g_Entity[e]['animating'] = 1 end MoveForward(e,200) RotateToPlayerSlowly(e,5) if GetAnimationFrame(e) == 109 then animationcomplete[e] = 0 end if GetAnimationFrame(e) == 159 then animationcomplete[e] = 1 end --ground attack behaviour elseif groundattack[e] == 1 and GetPlayerDistance(e) < 200 then if state[e] ~= "attacking" then g_Entity[e]['animating'] = 0 state[e] = "attacking" attacking[e] = 1 end end if attacking[e] == 1 then ModulateSpeed(e,4) if g_Entity[e]['animating'] == 0 then SetAnimationFrames(400,450) LoopAnimation(e) g_Entity[e]['animating'] = 1 end end end --check for death and play death animation if g_Entity[e]['health'] < 1 and dead[e] == 0 and g_Entity[e]['y'] < (terrainheight[e]+5) then if state[e] ~= "dead" then g_Entity[e]['animating'] = 0 state[e] = "dead" end death[e] = 1 ModulateSpeed(e,1.0) if g_Entity[e]['animating'] == 0 then SetAnimationFrames(759,807) PlayAnimation(e) g_Entity[e]['animating'] = 1 end StopSound(e) end end --gets lateral distance from starting point function WyvernDistance(e) wyvernDX = (g_Entity[e]['x'] - xpos[e]) wyvernDY = (g_Entity[e]['y'] - ypos[e]) wyvernDZ = (g_Entity[e]['z'] - zpos[e]) return math.sqrt(math.abs(wyvernDX*wyvernDX)+math.abs(wyvernDZ*wyvernDZ)); end