2020-03-27 12:46:48 -07:00
|
|
|
|
2020-03-30 14:21:29 -07:00
|
|
|
|
2020-04-20 04:53:23 -07:00
|
|
|
function quake.register_weapon(name, def)
|
|
|
|
|
|
|
|
local weap_delay = def.weap_delay
|
2020-04-20 07:28:31 -07:00
|
|
|
local weap_sound_shooting = def.weap_sound_shooting
|
2020-04-20 04:53:23 -07:00
|
|
|
local is_hitscan = def.is_hitscan
|
|
|
|
local range = def.range
|
2020-04-28 06:48:15 -07:00
|
|
|
local has_knockback = def.has_knockback
|
2020-04-20 04:53:23 -07:00
|
|
|
|
|
|
|
minetest.register_node(name, {
|
|
|
|
|
|
|
|
description = def.description,
|
|
|
|
drawtype = "mesh",
|
|
|
|
mesh = def.mesh,
|
|
|
|
tiles = def.tiles,
|
|
|
|
wield_scale = def.wield_scale,
|
|
|
|
inventory_image = def.inventory_image,
|
|
|
|
stack_max = 1,
|
|
|
|
groups = {oddly_breakable_by_hand = "2"},
|
2020-05-11 13:51:23 -07:00
|
|
|
on_drop = function()
|
|
|
|
return nil
|
|
|
|
end,
|
2020-04-20 04:53:23 -07:00
|
|
|
|
|
|
|
on_place = function()
|
|
|
|
return nil
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
|
|
|
|
|
|
----- gestione delay dell'arma -----
|
|
|
|
if user:get_meta():get_int("quake_weap_delay") == 1 then
|
|
|
|
return end
|
|
|
|
|
|
|
|
user:get_meta():set_int("quake_weap_delay", 1)
|
|
|
|
|
|
|
|
local inv = user:get_inventory()
|
|
|
|
|
|
|
|
minetest.after(weap_delay, function()
|
|
|
|
if inv:contains_item("main", "quake:match_over") then return end
|
|
|
|
user:get_meta():set_int("quake_weap_delay", 0)
|
|
|
|
end)
|
|
|
|
-----fine gestione delay -----
|
|
|
|
|
|
|
|
|
|
|
|
--se sono immune e sparo, perdo l'immunità
|
|
|
|
if inv:contains_item("main", "arena_lib:immunity") then
|
|
|
|
inv:remove_item("main", "arena_lib:immunity")
|
|
|
|
end
|
|
|
|
|
2020-04-20 07:28:31 -07:00
|
|
|
-- riproduzione suono
|
|
|
|
minetest.sound_play(weap_sound_shooting, {
|
|
|
|
to_player = user:get_player_name(),
|
|
|
|
max_hear_distance = 5,
|
|
|
|
})
|
|
|
|
|
2020-04-20 04:53:23 -07:00
|
|
|
local dir = user:get_look_dir()
|
|
|
|
local pos = user:get_pos()
|
|
|
|
local pos_head = {x = pos.x, y = pos.y+1.475, z = pos.z} -- deve sparare all'altezza mirino, ovvero dalla testa
|
|
|
|
local username = user:get_player_name()
|
|
|
|
|
2020-04-20 07:36:16 -07:00
|
|
|
local target_pointed_thing
|
|
|
|
|
2020-04-20 04:53:23 -07:00
|
|
|
if def.is_hitscan then
|
2020-04-28 06:48:15 -07:00
|
|
|
target_pointed_thing = get_pointed_players(pos_head, dir, range, username)
|
2020-05-11 13:43:59 -07:00
|
|
|
if not target_pointed_thing then return end
|
2020-05-21 12:38:58 -07:00
|
|
|
local player_count = 0
|
2020-05-11 13:43:59 -07:00
|
|
|
local i = 0
|
|
|
|
for i = 2,(target_pointed_thing[1])+1 do
|
|
|
|
if target_pointed_thing[i] then
|
2020-05-21 12:38:58 -07:00
|
|
|
quake.shoot(target_pointed_thing[1], user:get_player_name(), target_pointed_thing[i].ref, def.weap_damage, has_knockback)
|
2020-05-11 13:43:59 -07:00
|
|
|
end
|
|
|
|
end
|
2020-05-21 12:38:58 -07:00
|
|
|
player_count = 0
|
2020-04-20 04:53:23 -07:00
|
|
|
else
|
2020-05-11 13:43:59 -07:00
|
|
|
local has_knockback = def.knockback
|
|
|
|
local bullet_name = def.bullet
|
|
|
|
--i parametri potrebbero essere inutili ma non ne sono sicuro. Lasciamo così finchè va.
|
2020-05-21 12:38:58 -07:00
|
|
|
quake.shoot_bullet(user, pointed_thing, bullet_name, pos_head, dir)
|
2020-04-20 07:28:31 -07:00
|
|
|
--TODO armi con proiettili
|
2020-04-20 04:53:23 -07:00
|
|
|
end
|
|
|
|
|
2020-04-20 07:28:31 -07:00
|
|
|
|
|
|
|
|
2020-04-20 04:53:23 -07:00
|
|
|
end,
|
|
|
|
|
|
|
|
})
|
2020-04-09 05:21:35 -07:00
|
|
|
|
2020-04-20 04:53:23 -07:00
|
|
|
end
|
2020-03-27 12:46:48 -07:00
|
|
|
|
2020-05-15 12:02:33 -07:00
|
|
|
|
2020-05-11 13:43:59 -07:00
|
|
|
|
2020-03-27 12:46:48 -07:00
|
|
|
|
2020-04-20 03:58:28 -07:00
|
|
|
-- ritorna un array di player con a index 1 il numero di player trovati. Se non
|
|
|
|
-- trova player diversi da se stessi ritorna nil
|
|
|
|
function get_pointed_players(head_pos, dir, dist, username)
|
2020-04-10 08:20:48 -07:00
|
|
|
local p1 = vector.add(head_pos, vector.divide(dir,4))
|
2020-04-01 03:23:28 -07:00
|
|
|
local p2 = vector.add(head_pos, vector.multiply(dir, dist))
|
2020-04-01 14:04:08 -07:00
|
|
|
local ray = minetest.raycast(p1, p2, true, true)
|
2020-04-20 03:58:28 -07:00
|
|
|
|
2020-04-01 03:23:28 -07:00
|
|
|
minetest.add_particlespawner({
|
2020-04-10 08:20:48 -07:00
|
|
|
amount = 20,
|
|
|
|
time = 0.3,
|
2020-04-01 14:04:08 -07:00
|
|
|
minpos = p1,
|
|
|
|
maxpos = p1,
|
2020-04-10 08:20:48 -07:00
|
|
|
minvel = vector.multiply(dir,120),
|
|
|
|
maxvel = vector.multiply(dir,120),
|
2020-04-01 14:04:08 -07:00
|
|
|
minexptime = 0.2,
|
|
|
|
maxexptime = 0.2,
|
|
|
|
size = 2,
|
|
|
|
collisiondetection = false,
|
|
|
|
vertical = false,
|
2020-04-10 08:20:48 -07:00
|
|
|
texture = "quake_railgun_trail.png"
|
2020-04-01 03:23:28 -07:00
|
|
|
})
|
2020-04-20 03:58:28 -07:00
|
|
|
|
2020-04-19 13:04:21 -07:00
|
|
|
local array = {} --inizializzo array con numero di giocatori a 0
|
|
|
|
array[1] = 0
|
|
|
|
local i = 2
|
2020-04-20 03:58:28 -07:00
|
|
|
-- check su ogni cosa attraversata dal raycast (p1 a p2)
|
|
|
|
for hit in ray do
|
|
|
|
-- se è un oggetto
|
|
|
|
if hit.type == "object" and hit.ref then
|
|
|
|
-- se è un giocatore
|
|
|
|
if hit.ref:is_player() then
|
|
|
|
-- e non è colui che spara
|
|
|
|
if hit.ref:get_player_name() ~= username then
|
2020-04-19 13:04:21 -07:00
|
|
|
array[i] = hit
|
2020-04-20 03:58:28 -07:00
|
|
|
array[1] = i - 1 --incrementa il numero di giocatori
|
2020-04-19 13:04:21 -07:00
|
|
|
i = i + 1
|
2020-04-10 09:55:02 -07:00
|
|
|
end
|
2020-04-10 09:42:20 -07:00
|
|
|
end
|
2020-04-20 03:58:28 -07:00
|
|
|
|
2020-04-19 13:04:21 -07:00
|
|
|
else
|
2020-04-20 03:58:28 -07:00
|
|
|
-- se è un nodo mi fermo, e ritorno l'array se > 0 (ovvero ha trovato giocatori)
|
|
|
|
if hit.type == "node" then
|
|
|
|
if array[1] > 0 then
|
2020-04-19 13:04:21 -07:00
|
|
|
return array
|
2020-04-19 13:27:21 -07:00
|
|
|
else
|
|
|
|
return nil
|
2020-04-10 09:42:20 -07:00
|
|
|
end
|
|
|
|
end
|
2020-04-20 03:58:28 -07:00
|
|
|
end
|
2020-04-01 03:23:28 -07:00
|
|
|
end
|
2020-04-20 03:58:28 -07:00
|
|
|
-- se ho sparato a qualcuno puntando in aria (quindi senza incrociare blocchi)
|
|
|
|
if array[1] > 0 then
|
2020-04-19 13:04:21 -07:00
|
|
|
return array
|
|
|
|
end
|
2020-04-20 03:58:28 -07:00
|
|
|
|
2020-03-27 12:46:48 -07:00
|
|
|
end
|