I only learned the basics of the basics, and it was already hard to me, so I'm asking help for this.
I'd like to make a ventilator, to always push the player down while he tries to go up.
If someone help me whit that I would be very happy
Thank you.
addhook("movetile","back")
function back(id,x,y)
if player(id,"rot") == ... then
parse("setpos "..id." "..player(id,"y") -1)
end
end
minx=1 --the upper left edge of the room X position
miny=1 --the upper left edge of the room Y position
maxx=5 --the lower right edge of the room X position
maxy=5 --the lower right edge of the room Y position
force=16
addhook("always","push")
function push()
for id=1,32 do
if (player(id,"exists") and player(id,"tilex")>=minx and player(id,"tilex")<=maxx and player(id,"tiley")>=miny and player(id,"tiley")<=maxy) then
parse("setpos "..id.." "..player(id,"x").." "..(player(id,"y")-force))
end
end
end
local vx, vy -- Vent position
function math.distance(x, y, x2, y2)
return math.sqrt((y2-y)^2 + (x2-x)^2);
end
function update()
local t = player(0, "tableliving");
for _, v in ipairs(t) do
local x, y = player(v, "x"), player(v, "y");
local dist = math.distance(x, y, vx, vy);
local angle = math.atan2(vy-y, vx-x);
if ( dist <= 100 ) then
local ratio = 1-dist/100;
local power = 2 * ratio;
x = x - power*math.cos(angle);
y = y - power*math.sin(angle);
parse("setpos "..v.." "..x.." "..y);
end
end
end
addhook("always", "update");
minx=1 --the upper left edge of the room X position
miny=1 --the upper left edge of the room Y position
maxx=5 --the lower right edge of the room X position
maxy=5 --the lower right edge of the room Y position
force=16
push=false
bx=6 --the button X position in tiles
by=6 --the button Y position in tiles
addhook("use","button")
function button(id)
if (player(id,"tilex")==bx and player(id,"tiley")==by) then
if (push) then
push=false
else
push=true
end
end
addhook("always","push")
function push()
for id=1,32 do
if (player(id,"exists") and player(id,"tilex")>=minx and player(id,"tilex")<=maxx and player(id,"tiley")>=miny and player(id,"tiley")<=maxy) then
if (push) then
parse("setpos "..id.." "..player(id,"x").." "..(player(id,"y")-force))
end
end
end
end