Here\'s a simple script I wrote to hurt the player if he gets too near an object.
I\'m using this to set limits on where the player can go (too far up a mountain, leaving the combat zone, etc).
Attach to a dynamic entity. If the player gets within a certain distance from the entity, he/she will begin to lose health at a rate determined in the script (see comments).
This usually discourages players from going any further! The entity is hidden in game play but not in the editor, but use a very low poly model for it anyway.
The script can be attached to multiple entities (thanks to smallg here for how to do this in lua, I\'m a Delphi guy myself!).
These entities can then be placed where you don\'t want the player to go.
I wrote this to get around the fact that if I decrease the climb angle value of the player too low (to stop going over hills, etc), the player then cannot climb stairs and stuff.
Feel free to improve upon it!
-- LUA Script - precede every function and global member with lowercase name of script + \'_main\'
-- Hurt the player if he/she tries to leave an area
-- Attach to a dynamic entity. If the player gets within a certain distance from the entity
-- he/she will begin to lose health
-- For reference, the map max dimensions is 51200 x 51200, so if an entity is placed in the middle of the map
-- the max distance the player can be from the entity (using Pythagoras) is
-- sqrt((25600*25600) + (25600*25600)) units, which is approximately 36203 units
local barrier = {} -- array to store barrier object references in
local stop_timer = 0 -- variable to set timer state
local the_time = 0 -- keeps track of elapsed time
local start_hurting_player = 1 -- hurt the player after this amount of time in seconds
local hurt_player_by = 5 -- subtract this amount of health from the player after start_hurting_player seconds
local max_barriers = 1
local a = 1
function mission_area_init(e)
barrier[a] = e
max_barriers = a
Hide(barrier[a])
a = a + 1
end
function mission_area_main(e)
for a = 1, max_barriers do
if g_Entity[barrier[a]] ~= nil then
PlayerDX = g_Entity[barrier[a]]['x'] - g_PlayerPosX;
PlayerDY = g_Entity[barrier[a]]['y'] - g_PlayerPosY;
PlayerDZ = g_Entity[barrier[a]]['z'] - g_PlayerPosZ;
PlayerDist = math.sqrt(math.abs(PlayerDX*PlayerDX)+math.abs(PlayerDY*PlayerDY)+math.abs(PlayerDZ*PlayerDZ));
if PlayerDist > 400 and PlayerDist <= 1000 then -- change these distance values for warning player
Prompt("REMEMBER...NOBODY LIKES A COWARD!") -- change this string to whatever you like
end -- PlayerDist > 400 and PlayerDist <= 1000
if PlayerDist < 400 then -- change this distance value for hurting player
Prompt("YOU ARE BEING PUNISHED FOR RUNNING AWAY!") -- change this string to whatever you like
if stop_timer == 0 then
StartTimer(barrier[a])
stop_timer = 1
end -- stop_timer == 0
the_time = GetTimer(barrier[a]) / 1000
if the_time >= start_hurting_player then
PlaySound(barrier[a],0) -- a SHORT sound, set this in Sound0
HurtPlayer(e,hurt_player_by) -- actually hurt_player_by * 2
stop_timer = 0
end
end -- PlayerDist < 400
end -- check for nil barrier
end -- for loop
end -- function
Brook's Law ..."adding manpower to a late software project makes it later"