This repository was archived by the owner on Aug 29, 2023. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathLuaPickup.h
More file actions
287 lines (244 loc) · 5.53 KB
/
Copy pathLuaPickup.h
File metadata and controls
287 lines (244 loc) · 5.53 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#ifndef __LUAPICKUP_H__
#define __LUAPICKUP_H__
struct Pickup
{
int entity;
const int type = 6; // (Types are, Player = 0, Vehicle = 1, Object = 2, NPC = 3, Checkpoint = 4, Blip = 5, Pickup = 6)
Pickup()
{
entity = -1;
}
int Create(lua_State* L)
{
/*
Arg 1: The pointer of the Object
Arg 2+: The arguments entered
*/
const int args = lua_gettop(L);
if (args == 4)
{
Pickup* ent = luabridge::Userdata::get<Pickup>(L, 1, false);
std::string model;
CVector3 poss;
if (lua_isuserdata(L, 2))
{
Vector3* pos = luabridge::Userdata::get<Vector3>(L, 2, false);
poss = { pos->coord[0], pos->coord[1], pos->coord[2] };
pos = nullptr;
}
else if (lua_istable(L, 2))
{
lua_getfield(L, 2, "x");
lua_rawgeti(L, 2, 1);
poss.x = lua_tonumber(L, -2);
lua_pop(L, 1);
lua_getfield(L, 2, "y");
lua_rawgeti(L, 2, 1);
poss.y = lua_tonumber(L, -2);
lua_pop(L, 1);
lua_getfield(L, 2, "z");
lua_rawgeti(L, 2, 1);
poss.z = lua_tonumber(L, -2);
lua_pop(L, 1);
}
ent->entity = API::Pickup::Create(poss, luaL_optstring(L, 3, "prop_ld_health_pack"));
ent = nullptr;
}
else
{
API::Log::Warning("Pickup:Create requires args (position table {x = float, y = float, z = float}, string model).");
}
lua_pop(L, args);
return 0;
}
int Destroy(lua_State* L)
{
const int args = lua_gettop(L);
if (args == 1)
{
Pickup* ent = luabridge::Userdata::get<Pickup>(L, 1, false);
API::Entity::Destroy(ent->entity);
ent->entity = -1;
ent = nullptr;
}
else
{
API::Log::Warning("Pickup:Destroy requires no args.");
}
lua_pop(L, args);
return 0;
}
int ShowToAll(lua_State* L)
{
const int args = lua_gettop(L);
if (args == 1)
{
Pickup* ent = luabridge::Userdata::get<Pickup>(L, 1, false);
API::Pickup::ShowToAll(ent->entity);
ent = nullptr;
}
else
{
API::Log::Warning("Pickup:ShowToAll requires no args.");
}
lua_pop(L, args);
return 0;
}
int Show(lua_State* L);
int HideFromAll(lua_State* L)
{
const int args = lua_gettop(L);
if (args == 1)
{
Pickup* ent = luabridge::Userdata::get<Pickup>(L, 1, false);
API::Pickup::HideFromAll(ent->entity);
ent = nullptr;
}
else
{
API::Log::Warning("Pickup:HideFromAll requires no args.");
}
lua_pop(L, args);
return 0;
}
int Hide(lua_State* L);
int GetPosition(lua_State* L)
{
const int args = lua_gettop(L);
if (args == 1)
{
Pickup* ent = luabridge::Userdata::get<Pickup>(L, 1, false);
lua_pop(L, args);
CVector3 poss = API::Entity::GetPosition(ent->entity);
/*Vec pos(poss.x, poss.y, poss.z);
lua_pushlightuserdata(L, &pos);*/
lua_newtable(L);
lua_pushinteger(L, poss.x);
lua_setfield(L, -2, "x");
lua_pushinteger(L, poss.y);
lua_setfield(L, -2, "y");
lua_pushinteger(L, poss.z);
lua_setfield(L, -2, "z");
ent = nullptr;
}
else
{
lua_pop(L, args);
API::Log::Warning("Pickup:GetPosition requires no args.");
lua_pushnil(L);
}
return 1;
}
int SetPosition(lua_State* L)
{
const int args = lua_gettop(L);
if (args == 2 || args == 4)
{
Pickup* ent = luabridge::Userdata::get<Pickup>(L, 1, false);
CVector3 poss;
if (args == 2)
{
if (lua_isuserdata(L, 2))
{
Vector3* pos = luabridge::Userdata::get<Vector3>(L, 2, false);
poss = { pos->coord[0], pos->coord[1], pos->coord[2] };
pos = nullptr;
}
else if (lua_istable(L, 2))
{
lua_getfield(L, 2, "x");
lua_rawgeti(L, 2, 1);
poss.x = lua_tonumber(L, -2);
lua_pop(L, 1);
lua_getfield(L, 2, "y");
lua_rawgeti(L, 2, 1);
poss.y = lua_tonumber(L, -2);
lua_pop(L, 1);
lua_getfield(L, 2, "z");
lua_rawgeti(L, 2, 1);
poss.z = lua_tonumber(L, -2);
lua_pop(L, 1);
}
}
else
{
poss.x = lua_tonumber(L, 2);
poss.x = lua_tonumber(L, 3);
poss.x = lua_tonumber(L, 4);
}
API::Entity::SetPosition(ent->entity, poss);
ent = nullptr;
}
else
{
API::Log::Warning("Pickup:SetPosition requires args (table{x = float, y = float, z = float}) OR (float x, float y, float z).");
}
lua_pop(L, args);
return 0;
}
int GetModel(lua_State* L)
{
const int args = lua_gettop(L);
if (args == 1)
{
Pickup* ent = luabridge::Userdata::get<Pickup>(L, 1, false);
lua_pushstring(L, API::Pickup::GetModel(ent->entity).c_str());
ent = nullptr;
}
else
{
API::Log::Warning("Pickup:GetModel requires no args.");
}
lua_pop(L, args);
return 0;
}
int SetModel(lua_State* L)
{
const int args = lua_gettop(L);
if (args == 2)
{
Pickup* ent = luabridge::Userdata::get<Pickup>(L, 1, false);
API::Pickup::SetModel(ent->entity, lua_tostring(L, 2));
ent = nullptr;
}
else
{
API::Log::Warning("Pickup:SetModel requires args (string model).");
}
lua_pop(L, args);
return 0;
}
int GetRespawnDelay(lua_State* L)
{
const int args = lua_gettop(L);
if (args == 1)
{
Pickup* ent = luabridge::Userdata::get<Pickup>(L, 1, false);
lua_pushinteger(L, API::Pickup::GetRespawnDelay(ent->entity));
ent = nullptr;
}
else
{
API::Log::Warning("Pickup:GetRespawnDelay requires no args.");
}
lua_pop(L, args);
return 0;
}
int SetRespawnDelay(lua_State* L)
{
const int args = lua_gettop(L);
if (args == 2)
{
Pickup* ent = luabridge::Userdata::get<Pickup>(L, 1, false);
API::Pickup::SetRespawnDelay(ent->entity, lua_tointeger(L, 2));
ent = nullptr;
}
else
{
API::Log::Warning("Pickup:SetRespawnDelay requires args (int time(MS)).");
}
lua_pop(L, args);
return 0;
}
};
#endif