I wrote the attached as a blocking zone script. To do the blocking It uses one hidden/invisible entity that is moved in front of player if they are inside a trigger zone with this script attached.
-- Attach script to a trigger zone and extend the zone to the full area to be blocked to the player
-- Also needs an entity to be added to the map with its known entity number set in the script
-- Tested with the 'Gates' entity
-- Set Gates entity to not spawn at start after placement in map - can be placed anywhere
-- LUA Script - attach script to a trigger zone and extend the zone to the full area to be blocked to the player
-- Also needs an entity to be added to the map with its known entity number set in script below (also set entity to not spawn at start)
-- Tested with the 'Gates' entity
-- By cybernescence. Free to use for any purpose.
local blocking_entity_e = 7 -- set to the entity you are using to block the player (this is displayed on status bar once entity placed), also set this entity to not spawn at start
local blocking_message = "Hey, you can't go this way !" -- change to whatever message you'd like to display when player is blocked
local i_state = {}
local i_toggle = {}
local itemdist = 50
local tCheckTime = {}
local initialY = {}
local initialX = {}
local initialZ = {}
function blocking_zone_init(e)
i_state[e] = "start"
end
function blocking_zone_main(e)
if g_Entity[e]['plrinzone'] == 1 then
-- spawn the entity and hide it (make invisible)
if i_state[e] == "start" then
if g_Entity[blocking_entity_e] == nil then
Prompt("Error - this entity does not exist - check documentation in blocking_zone script!")
return
end
Spawn(blocking_entity_e)
Hide(blocking_entity_e)
tCheckTime[e] = GetTimer(e)
initialY[e] = g_PlayerPosY
initialX[e] = g_PlayerPosX
initialZ[e] = g_PlayerPosZ
entity_in_front_of_player(blocking_entity_e)
i_toggle[e] = "place"
i_state[e] = "block"
return
end
--position & rotate (invisible) entity to block player
if i_state[e] == "block" then
--entity_in_front_of_player(blocking_entity_e)
Prompt(blocking_message)
if i_toggle[e] == "set" then
--used if player moves in/out of zone or materially shifts position
entity_in_front_of_player(blocking_entity_e)
tCheckTime[e] = GetTimer(e)
i_toggle[e] = "place"
else
-- placing object with collision
GravityOn(blocking_entity_e)
CollisionOn(blocking_entity_e)
end
if GetTimer(e) >= tCheckTime[e] + 1000 then
if (g_PlayerPosX >= initialX[e] -75 and g_PlayerPosX <= initialX[e] +75) or (g_PlayerPosZ >= initialZ[e]-75 and g_PlayerPosZ <= initialZ[e]+75) then
else
initialY[e] = g_PlayerPosY
initialX[e] = g_PlayerPosX
initialZ[e] = g_PlayerPosZ
i_toggle[e] = "set"
end
end
end
else
initialY[e] = g_PlayerPosY
initialX[e] = g_PlayerPosX
initialZ[e] = g_PlayerPosZ
i_toggle[e] = "set"
end
end
function entity_in_front_of_player(e)
GravityOff(e)
CollisionOff(e)
itemx=g_PlayerPosX
itemz=g_PlayerPosZ
itemy=g_PlayerPosY
itemx = itemx+math.sin(math.rad(g_PlayerAngY))*itemdist
itemz = itemz+math.cos(math.rad(g_PlayerAngY))*itemdist
itemy = itemy-math.sin(math.rad(g_PlayerAngX))*itemdist
SetPosition(e,itemx,itemy-80,itemz)
yangle = g_PlayerAngY
if g_PlayerAngY >= 360 then
yangle = g_PlayerAngY - (360 * (math.floor(g_PlayerAngY / 360)))
elseif g_PlayerAngY < 0 and g_PlayerAngY > -360 then
yangle = g_PlayerAngY + 360
elseif g_PlayerAngY <= -360 then
yangle = g_PlayerAngY + (360 * ( -1 * (math.floor(g_PlayerAngY / 360))))
end
FaceAngle = yangle + 180
if FaceAngle > 360 then
FaceAngle = FaceAngle - 360
end
SetRotation(e,0,FaceAngle,0)
GravityOn(e)
CollisionOn(e)
end
Seems to work OK for me.