minetest-quake/_weapons/weapons.lua

150 lines
4.0 KiB
Lua
Raw Normal View History

2020-03-27 12:46:48 -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
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
target_pointed_thing = get_pointed_players(pos_head, dir, range, username)
if not target_pointed_thing then return end
local player_count = 0
local i = 0
for i = 2,(target_pointed_thing[1])+1 do
if target_pointed_thing[i] then
quake.shoot(target_pointed_thing[1], user:get_player_name(), target_pointed_thing[i].ref, def.weap_damage, has_knockback)
end
end
player_count = 0
2020-04-20 04:53:23 -07:00
else
local has_knockback = def.knockback
local bullet_name = def.bullet
--i parametri potrebbero essere inutili ma non ne sono sicuro. Lasciamo così finchè va.
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-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
end
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
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