require "scriptbank\\ai\\module_combatcore" oldhealth = {} starthealth = {} function madame_tudo_init(e) ai_bot_state[e] = "find path" end function madame_tudo_main(e) AIObjNo = g_Entity[e]['obj'] if ai_bot_state[e] == "find path" then CharacterControlManual(e) oldhealth[e] = g_Entity[e]['health'] starthealth[e] = g_Entity[e]['health'] PathIndex = -1 PointIndex = 2 pClosest = 99999 for pa = 1, AIGetTotalPaths(), 1 do for po = 1 , AIGetPathCountPoints(pa), 1 do pDX = g_Entity[e]['x'] - AIPathGetPointX(pa,po) pDY = g_Entity[e]['y'] - AIPathGetPointY(pa,po) pDZ = g_Entity[e]['z'] - AIPathGetPointZ(pa,po) pDist = math.sqrt(math.abs(pDX*pDX)+math.abs(pDY*pDY)+math.abs(pDZ*pDZ)); if pDist < pClosest and pDist < 200 then pClosest = pDist PathIndex = pa PointIndex = po end end -- po end -- pa if PathIndex > -1 then ai_bot_pathindex[e] = PathIndex ai_bot_state[e] = "follow path" ai_bot_pointdirection[e] = 1 ai_bot_pointindex[e] = PointIndex ai_bot_pointmax[e] = AIGetPathCountPoints(PathIndex) else ai_bot_state[e] = "idle" end elseif ai_bot_state[e] == "follow path" then patrolx = AIPathGetPointX(ai_bot_pathindex[e],ai_bot_pointindex[e]) patroly = AIPathGetPointY(ai_bot_pathindex[e],ai_bot_pointindex[e]) patrolz = AIPathGetPointZ(ai_bot_pathindex[e],ai_bot_pointindex[e]) AIEntityGoToPosition(AIObjNo,patrolx,patroly,patrolz) MoveForward(e,AIGetEntitySpeed(AIObjNo)) if g_Entity[e]['animating'] ~= 3 then SetAnimation(3) LoopAnimation(e) SetAnimationSpeedModulation(e,1) g_Entity[e]['animating'] = 3 end tDistX = g_Entity[e]['x'] - patrolx tDistZ = g_Entity[e]['z'] - patrolz VertDist = math.abs(g_Entity[e]['y'] - patroly) DistFromPath = math.sqrt(math.abs(tDistX*tDistX)+math.abs(tDistZ*tDistZ)) if DistFromPath < 25 and VertDist < 95 then StartTimer(e) if ai_bot_pointdirection[e] == 1 then ai_bot_pointindex[e] = ai_bot_pointindex[e] + 1 if ai_bot_pointindex[e] > ai_bot_pointmax[e] then ai_bot_pointindex[e] = ai_bot_pointmax[e] -1 ai_bot_pointdirection[e] = 0 end else ai_bot_pointindex[e] = ai_bot_pointindex[e] - 1 if ai_bot_pointindex[e] < 1 then ai_bot_pointindex[e] = 2 ai_bot_pointdirection[e] = 1 end end end if g_Entity[e]['health'] < oldhealth[e] or AIGetEntityHeardSound(AIObjNo) == 1 or (g_Entity[e]['plrvisible'] and g_PlayerGunFired > 0) then AIEntityStop(AIObjNo) if EntityLookingAtPlayer(e,1000,90) == 1 then SetAnimation(4) else SetAnimation(5) end PlayAnimation(e) g_Entity[e]['animating'] = 5 SetAnimationSpeedModulation(e,2.8) ai_bot_state[e] = "alerted" end elseif ai_bot_state[e] == "idle" then if g_Entity[e]['animating'] ~= 1 then SetAnimation(math.random(0,1)) PlayAnimation(e) g_Entity[e]['animating'] = 1 end if g_Entity[e]['health'] < oldhealth[e] or AIGetEntityHeardSound(AIObjNo) == 1 or (g_Entity[e]['plrvisible'] and g_PlayerGunFired > 0) then AIEntityStop(AIObjNo) if EntityLookingAtPlayer(e,1000,90) == 1 then SetAnimation(4) else SetAnimation(5) end if g_Entity[e]['animating'] ~= 5 then PlayAnimation(e) g_Entity[e]['animating'] = 5 SetAnimationSpeedModulation(e,2.8) end ai_bot_state[e] = "alerted" end elseif ai_bot_state[e] == "alerted" then if g_Entity[e]['animating'] == 0 then ai_bot_state[e] = "run away" end elseif ai_bot_state[e] == "run away" then ai_bot_targety[e] = g_Entity[e]['y'] if g_PlayerPosX < g_Entity[e]['x']-10 then ai_bot_targetx[e] = g_Entity[e]['x']+500 elseif g_PlayerPosX > g_Entity[e]['x']+10 then ai_bot_targetx[e] = g_Entity[e]['x']-500 else ai_bot_targetx[e] = g_Entity[e]['x'] end if g_PlayerPosZ < g_Entity[e]['z']-10 then ai_bot_targetz[e] = g_Entity[e]['z']+500 elseif g_PlayerPosZ > g_Entity[e]['z']+10 then ai_bot_targetz[e] = g_Entity[e]['z']-500 else ai_bot_targetz[e] = g_Entity[e]['z'] end AIEntityGoToPosition(AIObjNo,ai_bot_targetx[e],ai_bot_targety[e],ai_bot_targetz[e]) MoveForward(e,AIGetEntitySpeed(AIObjNo)*2) if g_Entity[e]['animating'] ~= 6 then SetAnimation(6) LoopAnimation(e) g_Entity[e]['animating'] = 6 SetAnimationSpeedModulation(e,1.2) end if g_Entity[e]['health'] < starthealth[e]*0.6 then SetAnimation(7) g_Entity[e]['animating'] = 7 PlayAnimation(e) ai_bot_state[e] = "crawl forward" SetAnimationSpeedModulation(e,2) end if GetPlayerDistance(e) > 2000 then if ai_bot_pathindex[e] ~= nil then ai_bot_state[e] = "follow path" else ai_bot_state[e] = "idle" end end elseif ai_bot_state[e] == "crawl forward" then if g_Entity[e]['animating'] == 0 then SetAnimation(8) LoopAnimation(e) SetAnimationSpeedModulation(e,1) g_Entity[e]['animating'] = 8 end ai_bot_targety[e] = g_Entity[e]['y'] if g_PlayerPosX < g_Entity[e]['x']-10 then ai_bot_targetx[e] = g_Entity[e]['x']+500 elseif g_PlayerPosX > g_Entity[e]['x']+10 then ai_bot_targetx[e] = g_Entity[e]['x']-500 else ai_bot_targetx[e] = g_Entity[e]['x'] end if g_PlayerPosZ < g_Entity[e]['z']-10 then ai_bot_targetz[e] = g_Entity[e]['z']+500 elseif g_PlayerPosZ > g_Entity[e]['z']+10 then ai_bot_targetz[e] = g_Entity[e]['z']-500 else ai_bot_targetz[e] = g_Entity[e]['z'] end AIEntityGoToPosition(AIObjNo,ai_bot_targetx[e],ai_bot_targety[e],ai_bot_targetz[e]) MoveForward(e,AIGetEntitySpeed(AIObjNo)*0.25) MoveWithAnimation(e,AIGetEntitySpeed(AIObjNo)*0.25) end AISetEntityPosition(AIObjNo,GetEntityPositionX(e),GetEntityPositionY(e),GetEntityPositionZ(e)) SetRotation(e,0,AIGetEntityAngleY(AIObjNo),0) end function madame_tudo_exit(e) if g_Entity[e]['animating'] ~= 11 then SetAnimation(11) PlayAnimation(e) g_Entity[e]['animating'] = 11 end end function EntityLookingAtPlayer(e,dis,v) if g_Entity[e] ~= nil then if dis == nil then dis = 3000 end if v == nil then v = 0.5 end local destx = g_PlayerPosX - g_Entity[e]['x'] local destz = g_PlayerPosZ - g_Entity[e]['z'] if math.sqrt((destx*destx)+(destz*destz)) <= dis then local angle = math.atan2(destx,destz) angle = angle * (180.0 / math.pi) if angle <= 0 then angle = 360 + angle elseif angle > 360 then angle = angle - 360 end while g_Entity[e]['angley'] < 0 or g_Entity[e]['angley'] > 360 do if g_Entity[e]['angley'] <= 0 then g_Entity[e]['angley'] = 360 + g_Entity[e]['angley'] elseif g_Entity[e]['angley'] > 360 then g_Entity[e]['angley'] = g_Entity[e]['angley'] - 360 end end local L = angle - v local R = angle + v if L <= 0 then L = 360 + L elseif L > 360 then L = L - 360 end if R <= 0 then R = 360 + R elseif R > 360 then R = R - 360 end if (L < R and math.abs(g_Entity[e]['angley']) > L and math.abs(g_Entity[e]['angley']) < R) then return 1 elseif (L > R and (math.abs(g_Entity[e]['angley']) > L or math.abs(g_Entity[e]['angley']) < R)) then return 1 else return 0 end else return 0 end end end