This repository has been archived by the owner on May 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
construct.lua
140 lines (116 loc) · 4.25 KB
/
construct.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
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
--[[
Copyright (C) 2020 Jacob Schlecht
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.]]--
local prop_limit = 100
local admins_remove = {}
--admins_remove["76561197972837186"] = true -- vugi99
--admins_remove[steamid] = true
local constructions = {}
local propcount = {}
local shadows = {}
function rshadow(ply)
if (shadows[ply]) then
DestroyObject(shadows[ply].mapobjid)
shadows[ply] = nil
end
end
AddRemoteEvent("RemoveShadow",rshadow)
function constructshadow(ply, conid)
local x, y, z = GetPlayerLocation(ply)
local identifier = CreateObject(CONSTRUCTION_OBJECTS[conid].ID, x, y, z, 0, 0, 0, CONSTRUCTION_OBJECTS[conid].Scale[1], CONSTRUCTION_OBJECTS[conid].Scale[2], CONSTRUCTION_OBJECTS[conid].Scale[3])
if (identifier ~= false) then
shadows[ply] = {}
shadows[ply].objid = conid
shadows[ply].mapobjid = identifier
-- Set the object as ghosted using package name as a prefix to prevent conflicts with other values. - Credit nexus#4880
SetObjectPropertyValue(identifier, GHOSTED_PROPERTY_NAME, true, true)
SetObjectPropertyValue(identifier, OWNER_PROPERTY_NAME, ply, true)
SetObjectPropertyValue(identifier, CONSTRUCTION_ID_PROPERTY_NAME, conid, true)
else
print("Error at CreateObject Construction mod")
end
end
function upcons(ply, conid)
if (shadows[ply]) then
if (shadows[ply].objid ~= conid) then
DestroyObject(shadows[ply].mapobjid)
shadows[ply] = nil
constructshadow(ply, conid)
end
else
constructshadow(ply, conid)
end
end
AddRemoteEvent("UpdateCons", upcons)
function OnPlayerQuit(ply)
rshadow(ply)
local steamid = tostring(GetPlayerSteamId(ply))
for k, v in pairs(constructions) do
if v.owner == steamid then
RemoveConstruction(ply, k)
end
end
propcount[ply] = nil
end
AddEvent("OnPlayerQuit", OnPlayerQuit)
function OnPlayerJoin(ply)
propcount[ply] = 0
end
AddEvent("OnPlayerJoin", OnPlayerJoin)
function Createobj(ply, x, y, z, pitch, yaw, roll)
if (shadows[ply]) then
if propcount[ply] >= prop_limit then
AddPlayerChat(ply, "Prop limit reached")
return
end
local tbltoinsert = {}
tbltoinsert.mapobjid = shadows[ply].mapobjid
tbltoinsert.objid = shadows[ply].objid
tbltoinsert.owner = tostring(GetPlayerSteamId(ply))
propcount[ply] = propcount[ply] + 1
-- Move the object to the desired position
SetObjectLocation(tbltoinsert.mapobjid, x, y, z)
SetObjectRotation(tbltoinsert.mapobjid, pitch, yaw, roll)
-- Disable ghosting on this object
SetObjectPropertyValue(tbltoinsert.mapobjid, GHOSTED_PROPERTY_NAME, false, true)
if tbltoinsert.objid == 4 then
-- Create a door for the door frame construct.
-- The yaw for the door is rotated 90 degrees.
-- The sin-cos(rad(yaw)) * 507 is to move the door to the correct location relative to the construct
tbltoinsert.door = CreateDoor(3, x - (math.sin(math.rad(yaw - 90)) * 507) + (math.cos(math.rad(yaw - 90))), y + (math.cos(math.rad(yaw - 90)) * 507) + (math.sin(math.rad(yaw - 90))), z - 27, yaw - 90, true)
end
constructions[tbltoinsert.mapobjid] = tbltoinsert
shadows[ply] = nil
end
end
AddRemoteEvent("Createcons", Createobj)
function Removeobj(ply, hitentity)
local steamid = tostring(GetPlayerSteamId(ply))
local v = constructions[hitentity]
if v == nil then
return
end
if v.owner == steamid then
RemoveConstruction(ply, v.mapobjid)
elseif admins_remove[steamid] then
RemoveConstruction(v.owner, v.mapobjid)
else
AddPlayerChat(ply, "You can't remove this object")
end
end
AddRemoteEvent("Removeobj", Removeobj)
function RemoveConstruction(ply, constructionID)
propcount[ply] = propcount[ply] - 1
DestroyObject(constructionID)
if constructions[constructionID].door ~= nil then DestroyDoor(constructions[constructionID].door) end
constructions[constructionID] = nil
end