-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2 Way Teleporter.lua
79 lines (51 loc) · 1.58 KB
/
2 Way Teleporter.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
--@name 2 Way Teleporter
--@author Ax25
--@server
local seats = {}
local saved = {}
function getOtherSeat(seat)
for i, s in pairs(seats) do
if seat ~= s then
return s
end
end
end
function handleSeat(ply, vehicle)
if not ( ply and ply:isValid() ) or not ( vehicle and vehicle:isValid() ) then
return
end
if seats[vehicle:entIndex()] and vehicle.busy then
vehicle:ejectDriver()
return
end
if seats[vehicle:entIndex()] then
vehicle.busy = true
local oldPos = vehicle:getPos()
local otherSeat = getOtherSeat(vehicle)
vehicle:setPos(otherSeat:getPos())
vehicle:ejectDriver()
vehicle:setPos(oldPos)
vehicle.busy = false
end
end
if getUserdata() ~= "" then
saved = bit.stringToTable(getUserdata())
end
if not table.isEmpty(saved) then
hook.add("DupeFinished", "restore", function(tbl)
for entIndex, seat in pairs(tbl) do
if saved[entIndex] then
seats[seat:entIndex()] = seat
end
end
setUserdata(bit.tableToString(seats))
hook.add("PlayerEnteredVehicle", "teleporter", handleSeat)
end)
else
local seat1 = prop.createSent(chip():getPos() + Vector(-30, 0, 30), Angle(), "phx_seat", true)
local seat2 = prop.createSent(chip():getPos() + Vector(30, 0, 30), Angle(), "phx_seat", true)
seats[seat1:entIndex()] = seat1
seats[seat2:entIndex()] = seat2
setUserdata(bit.tableToString(seats))
hook.add("PlayerEnteredVehicle", "teleporter", handleSeat)
end