-
Notifications
You must be signed in to change notification settings - Fork 3
/
init.lua
921 lines (755 loc) · 28.7 KB
/
init.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
local modpath = minetest.get_modpath(minetest.get_current_modname())
if minetest.global_exists("armor") and armor.attributes then
table.insert(armor.attributes, "bullet_res")
end
if minetest.global_exists("armor") and armor.attributes then
table.insert(armor.attributes, "ammo_save")
end
if minetest.global_exists("armor") and armor.attributes then
table.insert(armor.attributes, "ranged_dmg")
end
minetest.register_node("rangedweapons:antigun_block", {
description = "" ..core.colorize("#35cdff","Anti-gun block\n")..core.colorize("#FFFFFF", "Prevents people from using guns, in 10 node radius to each side from this block"),
tiles = {"rangedweapons_antigun_block.png"},
groups = {choppy = 3, oddly_breakable_by_hand = 3},
sounds = default.node_sound_wood_defaults(),
})
----
---- gun_funcs
----
local function update_ammo_counter_on_gun(gunMeta)
gunMeta:set_string("count_meta", tostring(gunMeta:get_int("RW_bullets")))
end
make_sparks = function(pos)
minetest.sound_play("rengedweapons_ricochet", {pos = pos, gain = 0.75})
for i=1,9 do
minetest.add_particle({
pos = pos,
velocity = {x=math.random(-6.0,6.0), y=math.random(-10.0,15.0), z=math.random(-6.0,6.0)},
acceleration = {x=math.random(-9.0,9.0), y=math.random(-15.0,-3.0), z=math.random(-9.0,9.0)},
expirationtime = 1.0,
size = math.random(1,2),
collisiondetection = true,
vertical = false,
texture = "rangedweapons_spark.png",
glow = 25,
})
end
end
local max_gun_efficiency = tonumber(minetest.settings:get("rangedweapons_max_gun_efficiency")) or 300
rangedweapons_gain_skill = function(player,skill,chance)
if math.random(1, chance) == 1 then
local p_meta = player:get_meta()
local skill_num = p_meta:get_int(skill)
if skill_num < max_gun_efficiency then
p_meta:set_int(skill, skill_num + 1)
minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#25c200","You've improved your skill with this type of gun!"))
end
end
end
rangedweapons_reload_gun = function(itemstack, player)
local GunCaps = itemstack:get_definition().RW_gun_capabilities
local gun_unload_sound = ""
if GunCaps ~= nil then
gun_unload_sound = GunCaps.gun_unload_sound or ""
end
minetest.sound_play(gun_unload_sound, {pos = player:get_pos()})
local gun_reload = 0.25
if GunCaps ~= nil then
gun_reload = GunCaps.gun_reload or 0.25
end
local playerMeta = player:get_meta()
local gunMeta = itemstack:get_meta()
gunMeta:set_float("RW_reload_delay",gun_reload)
playerMeta:set_float("rw_cooldown",gun_reload)
local player_has_ammo = 0
local clipSize = 0
local reload_ammo = ""
if GunCaps.suitable_ammo ~= nil then
local inv = player:get_inventory()
for i = 1,inv:get_size("main") do
for _, ammo in pairs(GunCaps.suitable_ammo) do
if inv:get_stack("main",i):get_name() == ammo[1] then
reload_ammo = inv:get_stack("main",i)
clipSize = ammo[2]
player_has_ammo = 1
break
end end
if player_has_ammo == 1 then
break
end
end end
if player_has_ammo == 1 then
local gunMeta = itemstack:get_meta()
local ammoCount = gunMeta:get_int("RW_bullets")
local ammoName = gunMeta:get_string("RW_ammo_name")
local inv = player:get_inventory()
if minetest.settings:get_bool("rangedweapons_infinite_ammo", false) then
gunMeta:set_int("RW_bullets",clipSize)
else
inv:add_item("main",ammoName.." "..ammoCount)
if inv:contains_item("main",reload_ammo:get_name().." "..clipSize) then
inv:remove_item("main",reload_ammo:get_name().." "..clipSize)
gunMeta:set_int("RW_bullets",clipSize)
else
gunMeta:set_int("RW_bullets",reload_ammo:get_count())
inv:remove_item("main",reload_ammo:get_name().." "..reload_ammo:get_count())
end
end
gunMeta:set_string("RW_ammo_name",reload_ammo:get_name())
update_ammo_counter_on_gun(gunMeta)
if GunCaps.gun_magazine ~= nil then
local pos = player:get_pos()
local dir = player:get_look_dir()
local yaw = player:get_look_horizontal()
if pos and dir and yaw then
pos.y = pos.y + 1.4
local obj = minetest.add_entity(pos,"rangedweapons:mag")
if obj then
obj:set_properties({textures = {GunCaps.gun_magazine}})
obj:set_velocity({x=dir.x*2, y=dir.y*2, z=dir.z*2})
obj:set_acceleration({x=0, y=-5, z=0})
obj:set_rotation({x=0,y=yaw - math.pi/2,z=0})
end end end
if GunCaps.gun_unloaded ~= nil then
itemstack:set_name(GunCaps.gun_unloaded)
end
end
end
rangedweapons_single_load_gun = function(itemstack, player)
local GunCaps = itemstack:get_definition().RW_gun_capabilities
if GunCaps ~= nil then
gun_unload_sound = GunCaps.gun_unload_sound or ""
end
minetest.sound_play(gun_unload_sound, {pos = player:get_pos()})
local gun_reload = 0.25
if GunCaps ~= nil then
gun_reload = GunCaps.gun_reload or 0.25
end
local playerMeta = player:get_meta()
local gunMeta = itemstack:get_meta()
gunMeta:set_float("RW_reload_delay",gun_reload)
playerMeta:set_float("rw_cooldown",gun_reload)
local player_has_ammo = 0
local clipSize = 0
local reload_ammo = ""
if GunCaps.suitable_ammo ~= nil then
local inv = player:get_inventory()
for i = 1,inv:get_size("main") do
for _, ammo in pairs(GunCaps.suitable_ammo) do
if inv:get_stack("main",i):get_name() == ammo[1] then
reload_ammo = inv:get_stack("main",i)
clipSize = ammo[2]
player_has_ammo = 1
break
end end
if player_has_ammo == 1 then
break
end
end end
if player_has_ammo == 1 then
local gunMeta = itemstack:get_meta()
local ammoCount = gunMeta:get_int("RW_bullets")
local ammoName = gunMeta:get_string("RW_ammo_name")
local inv = player:get_inventory()
if ammoName ~= reload_ammo:get_name() then
inv:add_item("main",ammoName.." "..ammoCount)
gunMeta:set_int("RW_bullets",0)
end
if inv:contains_item("main",reload_ammo:get_name()) and
gunMeta:get_int("RW_bullets") < clipSize then
if not minetest.settings:get_bool("rangedweapons_infinite_ammo", false) then
inv:remove_item("main",reload_ammo:get_name())
end
gunMeta:set_int("RW_bullets",gunMeta:get_int("RW_bullets")+1)
end
gunMeta:set_string("RW_ammo_name",reload_ammo:get_name())
update_ammo_counter_on_gun(gunMeta)
if GunCaps.gun_unloaded ~= nil then
itemstack:set_name(GunCaps.gun_unloaded)
end
end
end
rangedweapons_yeet = function(itemstack, player)
if minetest.find_node_near(player:get_pos(), 10,"rangedweapons:antigun_block")
then
minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000","throwable weapons are prohibited in this area!"))
else
local ThrowCaps = itemstack:get_definition().RW_throw_capabilities
local playerMeta = player:get_meta()
local throw_cooldown = 0
if ThrowCaps ~= nil then
throw_cooldown = ThrowCaps.throw_cooldown or 0
end
if playerMeta:get_float("rw_cooldown") <= 0 then
playerMeta:set_float("rw_cooldown", throw_cooldown)
local throw_damage = {fleshy=1}
local throw_sound = "rangedweapons_throw"
local throw_velocity = 20
local throw_accuracy = 100
local throw_cooling = 0
local throw_crit = 0
local throw_critEffc = 1
local throw_mobPen = 0
local throw_nodePen = 0
local throw_dps = 0
local throw_gravity = 0
local throw_door_breaking = 0
local throw_skill = ""
local throw_skillChance = 0
local throw_smokeSize = 0
local throw_ent = "rangedweapons:shot_bullet"
local throw_visual = "wielditem"
local throw_texture = "rangedweapons:shot_bullet_visual"
local throw_glass_breaking = 0
local throw_particles = {}
local throw_sparks = 0
local throw_bomb_ignite = 0
local throw_size = 0
local throw_glow = 0
local OnCollision = function()end
if ThrowCaps ~= nil then
throw_damage = ThrowCaps.throw_damage or {fleshy=1}
throw_sound = ThrowCaps.throw_sound or "rangedweapons_glock"
throw_velocity = ThrowCaps.throw_velocity or 20
throw_accuracy = ThrowCaps.throw_accuracy or 100
throw_cooling = ThrowCaps.throw_cooling or itemstack:get_name()
throw_crit = ThrowCaps.throw_crit or 0
throw_critEffc = ThrowCaps.throw_critEffc or 1
throw_projectiles = ThrowCaps.throw_projectiles or 1
throw_mobPen = ThrowCaps.throw_mob_penetration or 0
throw_nodePen = ThrowCaps.throw_node_penetration or 0
throw_dps = ThrowCaps.throw_dps or 0
throw_gravity = ThrowCaps.throw_gravity or 0
throw_door_breaking = ThrowCaps.throw_door_breaking or 0
throw_ent = ThrowCaps.throw_entity or "rangedweapons:shot_bullet"
throw_visual = ThrowCaps.throw_visual or "wielditem"
throw_texture = ThrowCaps.throw_texture or "rangedweapons:shot_bullet_visual"
throw_glass_breaking = ThrowCaps.throw_glass_breaking or 0
throw_particles = ThrowCaps.throw_particles or nil
throw_sparks = ThrowCaps.throw_sparks or 0
throw_bomb_ignite = ThrowCaps.ignites_explosives or 0
throw_size = ThrowCaps.throw_projectile_size or 0
throw_glow = ThrowCaps.throw_projectile_glow or 0
OnCollision = ThrowCaps.OnCollision or function()end
if ThrowCaps.throw_skill ~= nil then
throw_skill = ThrowCaps.throw_skill[1] or ""
throw_skillChance = ThrowCaps.throw_skill[2] or 0
else
throw_skill = ""
throw_skillChance = 0
end
end
if throw_skillChance > 0 and throw_skill ~= "" then
rangedweapons_gain_skill(player,throw_skill,throw_skillChance)
end
local skill_value = 1
if throw_skill ~= "" then
skill_value = playerMeta:get_int(throw_skill)/100
end
rangedweapons_launch_projectile(player,throw_projectiles,throw_damage,throw_ent,throw_visual,throw_texture,throw_sound,throw_velocity,throw_accuracy,skill_value,OnCollision,throw_crit,throw_critEffc,throw_mobPen,throw_nodePen,0,"","","",throw_dps,throw_gravity,throw_door_breaking,throw_glass_breaking,throw_particles,throw_sparks,throw_bomb_ignite,throw_size,0,itemstack:get_wear(),throw_glow)
itemstack:take_item()
end
end
end
rangedweapons_shoot_gun = function(itemstack, player)
if minetest.find_node_near(player:get_pos(), 10,"rangedweapons:antigun_block")
then
minetest.sound_play("rangedweapons_empty", {pos = player:get_pos()})
minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000","Guns are prohibited in this area!"))
else
local gun_cooldown = 0
local GunCaps = itemstack:get_definition().RW_gun_capabilities
local gun_ammo_save = 0
if GunCaps ~= nil then
gun_cooldown = GunCaps.gun_cooldown or 0
gun_ammo_save = GunCaps.ammo_saving or 0
end
local gunMeta = itemstack:get_meta()
local playerMeta = player:get_meta()
if gunMeta:get_int("RW_bullets") > 0 and
playerMeta:get_float("rw_cooldown") <= 0 then
playerMeta:set_float("rw_cooldown", gun_cooldown)
if math.random(1,100) > gun_ammo_save then
gunMeta:set_int("RW_bullets",gunMeta:get_int("RW_bullets")-1)
end
update_ammo_counter_on_gun(gunMeta)
local OnCollision = function() end
local bulletStack = ItemStack({name = gunMeta:get_string("RW_ammo_name")})
local AmmoCaps = bulletStack:get_definition().RW_ammo_capabilities
local gun_damage = {fleshy=1}
local gun_sound = "rangedweapons_glock"
local gun_velocity = 20
local gun_accuracy = 100
local gun_cooling = 0
local gun_crit = 0
local gun_critEffc = 1
local gun_projectiles = 1
local gun_mobPen = 0
local gun_nodePen = 0
local gun_shell = 0
local gun_durability = 0
local gun_dps = 0
local gun_gravity = 0
local gun_door_breaking = 0
local gun_skill = ""
local gun_skillChance = 0
local gun_smokeSize = 0
local bullet_damage = {fleshy=0}
local bullet_velocity = 0
local bullet_ent = "rangedweapons:shot_bullet"
local bullet_visual = "wielditem"
local bullet_texture = "rangedweapons:shot_bullet_visual"
local bullet_crit = 0
local bullet_critEffc = 0
local bullet_projMult = 1
local bullet_mobPen = 0
local bullet_nodePen = 0
local bullet_shell_ent = "rangedweapons:empty_shell"
local bullet_shell_visual = "wielditem"
local bullet_shell_texture = "rangedweapons:shelldrop"
local bullet_dps = 0
local bullet_gravity = 0
local bullet_glass_breaking = 0
local bullet_particles = {}
local bullet_sparks = 0
local bullet_bomb_ignite = 0
local bullet_size = 0
local bullet_glow = 20
if GunCaps ~= nil then
gun_damage = GunCaps.gun_damage or {fleshy=1}
gun_sound = GunCaps.gun_sound or "rangedweapons_glock"
gun_velocity = GunCaps.gun_velocity or 20
gun_accuracy = GunCaps.gun_accuracy or 100
gun_cooling = GunCaps.gun_cooling or itemstack:get_name()
gun_crit = GunCaps.gun_crit or 0
gun_critEffc = GunCaps.gun_critEffc or 1
gun_projectiles = GunCaps.gun_projectiles or 1
gun_mobPen = GunCaps.gun_mob_penetration or 0
gun_nodePen = GunCaps.gun_node_penetration or 0
gun_shell = GunCaps.has_shell or 0
gun_durability = GunCaps.gun_durability or 0
gun_dps = GunCaps.gun_dps or 0
gun_ammo_save = GunCaps.ammo_saving or 0
gun_gravity = GunCaps.gun_gravity or 0
gun_door_breaking = GunCaps.gun_door_breaking or 0
gun_smokeSize = GunCaps.gun_smokeSize or 0
if GunCaps.gun_skill ~= nil then
gun_skill = GunCaps.gun_skill[1] or ""
gun_skillChance = GunCaps.gun_skill[2] or 0
else
gun_skill = ""
gun_skillChance = 0
end
end
if gun_skillChance > 0 and gun_skill ~= "" then
rangedweapons_gain_skill(player,gun_skill,gun_skillChance)
end
if AmmoCaps ~= nil then
OnCollision = AmmoCaps.OnCollision or function()end
bullet_damage = AmmoCaps.ammo_damage or {fleshy=1}
bullet_velocity = AmmoCaps.ammo_velocity or 0
bullet_ent = AmmoCaps.ammo_entity or "rangedweapons:shot_bullet"
bullet_visual = AmmoCaps.ammo_visual or "wielditem"
bullet_texture = AmmoCaps.ammo_texture or "rangedweapons:shot_bullet_visual"
bullet_crit = AmmoCaps.ammo_crit or 0
bullet_critEffc = AmmoCaps.ammo_critEffc or 0
bullet_projMult = AmmoCaps.ammo_projectile_multiplier or 1
bullet_mobPen = AmmoCaps.ammo_mob_penetration or 0
bullet_nodePen = AmmoCaps.ammo_node_penetration or 0
bullet_shell_ent = AmmoCaps.shell_entity or "rangedweapons:empty_shell"
bullet_shell_visual = AmmoCaps.shell_visual or "wielditem"
bullet_shell_texture = AmmoCaps.shell_texture or "rangedweapons:shelldrop"
bullet_dps = AmmoCaps.ammo_dps or 0
bullet_gravity = AmmoCaps.ammo_gravity or 0
bullet_glass_breaking = AmmoCaps.ammo_glass_breaking or 0
bullet_particles = AmmoCaps.ammo_particles or nil
bullet_sparks = AmmoCaps.has_sparks or 0
bullet_bomb_ignite = AmmoCaps.ignites_explosives or 0
bullet_size = AmmoCaps.ammo_projectile_size or 0.0025
bullet_glow = AmmoCaps.ammo_projectile_glow or 20
end
local combined_crit = gun_crit + bullet_crit
local combined_critEffc = gun_critEffc + bullet_critEffc
local combined_velocity = gun_velocity + bullet_velocity
local combined_projNum = math.ceil(gun_projectiles * bullet_projMult)
local combined_mobPen = gun_mobPen + bullet_mobPen
local combined_nodePen = gun_nodePen + bullet_nodePen
local combined_dps = gun_dps + bullet_dps
local combined_dmg = {}
local combined_gravity = gun_gravity + bullet_gravity
for _, gunDmg in pairs(gun_damage) do
if bullet_damage[_] ~= nil then
combined_dmg[_] = gun_damage[_] + bullet_damage[_]
else
combined_dmg[_] = gun_damage[_]
end
end
for _, bulletDmg in pairs(bullet_damage) do
if gun_damage[_] == nil then
combined_dmg[_] = bullet_damage[_]
end
end
--minetest.chat_send_all(minetest.serialize(combined_dmg))
local skill_value = 1
if gun_skill ~= "" then
skill_value = playerMeta:get_int(gun_skill)/100
end
rangedweapons_launch_projectile(player,combined_projNum,combined_dmg,bullet_ent,bullet_visual,bullet_texture,gun_sound,combined_velocity,gun_accuracy,skill_value,OnCollision,combined_crit,combined_critEffc,combined_mobPen,combined_nodePen,gun_shell,bullet_shell_ent,bullet_shell_texture,bullet_shell_visual,combined_dps,combined_gravity,gun_door_breaking,bullet_glass_breaking,bullet_particles,bullet_sparks,bullet_bomb_ignite,bullet_size,gun_smokeSize,0,bullet_glow)
if minetest.settings:get_bool("rangedweapons_gun_wear", true) then
itemstack:add_wear(65535/gun_durability)
end
itemstack:set_name(gun_cooling)
end
end end
rangedweapons_shoot_powergun = function(itemstack, player)
if minetest.find_node_near(player:get_pos(), 10,"rangedweapons:antigun_block")
then
minetest.sound_play("rangedweapons_empty", {pos = player:get_pos()})
minetest.chat_send_player(player:get_player_name(), "" ..core.colorize("#ff0000","Guns are prohibited in this area!"))
else
local power_cooldown = 0
local power_consumption = 0
local PowerCaps = itemstack:get_definition().RW_powergun_capabilities
if PowerCaps ~= nil then
power_cooldown = PowerCaps.power_cooldown or 0
power_consumption = PowerCaps.power_consumption or 0
end
local inv = player:get_inventory()
local playerMeta = player:get_meta()
if inv:contains_item("main", "rangedweapons:power_particle "..PowerCaps.power_consumption) and
playerMeta:get_float("rw_cooldown") <= 0 then
playerMeta:set_float("rw_cooldown", power_cooldown)
local OnCollision = function() end
local power_damage = {fleshy=1}
local power_sound = "rangedweapons_laser"
local power_velocity = 20
local power_accuracy = 100
local power_cooling = 0
local power_crit = 0
local power_critEffc = 1
local power_mobPen = 0
local power_nodePen = 0
local power_durability = 0
local power_dps = 0
local power_gravity = 0
local power_door_breaking = 0
local power_skill = ""
local power_skillChance = 0
local power_ent = "rangedweapons:shot_bullet"
local power_visual = "wielditem"
local power_texture = "rangedweapons:shot_bullet_visual"
local power_glass_breaking = 0
local power_particles = {}
local power_sparks = 0
local power_bomb_ignite = 0
local power_size = 0
local power_glow = 20
local power_projectiles = 1
if PowerCaps ~= nil then
power_damage = PowerCaps.power_damage or {fleshy=1}
power_sound = PowerCaps.power_sound or "rangedweapons_glock"
power_velocity = PowerCaps.power_velocity or 20
power_accuracy = PowerCaps.power_accuracy or 100
power_cooling = PowerCaps.power_cooling or itemstack:get_name()
power_crit = PowerCaps.power_crit or 0
power_critEffc = PowerCaps.power_critEffc or 1
power_projectiles = PowerCaps.power_projectiles or 1
power_mobPen = PowerCaps.power_mob_penetration or 0
power_nodePen = PowerCaps.power_node_penetration or 0
power_durability = PowerCaps.power_durability or 0
power_dps = PowerCaps.power_dps or 0
power_gravity = PowerCaps.power_gravity or 0
power_door_breaking = PowerCaps.power_door_breaking or 0
OnCollision = PowerCaps.OnCollision or function()end
power_ent = PowerCaps.power_entity or "rangedweapons:shot_bullet"
power_visual = PowerCaps.power_visual or "wielditem"
power_texture = PowerCaps.power_texture or "rangedweapons:shot_bullet_visual"
power_glass_breaking = PowerCaps.power_glass_breaking or 0
power_particles = PowerCaps.power_particles or nil
power_sparks = PowerCaps.has_sparks or 0
power_bomb_ignite = PowerCaps.ignites_explosives or 0
power_size = PowerCaps.power_projectile_size or 0.0025
power_glow = PowerCaps.power_projectile_glow or 20
if PowerCaps.power_skill ~= nil then
power_skill = PowerCaps.power_skill[1] or ""
power_skillChance = PowerCaps.power_skill[2] or 0
else
power_skill = ""
power_skillChance = 0
end
end
if power_skillChance > 0 and power_skill ~= "" then
rangedweapons_gain_skill(player,power_skill,power_skillChance)
end
local skill_value = 1
if power_skill ~= "" then
skill_value = playerMeta:get_int(power_skill)/100
end
rangedweapons_launch_projectile(player,power_projectiles,power_damage,power_ent,power_visual,power_texture,power_sound,power_velocity,power_accuracy,skill_value,OnCollision,power_crit,power_critEffc,power_mobPen,power_nodePen,0,"","","",power_dps,power_gravity,power_door_breaking,power_glass_breaking,power_particles,power_sparks,power_bomb_ignite,power_size,0,0,power_glow)
if minetest.settings:get_bool("rangedweapons_gun_wear", true) then
itemstack:add_wear(65535/power_durability)
end
itemstack:set_name(power_cooling)
inv:remove_item("main", "rangedweapons:power_particle "..PowerCaps.power_consumption)
end
end end
rangedweapons_launch_projectile = function(player,projNum,projDmg,projEnt,visualType,texture,shoot_sound,combined_velocity,accuracy,skill_value,ColResult,projCrit,projCritEffc,mobPen,nodePen,has_shell,shellEnt,shellTexture,shellVisual,dps,gravity,door_break,glass_break,bullet_particles,sparks,ignite,size,smokeSize,proj_wear,proj_glow)
--minetest.chat_send_all(accuracy)
----------------------------------
local pos = player:get_pos()
local dir = player:get_look_dir()
local yaw = player:get_look_horizontal()
local svertical = player:get_look_vertical()
if pos and dir and yaw then
minetest.sound_play(shoot_sound, {pos = pos, max_hear_distance = 500})
pos.y = pos.y + 1.45
if has_shell > 0 and minetest.settings:get_bool("rangedweapons_animate_empty_shells", true) then
local shl = minetest.add_entity(pos, shellEnt)
shl:set_velocity({x=dir.x * -10, y=dir.y * -10, z=dir.z * -10})
shl:set_acceleration({x=dir.x * -5, y= -10, z=dir.z * -5})
shl:set_rotation({x=0,y=yaw - math.pi/2,z=-svertical})
shl:set_properties({
textures = {shellTexture},
visual = shellVisual,})
end
if smokeSize > 0 then
minetest.add_particle({
pos = pos,
velocity = {x=(dir.x*3)+(math.random(-10,10)/10), y=(dir.y*3)+(math.random(-10,10)/10), z=(dir.z*3)+(math.random(-10,10)/10)} ,
acceleration = {x=dir.x * -3, y=2, z=dir.z * -3},
expirationtime = math.random(5,10)/10,
size = smokeSize / 2,
collisiondetection = false,
vertical = false,
texture = "tnt_smoke.png",
glow = 5,
})
end
local projectiles = projNum or 1
for i=1,projectiles do
local obj = minetest.add_entity(pos, projEnt)
local ent = obj:get_luaentity()
obj:set_properties(
{textures = {texture},
visual = visualType,
collisionbox = {-size,-size,-size, size,size,size},
glow = proj_glow,}
)
ent.owner = player:get_player_name()
if obj then
ent.damage = projDmg
ent.crit = projCrit
ent.critEffc = projCritEffc
ent.OnCollision = ColResult
ent.mobPen = mobPen
ent.nodePen = nodePen
ent.dps = dps
ent.door_break = door_break
ent.glass_break = glass_break
ent.skill_value = skill_value
ent.bullet_particles = bullet_particles
ent.sparks = sparks
ent.ignite = ignite
ent.size = size
ent.timer = 0 + (combined_velocity/2000)
ent.wear = proj_wear
local acc = ((( 100 - accuracy ) / 10) / skill_value ) or 0
obj:set_velocity({x=dir.x * combined_velocity + math.random(-acc,acc), y=dir.y * combined_velocity + math.random(-acc,acc), z=dir.z * combined_velocity + math.random(-acc,acc)})
obj:set_acceleration({x=0, y=-gravity, z=0})
obj:set_rotation({x=0,y=yaw - math.pi/2,z=-svertical})
end end end
end
eject_shell = function(itemstack,player,rld_item,rld_time,rldsound,shell)
itemstack:set_name(rld_item)
local meta = player:get_meta()
meta:set_float("rw_cooldown", rld_time)
local gunMeta = itemstack:get_meta()
local bulletStack = ItemStack({name = gunMeta:get_string("RW_ammo_name")})
local pos = player:get_pos()
minetest.sound_play(rldsound, {pos = pos})
local dir = player:get_look_dir()
local yaw = player:get_look_horizontal()
if pos and dir and yaw then
pos.y = pos.y + 1.6
local obj = minetest.add_entity(pos, "rangedweapons:empty_shell")
if bulletStack ~= "" then
local AmmoCaps = bulletStack:get_definition().RW_ammo_capabilities
local bullet_shell_visual = "wielditem"
local bullet_shell_texture = "rangedweapons:shelldrop"
bullet_shell_visual = AmmoCaps.shell_visual or "wielditem"
bullet_shell_texture = AmmoCaps.shell_texture or "rangedweapons:shelldrop"
obj:set_properties({textures = {bullet_shell_texture}})
obj:set_properties({visual = bullet_shell_visual})
end
if obj then
obj:set_velocity({x=dir.x*-10, y=dir.y*-10, z=dir.z*-10})
obj:set_acceleration({x=dir.x*-5, y=-10, z=dir.z*-5})
obj:set_yaw(yaw - math.pi/2)
end end end
---------------------------------------------------
dofile(modpath.."/cooldown_stuff.lua")
dofile(modpath.."/skills.lua")
dofile(modpath.."/misc.lua")
dofile(modpath.."/bullet_knockback.lua")
dofile(modpath.."/ammo.lua")
dofile(modpath.."/crafting.lua")
if minetest.settings:get_bool("rangedweapons_shurikens", true) then
dofile(modpath.."/shurikens.lua")
end
if minetest.settings:get_bool("rangedweapons_handguns", true) then
dofile(modpath.."/makarov.lua")
dofile(modpath.."/luger.lua")
dofile(modpath.."/beretta.lua")
dofile(modpath.."/m1991.lua")
dofile(modpath.."/glock17.lua")
dofile(modpath.."/deagle.lua")
end
if minetest.settings:get_bool("rangedweapon_forceguns", true) then
dofile(modpath.."/forcegun.lua")
end
if minetest.settings:get_bool("rangedweapons_javelins", true) then
dofile(modpath.."/javelin.lua")
end
if minetest.settings:get_bool("rangedweapons_power_weapons", true) then
dofile(modpath.."/generator.lua")
dofile(modpath.."/laser_blaster.lua")
dofile(modpath.."/laser_rifle.lua")
dofile(modpath.."/laser_shotgun.lua")
end
if minetest.settings:get_bool("rangedweapons_machine_pistols", true) then
dofile(modpath.."/tmp.lua")
dofile(modpath.."/tec9.lua")
dofile(modpath.."/uzi.lua")
dofile(modpath.."/kriss_sv.lua")
end
if minetest.settings:get_bool("rangedweapons_shotguns", true) then
dofile(modpath.."/remington.lua")
dofile(modpath.."/spas12.lua")
dofile(modpath.."/benelli.lua")
end
if minetest.settings:get_bool("rangedweapons_auto_shotguns", true) then
dofile(modpath.."/jackhammer.lua")
dofile(modpath.."/aa12.lua")
end
if minetest.settings:get_bool("rangedweapons_smgs", true) then
dofile(modpath.."/mp5.lua")
dofile(modpath.."/ump.lua")
dofile(modpath.."/mp40.lua")
dofile(modpath.."/thompson.lua")
end
if minetest.settings:get_bool("rangedweapons_rifles", true) then
dofile(modpath.."/awp.lua")
dofile(modpath.."/svd.lua")
dofile(modpath.."/m200.lua")
end
if minetest.settings:get_bool("rangedweapons_heavy_machineguns", true) then
dofile(modpath.."/m60.lua")
dofile(modpath.."/rpk.lua")
dofile(modpath.."/minigun.lua")
end
if minetest.settings:get_bool("rangedweapons_revolvers", true) then
dofile(modpath.."/python.lua")
dofile(modpath.."/taurus.lua")
end
if minetest.settings:get_bool("rangedweapons_assault_rifles", true) then
dofile(modpath.."/m16.lua")
dofile(modpath.."/g36.lua")
dofile(modpath.."/ak47.lua")
dofile(modpath.."/scar.lua")
end
if minetest.settings:get_bool("rangedweapons_explosives", true) then
dofile(modpath.."/explosives.lua")
dofile(modpath.."/m79.lua")
dofile(modpath.."/milkor.lua")
dofile(modpath.."/rpg.lua")
dofile(modpath.."/hand_grenade.lua")
end
if minetest.settings:get_bool("rangedweapons_glass_breaking", true) then
dofile(modpath.."/glass_breaking.lua")
--[[ What is this good for?
minetest.register_abm({
nodenames = {"rangedweapons:broken_glass"},
interval = 1,
chance = 1,
action = function(pos, node)
if minetest.get_node(pos).name == "rangedweapons:broken_glass" then
node.name = "default:glass"
minetest.set_node(pos, node)
end
end
})
end
--]]
end
local rangedweapons_empty_shell = {
physical = false,
timer = 0,
visual = "wielditem",
visual_size = {x=0.3, y=0.3},
textures = {"rangedweapons:shelldrop"},
lastpos= {},
collisionbox = {0, 0, 0, 0, 0, 0},
}
rangedweapons_empty_shell.on_step = function(self, dtime, pos)
self.timer = self.timer + dtime
local pos = self.object:get_pos()
local node = minetest.get_node(pos)
if self.lastpos.y ~= nil then
if minetest.registered_nodes[node.name]~= nil then
if minetest.registered_nodes[node.name].walkable then
local vel = self.object:get_velocity()
local acc = self.object:get_acceleration()
self.object:set_velocity({x=vel.x*-0.3, y=vel.y*-0.75, z=vel.z*-0.3})
minetest.sound_play("rangedweapons_shellhit", {pos = self.lastpos, gain = 0.8})
self.object:set_acceleration({x=acc.x, y=acc.y, z=acc.z})
end end
end
if self.timer > 1.69 then
minetest.sound_play("rangedweapons_bulletdrop", {pos = self.lastpos, gain = 0.8})
self.object:remove()
end
self.lastpos= {x = pos.x, y = pos.y, z = pos.z}
end
minetest.register_entity("rangedweapons:empty_shell", rangedweapons_empty_shell )
minetest.register_abm({
nodenames = {"doors:hidden"},
interval = 1,
chance = 1,
action = function(pos, node)
pos.y = pos.y-1
if minetest.get_node(pos).name == "air" then
pos.y = pos.y+1
node.name = "air"
minetest.set_node(pos, node)
end
end
})
minetest.register_on_joinplayer(function(player)
hit =
player:hud_add({
hud_elem_type = "image",
text = "rangedweapons_empty_icon.png",
scale = {x = 2, y = 2},
position = {x = 0.5, y = 0.5},
offset = {x = 0, y = 0},
alignment = {x = 0, y = 0}
})
scope_hud =
player:hud_add({
hud_elem_type = "image",
position = { x=0.5, y=0.5 },
scale = { x=-100, y=-100 },
text = "rangedweapons_empty_icon.png",
})
end)
local timer = 0
minetest.register_globalstep(function(dtime)
timer = timer + dtime;
if timer >= 1.0 then
for _, player in pairs(minetest.get_connected_players()) do
player:hud_change(hit, "text", "rangedweapons_empty_icon.png")
timer = 0
end
end
end)