Larry I am loving all the videos and demo levels you have been showing especially the hidden base and sinking subs..
You are really getting very productive...
Now to the Lua scripts - as you know I am also learning Lua..
but..
Larry.. I don't think this code is working the way you think.. ( if it is.. then I have a awful lot more to learn)...
The main function has another function embedded inside it... ai_soldier_AggroCheck(e)
This is a copy from the soldier script.. but the (e) in the soldier script is the soldier [e] number..
The (e) in your secruritycam script is the [e] number for the security camera..
You them have the if statement doing the same code and check twice... when open[e] == 1
at step 26
elseif open[e] == 1 and GetPlayerDistance(e) > 300 then
and again at step 72
elseif open[e] == 1 and GetPlayerDistance(e) > 300 then
What I think you are seeing in the video is the soldiers sensing you are within range and then coming after you...
To test... change its script to the one with only camera/siren code...
do the soldiers still come and attack you...
I think this script is animating the camera and activating the siren but it does not warn the guards...yet..
Here is your code with the aggro check removed... does it still work...as in your video..
-- Script by Old Larry -coz I learn the LUA scripts slowly but surely ;) --Many thanks to this great community !!!
-- Security Camera watch and alert enemies automatically when player enter the zone then it closes when player leaves the zone
-- Save the script as securitycam.lua
local open = {}
function securitycam_init(e)
open[e] = 0
end
function securitycam_main(e)
if GetPlayerDistance(e) < 400 then --here you can change you desidered distance at 150, 200,250...
if open[e] == 0 then
-- the camera is closed
StartTimer(e);
if g_Entity[e]['animating'] == 0 then
SetAnimation(1);
PlayAnimation(e);
open[e] = 1
g_Entity[e]['animating'] = 1;
PlaySound(e,0);
SetSoundVolume(90)
CollisionOn(e);
end
elseif open[e] == 1 and GetPlayerDistance(e) > 300 then --here you can change you desidered distance at 150, 200,250...
-- the camera is open
if g_Entity[e]['animating'] == 0 then
SetAnimation(1);
PlayAnimation(e);
open[e] = 1
g_Entity[e]['animating'] = 1;
PlaySound(e,0);
SetSoundVolume(90)
CollisionOn(e); --maintain this ON to can destroy the camera to stop alarm - must set the camera as explodable
end
--ai_soldier_AggroCheck(e);
end
end
end
I think this is how to make it work...
1. You need some way to tell the soldier he is a security guard and has a security camera
2. You need some way for camera to tell it's security guards that the alarm is active.
3. So you need 2 scripts... one for cameras and one for guards...