I've put back the default global.lua script with Avram's and tomjscott's omegacore:
-- LUA Globals Common Header
--
-- Constants
AI_MANUAL = 0
AI_AUTOMATIC = 1
AI_CLOSEST_TO_PLAYER = 50
-- Globals (built-in)
g_Entity = {}
-- AI Globals
ai_soldier_state = {}
ai_soldier_pathindex = {}
ai_combat_mode = {}
ai_combat_state_delay = {}
ai_combat_old_time = {}
ai_combat_turn_delay = 1
ai_combat_cover_delay = 4
ai_combat_delay_after_finding = 2
ai_next_aggro_delay = 0
ai_start_x = {}
ai_start_z = {}
ai_dest_x = {}
ai_dest_z = {}
ai_old_health = {}
ai_ran_to_cover = {}
ai_alerted_mode = {}
ai_alerted_state_delay = {}
ai_alerted_old_time = {}
ai_alerted_spoken = {}
ai_returning_home = {}
ai_alert_x = -10000
ai_alert_z = -10000
ai_alert_counter = 0
ai_alert_entity = 0
ai_path_point_index = {}
ai_path_point_direction = {}
ai_path_point_max = {}
ai_starting_heath = {}
ai_patrol_x = {}
ai_patrol_z = {}
ai_aggro_x = nil
ai_aggro_z = nil
ai_aggro_entity = nil
ai_aggro_range = 400
PlayerDist = 0
-- Weapon name global
weapon_name = {}
-- Globals (passed-in)
g_PlayerPosX = 0
g_PlayerPosY = 0
g_PlayerPosZ = 0
g_PlayerAngX = 0
g_PlayerAngY = 0
g_PlayerAngZ = 0
g_PlayerObjNo = 0
g_PlayerHealth = 0
g_PlayerLives = 0
g_Time = 0
g_TimeElapsed = 0
g_KeyPressE = 0
-- Common Updater Functions (called by Engine)
function UpdateEntitySMALL(e,object,x,y,z)
g_Entity[e] = {x=x; y=y; z=z; obj=object;}
end
function UpdateEntity(e,object,x,y,z,act,col,key,zon,plrvis,ani,hea,frm,tmr,pdst,avd)
g_Entity[e] = {x=x; y=y; z=z; activated=act; animating=ani; collected=col; haskey=key; plrinzone=zon; plrvisible=plrvis; obj=object; health=hea; frame=frm; timer=tmr; plrdist=pdst; avoid=avd; }
end
function UpdateEntityRT(e,object,x,y,z,act,col,key,zon,plrvis,hea,frm,tmr,pdst,avd)
g_Entity[e]['x'] = x;
g_Entity[e]['y'] = y;
g_Entity[e]['z'] = z;
g_Entity[e]['obj'] = object;
g_Entity[e]['activated'] = act;
g_Entity[e]['collected'] = col;
g_Entity[e]['haskey'] = key;
g_Entity[e]['plrinzone'] = zon;
g_Entity[e]['plrvisible'] = plrvis;
g_Entity[e]['health'] = hea;
g_Entity[e]['frame'] = frm;
g_Entity[e]['timer'] = tmr;
g_Entity[e]['plrdist'] = pdst;
g_Entity[e]['avoid'] = avd;
end
function UpdateEntityAnimatingFlag(e,ani)
g_Entity[e]['animating'] = ani;
end
-- Macro Functions
function GetPlayerDistance(e)
tPlayerDX = (g_Entity[e]['x'] - g_PlayerPosX)
tPlayerDY = (g_Entity[e]['y'] - g_PlayerPosY)
tPlayerDZ = (g_Entity[e]['z'] - g_PlayerPosZ)
if math.abs(tPlayerDY) > 100 then
tPlayerDY = tPlayerDY * 4
end
return math.sqrt(math.abs(tPlayerDX*tPlayerDX)+math.abs(tPlayerDY*tPlayerDY)+math.abs(tPlayerDZ*tPlayerDZ));
end
-- Common Action Functions (called by LUA)
function Prompt(str)
SendMessageS("prompt",str);
end
function PromptDuration(str,v)
SendMessageS("promptduration",v,str);
end
function PromptTextSize(v)
SendMessageI("prompttextsize",v);
end
function PromptLocal(e,str)
SendMessageS("promptlocal",e,str);
end
function SetFogNearest(v)
SendMessageF("setfognearest",v)
end
function SetFogDistance(v)
SendMessageF("setfogdistance",v)
end
function SetFogRed(v)
SendMessageF("setfogred",v)
end
function SetFogGreen(v)
SendMessageF("setfoggreen",v)
end
function SetFogBlue(v)
SendMessageF("setfogblue",v)
end
function SetAmbienceIntensity(v)
SendMessageF("setambienceintensity",v)
end
function SetAmbienceRed(v)
SendMessageF("setambiencered",v)
end
function SetAmbienceGreen(v)
SendMessageF("setambiencegreen",v)
end
function SetAmbienceBlue(v)
SendMessageF("setambienceblue",v)
end
function SetSurfaceRed(v)
SendMessageF("setsurfacered",v)
end
function SetSurfaceGreen(v)
SendMessageF("setsurfacegreen",v)
end
function SetSurfaceBlue(v)
SendMessageF("setsurfaceblue",v)
end
function JumpToLevelIfUsed(e)
SendMessageS("jumptolevel",e,"")
end
function JumpToLevel(levelname)
SendMessageS("jumptolevel",0,levelname)
end
function FinishLevel()
SendMessageI("finishlevel",0);
end
function HideTerrain()
SendMessageF("hideterrain",0)
end
function ShowTerrain()
SendMessageF("showterrain",0)
end
function HideWater()
SendMessageF("hidewater",0)
end
function ShowWater()
SendMessageF("showwater",0)
end
function HideHuds()
SendMessageF("hidehuds",0)
end
function ShowHuds()
SendMessageF("showhuds",0)
end
function FreezeAI()
SendMessageF("freezeai",0)
end
function UnFreezeAI()
SendMessageF("unfreezeai",0)
end
function FreezePlayer()
SendMessageF("freezeplayer",0)
end
function UnFreezePlayer()
SendMessageF("unfreezeplayer",0)
end
function SetPlayerHealth(v)
SendMessageF("setplayerhealth",v)
end
function SetEntityHealth(e,v)
SendMessageI("setentityhealth",e,v);
end
function StartParticleEmitter(e)
SendMessageF("startparticleemitter",e,0);
end
function StopParticleEmitter(e)
SendMessageF("stopparticleemitter",e,0);
end
function StartTimer(e)
SendMessageI("starttimer",e);
end
function GetTimer(e)
return g_Time - g_Entity[e]['timer'];
end
function Destroy(e)
SendMessageI("destroy",e);
end
function CollisionOn(e)
SendMessageI("collisionon",e);
end
function CollisionOff(e)
SendMessageI("collisionoff",e);
end
function Hide(e)
SendMessageI("hide",e);
end
function Show(e)
SendMessageI("show",e);
end
function Spawn(e)
SendMessageI("spawn",e);
end
function SetActivated(e,v)
g_Entity[e]['activated'] = v
SendMessageI("setactivated",e,v);
end
function ActivateIfUsed(e)
SendMessageI("activateifused",e);
end
function TransportToIfUsed(e)
SendMessageI("transporttoifused",e);
end
function Collected(e)
SendMessageI("collected",e);
end
function MoveUp(e,v)
SendMessageF("moveup",e,v);
end
function MoveForward(e,v)
SendMessageF("moveforward",e,v);
end
function MoveBackward(e,v)
SendMessageF("movebackward",e,v);
end
function SetPosition(e,x,y,z)
SendMessageF("setpositionx",e,x);
SendMessageF("setpositiony",e,y);
SendMessageF("setpositionz",e,z);
end
function ResetPosition(e,x,y,z)
SendMessageF("resetpositionx",e,x);
SendMessageF("resetpositiony",e,y);
SendMessageF("resetpositionz",e,z);
end
function SetRotation(e,x,y,z)
SendMessageF("setrotationx",e,x);
SendMessageF("setrotationy",e,y);
SendMessageF("setrotationz",e,z);
end
function ModulateSpeed(e,v)
SendMessageF("modulatespeed",e,v);
end
function RotateX(e,v)
SendMessageF("rotatex",e,v);
end
function RotateY(e,v)
SendMessageF("rotatey",e,v);
end
function RotateZ(e,v)
SendMessageF("rotatez",e,v);
end
function Scale(e,v)
SendMessageF("scale",e,v);
end
function SetAnimation(e)
SendMessageI("setanimation",e);
end
function SetAnimationFrames(e,v)
SendMessageI("setanimationframes",e,v);
end
function PlayAnimation(e)
SendMessageI("playanimation",e);
end
function LoopAnimation(e)
SendMessageI("loopanimation",e);
end
function StopAnimation(e)
SendMessageI("stopanimation",e);
end
function SetAnimationSpeed(e,v)
SendMessageI("setanimationspeed",e,v);
end
function SetAnimationFrame(e,v)
SendMessageF("setanimationframe",e,v);
end
function GetAnimationFrame(e)
return g_Entity[e]['frame'];
end
function CharacterControlUnarmed(e)
SendMessageI("charactercontrolunarmed",e);
end
function CharacterControlLimbo(e)
SendMessageI("charactercontrollimbo",e);
end
function CharacterControlArmed(e)
SendMessageI("charactercontrolarmed",e);
end
function CharacterControlFidget(e)
SendMessageI("charactercontrolfidget",e);
end
function CharacterControlDucked(e)
SendMessageI("charactercontrolducked",e);
end
function CharacterControlStand(e)
SendMessageI("charactercontrolstand",e);
end
function SetCharacterToWalk(e)
SendMessageI("setcharactertowalkrun",e,0);
end
function SetCharacterToRun(e)
SendMessageI("setcharactertowalkrun",e,1);
end
function SetCharacterToStrafeLeft(e)
SendMessageI("setcharactertostrafe",e,0);
end
function SetCharacterToStrafeRight(e)
SendMessageI("setcharactertostrafe",e,1);
end
function SetCharacterVisionDelay(e,v)
SendMessageI("setcharactervisiondelay",e,v);
end
function LockCharacterPosition(e,v)
SendMessageI("setlockcharacter",e,1);
end
function UnlockCharacterPosition(e,v)
SendMessageI("setlockcharacter",e,0);
end
function GravityOff(e)
SendMessageI("setnogravity",e,1);
end
function GravityOn(e)
SendMessageI("setnogravity",e,0);
end
function LookAtPlayer(e)
SendMessageI("lookatplayer",e);
end
function RotateToPlayer(e)
SendMessageI("rotatetoplayer",e,100);
end
function RotateToPlayerSlowly(e,v)
SendMessageI("rotatetoplayer",e,v);
end
function AddPlayerWeapon(e)
SendMessageI("addplayerweapon",e);
end
function AddPlayerAmmo(e)
SendMessageI("addplayerammo",e);
end
function AddPlayerHealth(e)
SendMessageI("addplayerhealth",e);
end
function SetPlayerLives(e,v)
SendMessageI("setplayerlives",e,v);
end
function RemovePlayerWeapons(e)
SendMessageI("removeplayerweapons",e);
end
function AddPlayerJetPack(e,fuel)
SendMessageI("addplayerjetpack",e,fuel);
end
function Checkpoint(e)
SendMessageI("checkpoint",e);
end
function GetPlayerInZone(e)
return g_Entity[e]['plrinzone'];
end
function PlaySound(e,v)
SendMessageI("playsound",e,v);
end
function PlaySoundIfSilent(e,v)
SendMessageI("playsoundifsilent",e,v);
end
function PlayNon3DSound(e,v)
SendMessageI("playnon3dsound",e,v);
end
function LoopSound(e,v)
SendMessageI("loopsound",e,v);
end
function StopSound(e,v)
SendMessageI("stopsound",e,v);
end
function SetSoundSpeed(freq)
SendMessageI("setsoundspeed",freq);
end
function SetSoundVolume(vol)
SendMessageI("setsoundvolume",vol);
end
function FireWeapon(e)
SendMessageI("fireweapon",e);
end
function HurtPlayer(e,v)
SendMessageI("hurtplayer",e,v);
end
function SwitchScript(e,str)
SendMessageS("switchscript",e,str);
end
function SetCharacterSound(e,str)
SendMessageS("setcharactersound",e,str);
end
function PlayCharacterSound(e,str)
SendMessageS("playcharactersound",e,str);
end
function PlayCombatMusic(playTime,fadeTime)
music_play_timecue(2,playTime,fadeTime);
end
function PlayFinalAssaultMusic(fadeTime)
music_play_cue(3,fadeTime);
end
function DisableMusicReset(v)
SendMessageI("disablemusicreset",v);
end
function HideLight(e)
SendMessageI("setlightvisible",e,0);
end
function ShowLight(e)
SendMessageI("setlightvisible",e,1);
end
function LoadImages(str,v)
SendMessageS("loadimages",v,str);
end
function SetImagePosition(x,y)
SendMessageF("setimagepositionx",x);
SendMessageF("setimagepositiony",y);
end
function ShowImage(i)
SendMessageI("showimage",i);
end
function HideImage(i)
SendMessageI("hideimage",i);
end
function SetImageAlignment(i)
SendMessageI("setimagealignment",i);
end
-- Load Avram's FPSC:R toolkit
package.path = "scriptbank/?.lua;"
aConfig = aConfig or { path = "Avram/" }
require (aConfig.path .. "bootstrap")
require "omegacore"
Then, to you can have sounds for enemies, just replace from ai_soldier.lua (or whatever other entity you use) the lines "PlayCombatMusic(8000,500)" with
"PlaySound(e, 8000,500)" and of course, then must manual set the sounds in the each characters options.
-- LUA Script - precede every function and global member with lowercase name of script
--local PlayCombatMusic = {}
--local music_play_timecue = {}
--local music_play_cue = {}
ai_newdest_time = {}
ai_cover_on = {}
-- init when level first runs
function ai_soldier_init(e)
ai_soldier_state[e] = "patrol";
ai_soldier_pathindex[e] = -1;
ai_start_x[e] = nil
ai_starting_heath[e] = nil
ai_ran_to_cover[e] = 0
ModulateSpeed(e,1.0)
ai_old_health[e] = 0
CharacterControlStand(e)
ai_returning_home[e] = 0
ai_newdest_time[e] = -1
ai_cover_on[e] = 0
ai_alerted_spoken[e] = 0
SetCharacterSound(e,"testsoldier")
--MsgBox ( "soldier init" )
end
-- logic will patrol closest waypoint path, then shoot at player if they
-- get too close, and will run away for cover if their health is low
function ai_soldier_main(e)
-- Detect player distance (note: possible optimization here)
PlayerDX = g_Entity[e]['x'] - g_PlayerPosX;
PlayerDY = g_Entity[e]['y'] - g_PlayerPosY;
PlayerDZ = g_Entity[e]['z'] - g_PlayerPosZ;
PlayerDist = math.sqrt(math.abs(PlayerDX*PlayerDX)+math.abs(PlayerDY*PlayerDY)+math.abs(PlayerDZ*PlayerDZ));
-- Entity Object Number
EntObjNo = g_Entity[e]['obj'];
if ai_starting_heath[e] == nil then
ai_starting_heath[e] = g_Entity[e]['health']
end
-- Store starting point so we can return there if player moves far away
if ai_start_x[e] == nil then
ai_start_x[e] = g_Entity[e]['x']
ai_start_z[e] = g_Entity[e]['z']
AISetEntityControl(EntObjNo,AI_MANUAL);
end
-- Patrol Mode
if ai_soldier_state[e] == "patrol" then
-- Try and find a close path to patrol, just check once for it
if ai_soldier_pathindex[e] == -1 then
ai_soldier_pathindex[e] = -2
CharacterControlArmed(e)
-- find initial waypoint path to follow
PathIndex = -1;
pClosest = 99999;
for pa = 1, AIGetTotalPaths(), 1 do
for po = 1 , AIGetPathCountPoints(pa), 1 do
pDX = g_Entity[e]['x'] - AIPathGetPointX(pa,po);
pDZ = g_Entity[e]['z'] - AIPathGetPointZ(pa,po);
pDist = math.sqrt(math.abs(pDX*pDX)+math.abs(pDZ*pDZ));
if pDist < pClosest and pDist < 200 then
pClosest = pDist;
PathIndex = pa;
end
end -- po
end -- pa
-- follow found path
if PathIndex > -1 then
ai_soldier_pathindex[e] = PathIndex;
ai_path_point_index[e] = 2
ModulateSpeed(e,1.0)
SetCharacterToWalk(e)
ai_path_point_direction[e] = 1
ai_path_point_max[e] = AIGetPathCountPoints(ai_soldier_pathindex[e])
end
end
CharacterControlUnarmed(e)
-- If set to head home, lets go there
if ai_returning_home[e] == 1 then
tDistX = g_Entity[e]['x'] - ai_start_x[e];
tDistZ = g_Entity[e]['z'] - ai_start_z[e];
DistToStart = math.sqrt(math.abs(tDistX*tDistX)+math.abs(tDistZ*tDistZ))
if DistToStart < 200 or GetTimer(e) > ai_combat_state_delay[e] then
ai_soldier_pathindex[e] = -1
SetCharacterToWalk(e)
CharacterControlUnarmed(e)
AIEntityStop(EntObjNo);
ModulateSpeed(e,1.0)
ai_returning_home[e] = 0
ai_soldier_state[e] = "alerted"
ai_alerted_mode[e] = 0
else
AIEntityGoToPosition(EntObjNo,ai_start_x[e],ai_start_z[e])
end
-- If we have a path then lets patrol it
elseif ai_soldier_pathindex[e] > -1 then
ai_patrol_x[e] = AIPathGetPointX(ai_soldier_pathindex[e],ai_path_point_index[e])
ai_patrol_z[e] = AIPathGetPointZ(ai_soldier_pathindex[e],ai_path_point_index[e])
AIEntityGoToPosition(EntObjNo,ai_patrol_x[e],ai_patrol_z[e])
tDistX = g_Entity[e]['x'] - ai_patrol_x[e]
tDistZ = g_Entity[e]['z'] - ai_patrol_z[e]
DistFromPath = math.sqrt(math.abs(tDistX*tDistX)+math.abs(tDistZ*tDistZ))
if DistFromPath < 50 then
if ai_path_point_direction[e] == 1 then
ai_path_point_index[e] = ai_path_point_index[e] + 1
if ( ai_path_point_index[e] > ai_path_point_max[e] ) then
ai_path_point_index[e] = ai_path_point_max[e] -1
ai_path_point_direction[e] = 0
end
else
ai_path_point_index[e] = ai_path_point_index[e] - 1
if ( ai_path_point_index[e] < 1 ) then
ai_path_point_index[e] = 2
ai_path_point_direction[e] = 1
end
end
end
else
CharacterControlFidget(e)
end
ai_soldier_AggroCheck(e)
ai_soldier_AlertAggroCheck(e)
-- Alerted, perhaps player is near or gunshots can be heard?
if PlayerDist < AIGetEntityViewRange(EntObjNo) / 3 or AIGetEntityHeardSound(EntObjNo) == 1 then
ai_soldier_state[e] = "alerted"
ai_alerted_mode[e] = 0
ai_alert_x = g_Entity[e]['x']
ai_alert_z = g_Entity[e]['z']
ai_alert_counter = 10
ai_alert_entity = e
end
end
-- alerted mode
if ai_soldier_state[e] == "alerted" then
LookAtPlayer(e)
-- alert taken out
if g_Entity[e]['plrvisible'] == 1 then
ai_soldier_state[e] = "combat";
--replace or hide all "PlayCombatMusic(8000,500)" from this script and use:
PlaySound(e,8000,500)
ai_combat_mode[e] = 0
-- Add this enemy as a point of aggro, alerting anyone near to join the fight
ai_aggro_entity = e
ai_aggro_x = g_Entity[e]['x']
ai_aggro_z = g_Entity[e]['z']
AISetEntityControl(EntObjNo,AI_MANUAL)
AIEntityStop(EntObjNo)
CharacterControlArmed(e)
SetCharacterToRun(e)
else
if ai_alerted_mode[e] == 0 then
tSpeed = math.random(100,130) / 100.0
ModulateSpeed(e,tSpeed)
angle = math.random(360)
ai_dest_x[e] = g_PlayerPosX + (math.sin(angle) * 150)
ai_dest_z[e] = g_PlayerPosZ + (math.cos(angle) * 150)
AIEntityGoToPosition(EntObjNo,ai_dest_x[e],ai_dest_z[e])
ai_alerted_state_delay[e] = math.random(0,1)
ai_alerted_old_time[e] = os.clock()
CharacterControlArmed(e)
ai_alerted_mode[e] = 1
if ai_alerted_spoken[e] == 0 then
PlayCharacterSound(e,"onAlert")
ai_alerted_spoken[e] = 1
end
-- Target the player, run in to attack
elseif ai_alerted_mode[e] == 1 then
LookAtPlayer(e)
if os.clock() - ai_alerted_old_time[e] > ai_alerted_state_delay[e] then
ai_alerted_state_delay[e] = 2
ai_alerted_mode[e] = 2
AIEntityGoToPosition(EntObjNo,ai_dest_x[e],ai_dest_z[e])
end
elseif ai_alerted_mode[e] == 2 then
if os.clock() - ai_alerted_old_time[e] > ai_alerted_state_delay[e] then
AIEntityStop(EntObjNo)
ai_alerted_mode[e] = 0
ai_soldier_state[e] = "patrol";
ai_soldier_AggroCheck(e)
end
end
if g_Entity[e]['plrvisible'] == 1 then
ai_soldier_state[e] = "combat";
PlaySound(e,8000,500)
ai_combat_mode[e] = 0
-- Add this enemy as a point of aggro, alerting anyone near to join the fight
ai_aggro_entity = e
ai_aggro_x = g_Entity[e]['x']
ai_aggro_z = g_Entity[e]['z']
AISetEntityControl(EntObjNo,AI_MANUAL)
AIEntityStop(EntObjNo)
CharacterControlArmed(e)
SetCharacterToRun(e)
end
end
end
-- Combat mode
if ai_soldier_state[e] == "combat" then
LookAtPlayer(e)
-- If we are the soldier with aggro then update our position so if we run near to others, we can alert them to the fight
if ai_aggro_entity ~= null then
if ai_aggro_entity == e then
ai_aggro_x = g_Entity[e]['x']
ai_aggro_z = g_Entity[e]['z']
end
end
--Prompt(ai_combat_mode[e])
-- Kick off combat by choosing a destination to head for around the player
if ai_combat_mode[e] == 0 then
tSpeed = math.random(100,130) / 100.0
ModulateSpeed(e,tSpeed)
angle = math.random(360)
ai_dest_x[e] = g_PlayerPosX + (math.sin(angle) * 200)
ai_dest_z[e] = g_PlayerPosZ - (math.cos(angle) * 200)
-- Check if we can get to the new position without going around something
if ( AICouldSee ( EntObjNo , ai_dest_x[e] , g_Entity[e]['y'] , ai_dest_z[e] ) == 0 ) then
ai_dest_x[e] = g_PlayerPosX;
ai_dest_z[e] = g_PlayerPosZ;
end
if PlayerDist < AI_CLOSEST_TO_PLAYER then
ai_dest_x[e] = g_Entity[e]['x']
ai_dest_z[e] = g_Entity[e]['z']
end
StartTimer(e)
CharacterControlArmed(e)
ai_combat_mode[e] = 1
ai_cover_on[e] = AIEntityMoveToCover(EntObjNo,g_PlayerPosX,g_PlayerPosZ)
if ai_cover_on[e] == 0 then
AIEntityGoToPosition(EntObjNo,ai_dest_x[e],ai_dest_z[e])
ai_combat_state_delay[e] = math.random(250,500)
else
ai_combat_state_delay[e] = math.random(1000,2000)
end
-- Target the player, wait a short time then run in to attack
elseif ai_combat_mode[e] == 1 then
if GetTimer(e) > ai_combat_state_delay[e] then
ai_combat_state_delay[e] = math.random(1000,2500)
StartTimer(e)
ai_combat_mode[e] = 2
end
if g_Entity[e]['plrvisible'] == 1 then
FireWeapon(e)
end
-- Run to destination for a small amount of time
elseif ai_combat_mode[e] == 2 then
if g_Entity[e]['plrvisible'] == 1 then
FireWeapon(e)
end
if (GetTimer(e) > ai_combat_state_delay[e]) or PlayerDist <= AI_CLOSEST_TO_PLAYER then
ai_combat_mode[e] = 3
end
-- Target the player
elseif ai_combat_mode[e] == 3 then
CharacterControlArmed(e)
ai_combat_mode[e] = 4
if ai_cover_on[e] == 1 then
ai_combat_state_delay[e] = math.random(500,1500)
else
ai_combat_state_delay[e] = math.random(250,500)
end
StartTimer(e)
-- Shoot the player if we can, if not head off to find him
elseif ai_combat_mode[e] == 4 then
if g_Entity[e]['plrvisible'] == 1 then
FireWeapon(e)
PlaySound(e,8000,500)
end
if ai_cover_on[e] == 1 then
CharacterControlDucked(e)
end
-- Once our shooting time has ended, lets go back to mode 0 and start over
-- If we cannot see the player, wait a short time before hunting him down
if GetTimer(e) > ai_combat_state_delay[e] then
CharacterControlStand(e)
if g_Entity[e]['plrvisible'] == 0 then
ai_combat_mode[e] = 7
ai_cover_on[e] = 0
ai_combat_state_delay[e] = math.random(1000,2000)
StartTimer(e)
AIEntityGoToPosition(EntObjNo,g_PlayerPosX,g_PlayerPosZ)
else
ai_combat_mode[e] = 0
end
end
ai_old_health[e] = g_Entity[e]['health']
-- In cover, we wait a while, shoot if we can see the player, before venturing out again
elseif ai_combat_mode[e] == 5 then
CharacterControlArmed(e)
if g_Entity[e]['plrvisible'] == 1 then
FireWeapon(e)
end
if GetTimer(e) > ai_combat_old_time[e] then
ModulateSpeed(e,1.0)
--AIEntityStop(EntObjNo)
ai_combat_mode[e] = 0
end
-- Out of the range of the player, heading back to start point for a while, once there going back to Patrol mode
elseif ai_combat_mode[e] == 6 then
ai_returning_home[e] = 1
SetCharacterToWalk(e)
CharacterControlUnarmed(e)
AIEntityGoToPosition(EntObjNo,ai_start_x[e],ai_start_z[e])
ai_soldier_state[e] = "patrol"
ai_combat_state_delay[e] = 3000
StartTimer(e)
tSpeed = math.random(100,130) / 100.0
ModulateSpeed(e,tSpeed)
return
-- Unable to see the player to shoot, so heading after him
elseif ai_combat_mode[e] == 7 then
if g_Entity[e]['plrvisible'] == 1 then
FireWeapon(e)
end
AIEntityGoToPosition(EntObjNo,g_PlayerPosX,g_PlayerPosZ)
if ( g_Entity[e]['plrvisible'] == 1 or PlayerDist <= AI_CLOSEST_TO_PLAYER ) and GetTimer(e) > ai_combat_state_delay[e] then
ai_combat_mode[e] = 0
end
elseif ai_combat_mode[e] == 8 then
ai_combat_mode[e] = 9
AIEntityStop(EntObjNo)
elseif ai_combat_mode[e] == 9 then
ai_combat_mode[e] = 10
-- Pick left or right strafe
if ( math.random(0,1) == 0 ) then
SetCharacterToStrafeLeft(e)
else
SetCharacterToStrafeRight(e)
end
ai_combat_old_time[e] = os.clock()
elseif ai_combat_mode[e] == 10 then
-- We can see the player, lets shoot him!
if g_Entity[e]['plrvisible'] == 1 then
FireWeapon(e)
end
if os.clock() - ai_combat_old_time[e] > ai_combat_state_delay[e] then
ai_combat_state_delay[e] = math.random(1,3)
ai_combat_mode[e] = 4
ai_old_health[e] = g_Entity[e]['health']
end
elseif ai_combat_mode[e] == 11 then
if g_Entity[e]['plrvisible'] == 1 then
if os.clock() - ai_combat_old_time[e] > ai_combat_state_delay[e] then
CharacterControlStand(e)
ai_combat_old_time[e] = os.clock()
ai_combat_state_delay[e] = 1
ai_combat_mode[e] = 12
end
end
if ai_combat_mode[e] == 12 then
if g_Entity[e]['plrvisible'] == 1 then
FireWeapon(e)
end
if os.clock() - ai_combat_old_time[e] > ai_combat_state_delay[e] then
ai_combat_mode[e] = 4
end
end
end
-- If health is below 30, run and hide, then head to mode 5
if g_Entity[e]['health'] < 30 and ai_combat_mode[e] ~= 4 and ai_ran_to_cover[e] == 0 then
ModulateSpeed(e,1.3)
ai_ran_to_cover[e] = 1
AISetEntityControl(EntObjNo,AI_MANUAL);
a=AIEntityMoveToCover(EntObjNo,g_PlayerPosX,g_PlayerPosZ);
ai_combat_old_time[e] = 3000
StartTimer(e)
ai_combat_mode[e] = 5
end
-- When player out of range, return to patrol
if PlayerDist > AIGetEntityViewRange(EntObjNo)*1.5 then
ai_combat_mode[e] = 6
end
end
--if (ai_combat_mode[e] ~= nil) then
-- PromptLocal(e,"SS:" .. ai_soldier_state[e] .. " CM:" .. ai_combat_mode[e] .. " PV:" .. g_Entity[e]['plrvisible'] )
--end
end
function ai_soldier_AggroCheck(e)
-- If there player is in range and we can see him, or we have been shot, move into combat mode
if PlayerDist < AIGetEntityViewRange(EntObjNo) then
if g_Entity[e]['plrvisible'] == 1 or g_Entity[e]['health'] < ai_starting_heath[e] then
ai_soldier_state[e] = "combat";
PlaySound(e,8000,500)
ai_combat_mode[e] = 0
PlayCharacterSound(e,"onAggro")
-- Add this enemy as a point of aggro, alerting anyone near to join the fight
ai_aggro_entity = e
ai_aggro_x = g_Entity[e]['x']
ai_aggro_z = g_Entity[e]['z']
ai_alert_x = g_Entity[e]['x']
ai_alert_z = g_Entity[e]['z']
AISetEntityControl(EntObjNo,AI_MANUAL)
AIEntityStop(EntObjNo);
SetCharacterToRun(e)
else
-- We cant see the player, but perhaps we are near someone that can
if ai_aggro_entity ~= nil then
tDistX = g_Entity[e]['x'] - ai_aggro_x
tDistZ = g_Entity[e]['z'] - ai_aggro_z
tDist = math.sqrt(math.abs(tDistX*tDistX)+math.abs(tDistZ*tDistZ))
if tDist < ai_aggro_range then
ai_soldier_state[e] = "combat";
PlaySound(e,8000,500)
ai_combat_mode[e] = 0
AISetEntityControl(EntObjNo,AI_MANUAL)
AIEntityStop(EntObjNo);
SetCharacterToRun(e)
end
end
end
end
end
function ai_soldier_AlertAggroCheck(e)
-- If there is an alert close by
if e == ai_alert_entity then
ai_alert_counter = ai_alert_counter - 1
if ai_alert_counter <= 0 then
ai_alert_x = -10000
ai_alert_z = -10000
ai_alert_entity = 0
end
end
pDX = g_Entity[e]['x'] - ai_alert_x
pDZ = g_Entity[e]['z'] - ai_alert_z;
pDist = math.sqrt(math.abs(pDX*pDX)+math.abs(pDZ*pDZ));
if pDist < 800 then
ai_soldier_state[e] = "alerted"
ai_alerted_mode[e] = 0
end
end
function ai_soldier_exit(e)
PlayCharacterSound(e,"onDeath")
end
One short video with characters sounds:
See the attached picture.
Smile today, tomorrow could be worse
http://bestradiolarry.ro/fpsarea
"The best forum, game software, operating system or web platform, it's that software which can give you most of the features and speed, not just amazing graphics."