-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathplugin.lua
1692 lines (1438 loc) · 43 KB
/
plugin.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
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local plugin = RegisterPlugin("MakerMod", "2.0")
makermod = {}
makermod.objects = {}
makermod.objects.moving = {} -- for mmove
makermod.objects.attached = {} -- for mattachfx
makermod.players = {}
makermod.cvars = {}
makermod.commands = {}
makermod.timers = {} -- instead of objects.moving and objects.attached
makermod.timerListeners = {}
makermod.cvars['pain_maxdist'] = CreateCvar('makermod_pain_maxdistance', '199', CvarFlags.ARCHIVE)
makermod.cvars['pain_maxdmg'] = CreateCvar('makermod_pain_maxdamage', '100000000', CvarFlags.ARCHIVE)
makermod.cvars['max_arm'] = CreateCvar('makermod_arm_max', '1000', CvarFlags.ARCHIVE)
require(plugin['dirname'] .. '/animation.lua')
require(plugin['dirname'] .. '/toolgun.lua')
local function BlankFunc() end -----fucking lua without 'continue' statement
local function MainLoop()
for id,data in pairs(makermod.players) do
local ply = GetPlayer(id)
if #makermod.players[ply.id]['grabbed'] > 0 then
for k, ent in pairs(makermod.players[ply.id]['grabbed']) do
local temp = JPMath.AngleVectors(ply.angles, true, false, false)
temp = ply.position:MA(makermod.players[ply.id]['arm'], temp)
ent.position = temp
local ang = ply.angles
ang.x = ent.angles.x
ent.angles = ang
end
end
end
for k, v in pairs(makermod.timers) do
if makermod.timerListeners[v.type] then
if makermod.timerListeners[v.type](v) == false then
makermod.timers[k] = nil
end
end
end
end
AddListener('JPLUA_EVENT_RUNFRAME', MainLoop)
-- Registers user
function makermod.RegUser(ply)
if makermod.players[ply.id] then return end
local plyob = {}
-- properties
plyob.selected = nil
plyob.grabbed = {}
plyob.arm = 200
plyob.movetime = 10000
plyob.autograbbing = true
plyob.names = {}
plyob.objects = {}
plyob.password = ''
plyob.mark_position = nil
plyob.marks = {}
plyob.groups = {}
-- commands
plyob.print = function(str)
SendReliableCommand(ply.id, string.format('print "%s\n"', str))
end
makermod.players[ply.id] = plyob
if makermod.toolgun then
makermod.toolgun.setupplayer(ply)
end
end
AddListener('JPLUA_EVENT_CLIENTSPAWN', makermod.RegUser)
-- Adds a loop callback
function makermod.AddTimer(object)
makermod.timers[#makermod.timers + 1] = object
end
-- Removes timers
function makermod.StopAllTimers(ent)
for k, v in pairs(makermod.timers) do
if v.ent == ent then
makermod.timers[k] = nil
end
end
end
function makermod.StopTimersExceptRotate(ent)
for k, v in pairs(makermod.timers) do
if v.type ~= 'rotate' and v.ent == ent then
makermod.timers[k] = nil
end
end
end
-- Adds new command
function makermod.AddCommand(name, func, selectedObj)
if not func then
print('Can\'t find function for command ' .. name .. '.')
return
end
makermod.commands[name] = function(ply, args)
-- lua_reload after player connect
if not makermod.players[ply.id] then
makermod.RegUser(ply)
end
if selectedObj then
local ent = makermod.players[ply.id]['selected']
if not ent then
SendReliableCommand(ply.id, 'print "You have no selected objects.\n"')
return
end
return func(ply, args, makermod.players[ply.id], ent)
end
return func(ply, args, makermod.players[ply.id])
end
AddClientCommand(name, makermod.commands[name])
end
-- Executes command from the player name
function makermod.Exec(command, ply, params)
return makermod.commands[command](ply, params)
end
-- Runs multiple commands from the player name
function makermod.Run(code, ply)
-- preprocessing
local len = string.len(code)
-- add ; at the end of commands
if code.sub(code, len, len) ~= ';' then
code = code .. ';'
len = len + 1
end
-- remove spaces after ;
code = string.gsub(code, '; ', ';')
-- commands parsing
local char
local state = 1 -- 1: read command; 2: read arguments
local currentCommand = ""
local currentCommandId = 1
local currentArguments = {}
local currentArgument = ""
local currentArgumentId = 1
local inQuotes = false
for i=1, len do
char = string.sub(code, i, i)
if char == ' ' then
if state == 1 then
state = 2
elseif inQuotes then
-- read arguments
currentArgument = currentArgument .. " "
else
-- the next argument
currentArguments[currentArgumentId] = currentArgument
currentArgument = ""
currentArgumentId = currentArgumentId + 1
end
elseif char == ';' then
if inQuotes then
currentArgument = currentArgument .. ";"
else
-- the next command
currentArguments[currentArgumentId] = currentArgument
currentArgument = ""
currentArgumentId = 1
if currentCommand == 'wait' then
local delay = currentArguments[1]
local next = string.sub(code, i+1, len)
local data = {}
data['type'] = 'runtimer'
data['start'] = GetRealTime()
data['delay'] = tonumber(delay)
data['code'] = next
data['player'] = ply
makermod.AddTimer(data)
return
else
makermod.Exec(currentCommand, ply, currentArguments)
end
currentCommand = ""
currentCommandId = currentCommandId + 1
currentArguments = {}
state = 1
end
elseif char == "\"" then
if inQuotes == true then
inQuotes = false
else
inQuotes = true
end
else
if state == 1 then
-- read command name
currentCommand = currentCommand .. string.lower(char)
elseif state == 2 then
-- read arguments
currentArgument = currentArgument .. char
end
end
end
end
makermod.timerListeners['runtimer'] = function(object)
if object.start + object.delay <= GetRealTime() then
makermod.Run(object.code, object.player)
return false
end
end
local function StopEntity(ent)
for k, v in pairs(makermod.objects.moving) do
if v.ent == ent then
makermod.objects.moving[k] = nil
end
end
end
local function RemoveEntity(ent)
StopEntity(ent)
for k, v in pairs(makermod.objects.attached) do
if v.ent == ent then
makermod.objects.attached[k] = nil
end
end
makermod.objects[ent.id] = nil
ent:Free()
end
local function ParseVector(vec, args, startfrom)
startfrom = startfrom or 0
for i=1+startfrom, 3+startfrom do
if i==1 then type = 'x' elseif i==2 then type = 'y' elseif i==3 then type='z' end
if args[i] == nil then
return vec
else
res = string.match(args[i], "+(%d+)")
if res then
vec[type] = vec[type] + res
else
res = string.match(args[i], "-(%d+)")
if res then
vec[type] = vec[type] - res
else
res = string.match(args[i], "%d+")
if res then
vec[type] = res
end
end
end
end
end
return vec
end
local function ParseNumber(args, count, startfrom, result)
startfrom = startfrom or 0
result = result or {}
local i
for i=1+startfrom, count+startfrom do
if args[i] == nil then
return vec
else
res = string.match(args[i], "+(%d+)")
if res then
result[i] = vec[type] + res
else
res = string.match(args[i], "-(%d+)")
if res then
result[i] = vec[type] - res
else
res = string.match(args[i], "%d+")
if res then
result[i] = res
end
end
end
end
end
end
local function SetupEntity(ent, ply)
local temp = {}
temp['owner'] = ply
temp['touchfuncs'] = {}
temp['usefuncs'] = {}
temp['connectedTo'] = {}
temp['connectedFrom'] = {}
temp['password'] = ''
temp['name'] = ''
temp['tele_destination'] = nil
local touchfunc = function(ent, from, trace)
for _, r in pairs(temp['touchfuncs']) do ---Check Internal functions
pcall(r, ent, from, trace)
end
for _, r in pairs(temp['connectedTo']) do ---Check Connected Entities
local data = makermod.objects[r]
if not data then
BlankFunc()
else
pcall(data['touchfunc'], ent, from, trace)
end
end
end
local usefunc = function(ent, from, activator)
if (from.player ~= nil ) and (makermod.objects[ent.id]['password'] ~= '') then ---check for password
if makermod.players[from.player.id]['password'] ~= makermod.objects[ent.id]['password'] then return end
end
for _, r in pairs(temp['usefuncs']) do ---Check Internal functions
pcall(r, ent, from, activator)
end
for _, r in pairs(temp['connectedTo']) do ---Check Connected Entities
local data = makermod.objects[r]
if not data then
BlankFunc()
else
pcall(data['usefunc'], ent, from, trace)
end
end
end
temp['touchfunc'] = touchfunc
temp['usefunc'] = usefunc
ent:SetTouchFunction(touchfunc)
ent:SetUseFunction(usefunc)
makermod.objects[ent.id] = temp
end
function TraceEntity(ply, dist)
if not ply then return end
if not dist then dist = 16384 end
local pos = ply.position
pos.z = pos.z + 36.0
local angles = JPMath.AngleVectors(ply.angles,true, false, false)
local endPos = pos:MA(dist, angles)
local mask = Contents.Solid | Contents.Slime | Contents.Lava | Contents.Terrain | Contents.Body | Contents.Item | Contents.Corpse
local trace = RayTrace(pos, 0, endPos, ply.id,mask)
return trace
end
local function CheckEntity(ent, ply)
if not makermod.objects[ent.id] then
-- SetupEntity(ent, 'map_object')
SendReliableCommand(ply.id, string.format('print "You cannot select map object!\n"'))
return false
else
local data = makermod.objects[ent.id]
if data['owner'] ~= plyob then
SendReliableCommand(ply.id, string.format('print "You are not owner of this entity!\n"'))
return false
end
if data['owner'] == 'map_object' then
SendReliableCommand(ply.id, string.format('print "You cannot select map object!\n"'))
return false
end
end
return true
end
local function onUserDisconnect(ply)
for _, ent in pairs(makermod.players[ply.id]['objects']) do
makermod.objects[ent.id] = nil
ent:Free()
end
makermod.players[ply.id] = nil
end
AddListener('JPLUA_EVENT_CLIENTDISCONNECT',onUserDisconnect)
--[[
## Makermod Commands ##
]]--
-- Special objects
local specialObjects = {
stunbaton = 'weapon_stun_baton',
melee = 'weapon_melee',
saber = 'weapon_saber',
blasterpistol = 'weapon_blaster_pistol',
concussionrifle = 'weapon_concussion_rifle',
bryarpistol = 'weapon_bryar_pistol',
blaster = 'weapon_blaster',
disruptor = 'weapon_disruptor',
bowcaster = 'weapon_bowcaster',
repeater = 'weapon_repeater',
demp2 = 'weapon_demp2',
flechette = 'weapon_flechette',
rocket = 'weapon_rocket_launcher',
smallarmor = 'item_shield_sm_instant',
armor = 'item_shield_lrg_instant',
medpak = 'item_medpak_instant',
seeker = 'item_seeker',
shield = 'item_shield',
bacta = 'item_medpac',
bigbacta = 'item_medpac_big',
binoculars = 'item_binoculars',
sentry = 'item_sentry_gun',
jetpack = 'item_jetpack',
healthdisp = 'item_healthdisp',
ammodisp = 'item_ammodisp',
eweb = 'item_eweb_holdable',
cloak = 'item_cloak',
enlightenlight = 'item_force_enlighten_light',
enlightendark = 'item_force_enlighten_dark',
boon = 'item_force_boon',
ysalimari = 'item_ysalimari',
thermal = 'ammo_thermal', -- weapon_thermal ?
tripmine = 'ammo_tripmine', -- weapon_trip_mine ?
detpack = 'ammo_detpack', -- weapon_det_pack ?
force = 'ammo_force',
blasterammo = 'ammo_blaster',
powercell = 'ammo_powercell',
bolts = 'ammo_metallic_bolts',
rockets = 'ammo_rockets',
allammo = 'ammo_all',
redcube = 'item_redcube',
bluecube = 'item_bluecube',
gun = '',
ammounit = '',
shieldunit = '',
turret = '',
miniturret = '',
deathturret = ''
}
-- mplace <foldername/modelname>
-- mplace <modelpath>
-- mplace <special-ob-name> <optional-special-ob-parameters>
local function mPlace(ply, args, plyob)
local model = args[1]
-- wrong syntax
if not model then
plyob.print('Command usage: ^5/mplace <foldername/modelname>\n^7Command usage: ^5/mplace <special-ob-name> <optional-special-ob-parameters>')
return
end
local vars = {}
if specialObjects[model] then
vars['classname'] = specialObjects[model]
else
-- factory/catw2_b instead of models/map_objects/factory/catw2_b.md3
if not string.match(model, 'models/map_objects') then
model = 'models/map_objects/' .. model .. '.md3'
end
-- making an entity
vars['classname'] = 'misc_model'
vars['model'] = model
end
local ent = CreateEntity(vars)
SetupEntity(ent)
-- setting position
if plyob['autograbbing'] then
plyob['grabbed'][#plyob['grabbed'] + 1] = ent
plyob.print(string.format('Object grabbed:%d. Use /mgrabbing to turn off auto-grabbing.', ent.id))
else
if plyob['mark_position'] then
-- player has mmark
ent.position = plyob['mark_position']
else
-- player hasn't mmark
ent.position = ply.position:MA(plyob['arm'], JPMath.AngleVectors(ply.angles, true, false, false))
end
plyob.print( string.format("Object placed:%d Origin: (%d %d %d)", ent.id, math.floor(ent.position.x), math.floor(ent.position.y), math.floor(ent.position.z)) )
end
plyob['selected'] = ent
plyob['objects'][#plyob['objects'] + 1] = ent
end
-- mplacefx <effectname>
-- mplacefx <effectname> <delay>
-- mplacefx <effectname> <delay> <random-component>
local function mPlaceFX(ply, args, plyob)
local fx = args[1]
-- wrong syntax
if not fx then
plyob.print('Command usage: ^5/mplacefx <effectname> <delay-between-firings-in-milliseconds> <optional-random-delay-component-in-ms>\n^71 second is 1000 milliseconds')
return
end
-- making an entity
local vars = {}
vars['classname'] = 'fx_runner'
vars['fxFile'] = fx
-- delay
if args[2] then
vars['delay'] = tonumber(args[2])
if args[3] then
vars['random'] = tonumber(args[3])
end
end
local ent = CreateEntity(vars)
SetupEntity(ent)
-- setting position
if plyob['autograbbing'] then
plyob['grabbed'][#plyob['grabbed'] + 1] = ent
plyob.print(string.format('Effect grabbed:%d. Use /mgrabbing to turn off auto-grabbing.', ent.id))
else
if plyob['mark_position'] then
-- player has mmark
ent.position = plyob['mark_position']
else
-- player hasn't mmark
ent.position = ply.position:MA(plyob['arm'], JPMath.AngleVectors(ply.angles, true, false, false))
end
plyob.print( string.format('Effect placed:%d Origin: (%d %d %d)', ent.id, math.floor(ent.position.x), math.floor(ent.position.y), math.floor(ent.position.z)) )
end
plyob['selected'] = ent
plyob['objects'][#plyob['objects'] + 1] = ent
end
function mKill(ply, args, plyob)
local mode = args[1]
if mode == 'in' then
local ent = plyob['selected']
if not ent then return end
local data = {}
data.type = 'killin'
data.ent = ent
data.start = GetRealTime()
data.time = tonumber(args[2])
if args[2] == nil then data.time = 1 end
makermod.AddTimer(data)
elseif mode == 'trace' then
-- mkill trace
local trace = TraceEntity(ply, nil)
if trace.entityNum > 0 then
local ent = GetEntity(trace.entityNum)
if not ent then return end
if CheckEntity(ent, ply) then
for i=0, #GetPlayers() do
if makermod.players[ply.id]['selected'] == ent then
makermod.players[ply.id]['selected'] = nil
end
if makermod.players[ply.id]['grabbed'] == ent then
makermod.players[ply.id]['grabbed'] = {}
end
end
RemoveEntity(ent)
return
end
end
elseif mode == 'all' then
-- mkill all
makermod.players[ply.id]['selected'] = nil
makermod.players[ply.id]['grabbed'] = {}
for _, ent in pairs(makermod.players[ply.id]['objects']) do
if ent then
makermod.StopAllTimers(ent)
RemoveEntity(ent)
end
end
makermod.players[ply.id]['objects'] = {}
elseif mode and string.sub(mode, 0, 1) == '#' then
-- mkill #id
mode = string.sub(mode, 2)
local ent = plyob.names[mode]
if not ent then return end
for k, v in pairs(makermod.players[ply.id]['objects']) do
if ent and v == ent then
makermod.players[ply.id]['objects'][k] = nil
end
end
for k, v in pairs(makermod.players[ply.id]['grabbed']) do
if v == ent then
makermod.players[ply.id]['grabbed'][k] = nil
end
end
makermod.players[ply.id]['selected'] = nil
makermod.StopAllTimers(ent)
RemoveEntity(ent)
-- todo: remove ob from names
else
local ent = plyob['selected']
if not ent then return end
for k, v in pairs(makermod.players[ply.id]['objects']) do
if ent and v == ent then
makermod.players[ply.id]['objects'][k] = nil
end
end
for k, v in pairs(makermod.players[ply.id]['grabbed']) do
if v == ent then
makermod.players[ply.id]['grabbed'][k] = nil
end
end
makermod.players[ply.id]['selected'] = nil
makermod.StopAllTimers(ent)
RemoveEntity(ent)
end
end
-- kill in listener
makermod.timerListeners['killin'] = function(object)
if object.start + object.time < GetRealTime() then
RemoveEntity(object.ent)
return false
end
end
local function mMoveTime(ply, args, plyob)
if #args < 1 then
plyob.print(string.format("Your mmove time: %d ms (%d s)", makermod.players[ply.id]['movetime'], makermod.players[ply.id]['movetime'] / 1000))
return
end
local time = tonumber(args[1])
if time then
plyob['movetime'] = time
else
plyob.print("Wrong number!")
end
end
local function mMove(ply, args, plyob, ent)
-- wrong syntax
if #args < 1 then
plyob.print("Command usage: ^5/mmove <speed>\n^7Command usage: ^5/mmove <x> <y> <z>\n^7Command usage: ^5/mmove <x> <y> <z> <duration> <easing>\n^7Type /mmove list for easing list.")
return
end
-- easing functions list
if args[1] == 'list' then
-- todo: minfo easing
plyob.print(easinglist)
return
end
-- removing any timers
makermod.StopTimersExceptRotate(ent)
-- removing a grabbing
for k, v in pairs(plyob['grabbed']) do
if v == ent then
plyob['grabbed'][k] = nil
end
end
-- parsing the args:
-- mmove speed
-- mmove speed dur
-- mmove speed dur easing
-- mmove speed easing
-- mmove x y z
-- mmove x y z dur
-- mmove x y z dur easing
-- mmove x y z easing
local dest = Vector3(0, 0, 0)
local dur = plyob['movetime']
local ease = 'linear'
if #args == 1 or #args == 2 or (#args == 3 and makermod.easing[args[3]]) then
-- move in eye direction
local ma = JPMath.AngleVectors(ply.angles, true, false, false)
dest = ply.position:MA(tonumber(args[1]), ma)
dest = dest - ply.position
if #args > 1 then
if #args == 2 then
if makermod.easing[args[2]] then
-- mmove <speed> <easing>
ease = args[2]
else
-- mmove <speed> <duration>
dur = args[2]
end
else
-- mmove <speed> <duration>
dur = args[2]
ease = args[3]
end
end
else
-- move by (x y z)
dest = ParseVector(Vector3(0, 0, 0), args, 0) * 10
-- dest.x = tonumber(args[1]) * 10
-- dest.y = tonumber(args[2]) * 10
-- dest.z = tonumber(args[3]) * 10
if #args > 3 then
if #args == 4 then
if makermod.easing[args[4]] then
-- mmove <x> <y> <z> <easing>
ease = args[4]
else
-- mmove <x> <y> <z> <duration>
dur = args[4]
end
else
-- mmove <x> <y> <z> <duration> <easing>
dur = args[4]
ease = args[5]
end
end
end
if dest == Vector3(0, 0, 0) then return end
dur = tonumber(dur)
-- moving
if dur == 0 then
ent.position = ent.position + dest
else
-- animation
local data = {}
data.type = 'move'
data.ent = ent
data.start = GetRealTime()
data.coords = dest
data.pos = ent.position
data.ease = ease
data.dur = dur
makermod.AddTimer(data)
end
end
local function mRotate(ply, args, plyob, ent)
-- wrong syntax
if #args < 1 then
plyob.print("Command usage: ^5/mrotate <x> <y> <z>\n^7Command usage: ^5/mrotate <x> <y> <z> <duration> <easing>\n^7Type /mmove list for easing list.")
return
end
-- stopping the current rotating
for k, v in pairs(makermod.timers) do
if v.ent == ent and v.type == 'rotate' then
ent.angles = v.from
makermod.timers[k] = nil
break
end
end
if args[1] == "clear" then
ent.angles = Vector3(0, 0, 0)
return
end
-- parsing the args:
-- mrotate x y z
-- mrotate x y z dur
-- mrotate x y z dur easing
-- mrotate x y z easing
local angle = Vector3(tonumber(args[1]), tonumber(args[2]), tonumber(args[3]))
local dur = plyob['movetime']
local ease = 'linear'
if #args > 3 then
if #args == 4 then
if makermod.easing[args[4]] then
-- mrotate <x> <y> <z> <easing>
ease = args[4]
else
-- mrotate <x> <y> <z> <duration>
dur = args[4]
end
else
-- mrotate <x> <y> <z> <duration> <easing>
dur = args[4]
ease = args[5]
end
end
if angle == Vector3(0, 0, 0) then return end
dur = tonumber(dur)
-- moving
if dur == 0 then
ent.angles = ent.angles + angle
else
-- animation
local data = {}
data.type = 'rotate'
data.ent = ent
data.start = GetRealTime()
data.angle = angle
data.from = ent.angles
data.ease = ease
data.dur = dur
makermod.AddTimer(data)
end
end
function mConnectTo(ply, args)
if not makermod.players[ply.id]['selected'] then return end
local trace = TraceEntity(ply, nil)
if trace.entityNum >= 0 then
local ent = GetEntity(trace.entityNum)
if not CheckEntity(ent, ply) then return end
local data1 = makermod.objects[makermod.players[ply.id]['selected'].id]
local data2 = makermod.objects[ent.id]
data1['connectedTo'][#data1['connectedTo']+1] = ent
data2['connectedFrom'][#data2['connectedFrom']+1] = makermod.players[ply.id]['selected']
else
SendReliableCommand(ply.id, string.format('print "0 entity traced\n"'))
return
end
end
function mTouchable(ply, args)
if not makermod.players[ply.id]['selected'] then return end
makermod.players[ply.id]['selected'].touchable = true
end
function mUsable(ply, args)
if not makermod.players[ply.id]['selected'] then return end
makermod.players[ply.id]['selected'].usable = true
end
local function mPrintsw(ply, args)
if not makermod.players[ply.id]['selected'] then return end
local text = args[1]
local ent = makermod.players[ply.id]['selected']
if ent.touchable or ent.usable then
local printfunc = function(a,b,c)
if b ~= nil and b.player ~= nil then
SendReliableCommand(b.player.id, string.format('cp "%s" ', text))
end
end
if ent.touchable then
makermod.objects[ent.id]['touchfuncs'][#makermod.objects[ent.id]['touchfuncs'] + 1] = printfunc
end
if ent.usable then
makermod.objects[ent.id]['usefuncs'][#makermod.objects[ent.id]['usefuncs'] + 1] = printfunc
end
end
end
local function mTelesw(ply, args)
if not makermod.players[ply.id]['selected'] then return end
local data = makermod.objects[makermod.players[ply.id]['selected'].id]
local ent = makermod.players[ply.id]['selected']
local func = function(a,b,c)
if not b then return end
if b.player then
if not data['tele_destination'] then
data['tele_destination'] = Vector3(tonumber(args[1]), tonumber(args[2]), tonumber(args[3]))
end
b.player:Teleport(data['tele_destination'], b.player.angles)
else
b.position = data['tele_destination'] --TODO: Entity Teleporting?
end
end
if ent.touchable then
makermod.objects[ent.id]['touchfuncs'][#makermod.objects[ent.id]['touchfuncs'] + 1] = func
end
if ent.usable then
makermod.objects[ent.id]['usefuncs'][#makermod.objects[ent.id]['usefuncs'] + 1] = func
end
end
function mDest(ply, args)
if not makermod.players[ply.id]['selected'] then return end
if #args >= 1 then
if args[1] == 'trace' then
local trace = TraceEntity(ply, nil)
makermod.objects[makermod.players[ply.id]['selected'].id]['tele_destination'] = Vector3(trace.endpos.x, trace.endpos.y, trace.endpos.z)
else
--makermod.objects[makermod.players[ply.id]['selected'].id]['tele_destination'] = ParseVector(ply.position, args, 0)
makermod.objects[makermod.players[ply.id]['selected'].id]['tele_destination'] = Vector3(tonumber(args[1]), tonumber(args[2]), tonumber(args[3]))
end
else
makermod.objects[makermod.players[ply.id]['selected'].id]['tele_destination'] = ParseVector(ply.position, args)
end
end
local function mArm(ply, args, plyob)
if #args < 1 then
plyob.print("Marm: " .. plyob['arm'])
return
end
plyob['arm'] = tonumber(args[1]) --ParseNumber(args, 1, 0,{makermod.players[ply.id]['arm']})[1]
end
local function mGrabbing(ply, args, plyob)
local state
if args[1] then
if args[1] == 'off' then
state = true
else
state = false
end
else
state = plyob['autograbbing']
end
if state then
plyob['autograbbing'] = false
plyob.print("Automatic Grabbing OFF.")
else
plyob['autograbbing'] = true
plyob.print("Automatic Grabbing ON.")
end
end
function mSelect(ply, args, plyob)
if #args == 1 then
if not plyob.names[args[1]] then
plyob.print("There is no object.")
return
end
plyob['selected'] = plyob.names[args[1]]
plyob.print("Entity selected: " .. plyob['selected'].id)
else
local trace = TraceEntity(ply, nil)
if trace.entityNum >= 0 then
local ent = GetEntity(trace.entityNum)
if not ent then return end
if not CheckEntity(ent, ply) then
return
end
plyob['selected'] = ent
plyob.print("Entity selected: " .. ent.id)
end
end
end
function mDrop(ply, args)
if args[1] == 'all' then
makermod.players[ply.id]['grabbed'] = {}
return
end
for k, v in pairs(makermod.players[ply.id]['grabbed']) do
if v == makermod.players[ply.id]['selected'] then
makermod.players[ply.id]['grabbed'][k] = nil
end