Hi there!
Finally, i've got it! )))
Ready to use script for climbing ladders. All day i've wasted to create one script instead of two. Now any top and bottom active parts of ladder can have the same script (ladder.lua), which understand all it needs. In addition, any other ladders use the same script. It is only one!!! You need to place a ladder, set up right names for active parts, prepare climbing zones and entity's "if used" parameters. No bugs, ready to use. You can see the result using the link below.
----------- GOOGLE DISK VIDEO CONNECTOR START (USE CHROME TO OPEN)-----------
https://drive.google.com/file/d/1LUaAfozOkM4NAfJNQyC2XEwPbuT241ds/view?usp=sharing
----------- GOOGLE DISK VIDEO CONNECTOR END-----------
Here you can see the code itself.
-- LUA Script - precede every function and global member with lowercase name of script + '_main'
pressed = 0
timer_on_up = {}
timer_on_down = {}
timer_up = {}
timer_down = {}
entity_name = {}
ldist_t = {}
ldist_b = {}
l_e_t = {}
l_e_b = {}
function ladder_init_name(e,name)
entity_name[e]=name
local numpos=string.find(name,"_");
local laddernum = string.sub(entity_name[e],numpos+1,numpos+3)
if(string.find(name,"laddertop") ~= nil) then
l_e_t[laddernum]=e
else
if(string.find(name,"ladderbottom") ~= nil) then
l_e_b[laddernum]=e
end
end
ldist_t[laddernum]=0
ldist_b[laddernum]=0
timer_on_up[laddernum]=0
timer_on_down[laddernum]=0
timer_up[laddernum]=0
timer_down[laddernum]=0
end
function ladder_main(e)
local numpos=string.find(entity_name[e],"_");
local laddernum = string.sub(entity_name[e],numpos+1,numpos+3)
if(l_e_b[laddernum] and l_e_t[laddernum]) then
Prompt("L_E_B : " .. l_e_b[laddernum] .. " L_E_T : " .. l_e_t[laddernum])
end
if(l_e_b[laddernum] ~= nil) then
ldist_b[laddernum]=GetPlayerDistance(l_e_b[laddernum])
end
if(l_e_t[laddernum] ~= nil) then
ldist_t[laddernum]=GetPlayerDistance(l_e_t[laddernum])
end
if(ldist_b[laddernum]<ldist_t[laddernum]) then
if(ldist_b[laddernum]<100) then
Text(1,8,3,"Press E to climb up the ladder: " .. laddernum)
if g_KeyPressE == 1 then
pressed = 1
end
if g_KeyPressE == 0 and pressed == 1 then
timer_on_up[laddernum] = 1
timer_up[laddernum] = 0
pressed = 0
end
if timer_on_up[laddernum] == 1 then
timer_up[laddernum] = timer_up[laddernum] + 1
if timer_up[laddernum] > 50 then
timer_on_up[laddernum] = 0
timer_up[laddernum] = 0
TransportToIfUsed(l_e_b[laddernum])
end
end
end
else
if(ldist_t[laddernum]<100) then
Text(1,11,3,"Press E to climb down the ladder: " .. laddernum)
if g_KeyPressE == 1 then
pressed = 1
end
if g_KeyPressE == 0 and pressed == 1 then
timer_on_down[laddernum] = 1
timer_down[laddernum] = 0
pressed = 0
end
if timer_on_down[laddernum] == 1 then
timer_down[laddernum] = timer_down[laddernum] + 1
if timer_down[laddernum] > 50 then
timer_on_down[laddernum] = 0
timer_down[laddernum] = 0
TransportToIfUsed(l_e_t[laddernum])
end
end
end
end
if(ldist_b[laddernum]<100 or ldist_t[laddernum]<100) then
Text(1,2,3,"Dist_T: " .. ldist_t[laddernum] .. " Dist_B: " .. ldist_b[laddernum])
end
Text(1,15,3,"Timer On Up: " .. timer_on_up[laddernum] .. " Timer Up: " .. timer_up[laddernum])
Text(1,18,3,"Timer On Down: " .. timer_on_down[laddernum] .. " Timer Down: " .. timer_down[laddernum])
end
I will be glad to here some response for anyone who test it. And if you want to use it, you need to do several steps:
1. Save script as ladder.lua (no further changes neede to the script)
2. Then create ladder with bottom and top parts, and set up lua script for each active part as "ladder.lua"
3. There is one important rule. Name of bottom part is to be "ladderbottom_XX", and name of top is to be "laddertop_XX", where XX - is unique integer. I used in the video numbers 1,2,3.
4. Place 2 trigger zones near bottom and top and give names (names can be any as you want, but all trigger zones for all ladders are to be unique). This is important. I used int the video the following name for trigger zones: "ltop__1", "lbottom__1", "ltop__2", "lbottom__2", "ltop__3", "lbottom__3"
5. Then apply this names to "if used" parameters of active parts of you ladder.
That's all! If someone wants to test it and failing with setting the things up, i can create a short tutorial on this topic.
Thank you for all answers!!!