-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
148 lines (133 loc) · 4.31 KB
/
init.lua
File metadata and controls
148 lines (133 loc) · 4.31 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
NpcMovingUtils = require("NpcMovingUtils")
ShitUtils = require("ShitUtils.lua")
Multipunk = {
DebugMode = true,
PlayerEntityIds = {},
-- LastPosition = Vector4.new(0, 0, 0, 1),
-- LastRotation = EulerAngles.new(0, 0, 0),
}
registerHotkey("Test", "Test", function()
local entity = Game.FindEntityByID(Multipunk.PlayerEntityIds[0])
local position = Game.GetPlayer():GetWorldPosition()
local pol = MovePolicies.new()
pol:SetDestinationPosition(position)
pol:SetMovementType(moveMovementType.Sprint)
local mpc = entity:GetMovePolicesComponent()
print(mpc:IsOnStairs())
mpc:AddPolicies(pol)
end)
registerHotkey("RemoveAll", "RemoveAll", function()
RemoveAll()
end)
function RemoveAll()
local searchQuery = Game["TSQ_ALL;"]()
searchQuery.maxDistance = 1000
local success, parts = Game.GetTargetingSystem():GetTargetParts(Game.GetPlayer(), searchQuery)
if success then
local entities = {}
for i, v in ipairs(parts) do
local entity = v:GetComponent(v):GetEntity()
-- print(entity:IsVehicle())
if (entity:IsVehicle()) then
entity:Dispose()
end
if (entity:IsNPC()) then
entity:Dispose()
end
end
end
end
function Multipunk:OnMove(position, rotation)
local packet = {
packetType = "ClientPlayerMovePacket",
x = position.x,
y = position.y,
z = position.z,
yaw = rotation.yaw,
pitch = rotation.pitch
}
if Multipunk.DebugMode == false then
ConnectionSend(json.encode(packet) .. "\n")
else
packet["packetType"] = "ServerPlayerMovePacket"
packet["id"] = 1337
Multipunk:OnReceive(packet)
end
end
function Multipunk:OnReceive(packet)
-- print(packet)
local packetType = packet["packetType"]
if packetType == "ServerPlayerJoinPacket" then
local playerId = packet["id"]
local eid = Multipunk.PlayerEntityIds[playerId]
if (eid == nil) then
local spawnPosition = Game.GetPlayer():GetWorldTransform()
eid = exEntitySpawner.SpawnRecord('Character.Judy', spawnPosition)
Multipunk.PlayerEntityIds[key] = eid
end
end
if packetType == "ServerPlayerLeavePacket" then
local playerId = packet["id"]
local eid = Multipunk.PlayerEntityIds[playerId]
if (eid ~= nil) then
exEntitySpawner.Despawn(Game.FindEntityByID(eid))
end
end
if packetType == "ServerPlayerMovePacket" then
local playerId = packet["id"]
local eid = Multipunk.PlayerEntityIds[playerId]
if (eid == nil) then
local spawnPosition = Game.GetPlayer():GetWorldTransform()
eid = exEntitySpawner.SpawnRecord('Character.Judy', spawnPosition)
Multipunk.PlayerEntityIds[playerId] = eid
end
local position = Vector4.new(packet["x"], packet["y"], packet["z"], 1)
local rotation = EulerAngles.new(0, packet["pitch"], packet["yaw"])
local entity = Game.FindEntityByID(eid)
Multipunk:MoveNPC(entity, position, rotation)
end
end
function Multipunk:MoveNPC(entity, position, orientation)
local dist = entity:GetWorldPosition():Distance(position)
if (dist < 0.5) then
if (ShitUtils.EulerAnglesEuqials(entity:GetWorldOrientation():ToEulerAngles(), orientation) == false) then
NpcMovingUtils.Rotate(entity, orientation)
end
elseif (dist < 5) then
NpcMovingUtils.WalkTo(entity, position)
else
NpcMovingUtils.TeleportTo(entity, position)
end
end
function Multipunk:new()
registerForEvent("onInit", function()
-- ConnectionConnect("127.0.0.1", 2077)
end)
registerForEvent("onShutdown", function()
-- ConnectionDisconnect()
for key, val in pairs(Multipunk.PlayerEntityIds) do
exEntitySpawner.Despawn(Game.FindEntityByID(val))
end
Multipunk.PlayerEntityIds = {}
end)
registerForEvent("onUpdate", function(delta)
while true do
local rec = ConnectionReceive()
if (rec ~= nil and rec ~= "") then
-- print(rec)
local packet = json.decode(rec)
Multipunk:OnReceive(packet)
else
break
end
end
local position = Game.GetPlayer():GetWorldPosition()
local rotation = Game.GetPlayer():GetWorldOrientation():ToEulerAngles()
-- if position.x ~= Multipunk.LastPosition.x or position.y ~= Multipunk.LastPosition.y or position.z ~= Multipunk.LastPosition.z or rotation.pitch ~= Multipunk.LastRotation.pitch or rotation.roll ~= Multipunk.LastRotation.roll or rotation.yaw ~= Multipunk.LastRotation.yaw then
Multipunk:OnMove(position, rotation)
-- Multipunk.LastPosition = position
-- Multipunk.LastRotation = rotation
-- end
end)
end
return Multipunk:new()