Pulizie pt2
parent
694c001dec
commit
21e5096c5c
|
@ -1,16 +0,0 @@
|
|||
|
||||
quake.register_weapon("quake:bazooka", {
|
||||
description = "IT'S ONESHOT BABY",
|
||||
mesh = "bazooka.obj",
|
||||
tiles = {"quake_bazooka.png"},
|
||||
wield_scale = {x=1.3, y=1.3, z=1.3},
|
||||
inventory_image = "quake_bazooka_icon.png",
|
||||
weap_damage = 10, --FF7 in my heart
|
||||
weap_delay = 0.8,
|
||||
weap_sound_shooting = "quake_railgun_shoot",
|
||||
is_hitscan = false,
|
||||
range = 100,
|
||||
bullet = "quake:rocket",
|
||||
knockback = true
|
||||
|
||||
})
|
|
@ -21,6 +21,7 @@ function quake.register_bullet(name, def)
|
|||
explosion_range = def.explosion_range,
|
||||
duration = def.duration,
|
||||
explosion_damage = def.explosion_damage,
|
||||
no_collision_time = 1/(2*def.speed), -- il tempo necessario per non far impattare il proiettile contro il giocatore
|
||||
def = def,
|
||||
},
|
||||
}
|
||||
|
@ -35,26 +36,27 @@ function quake.register_bullet(name, def)
|
|||
|
||||
|
||||
-- cosa succede alla distruzione del proiettile. In pratica prende il metodo impostato
|
||||
--nella creazione del proiettile e lo usa alla distruzione. Comodo perchè così è astratta anche quella
|
||||
-- nella creazione del proiettile e lo usa alla distruzione. Comodo perchè così è astratta anche quella
|
||||
function bulletentity:_destroy()
|
||||
if (self.initial_properties.def.on_destroy) then
|
||||
self.initial_properties.def.on_destroy(self);
|
||||
|
||||
if self.initial_properties.def.on_destroy then
|
||||
self.initial_properties.def.on_destroy(self)
|
||||
end
|
||||
|
||||
self.lastpos = {}
|
||||
|
||||
--spawna le particelle
|
||||
-- spawna le particelle
|
||||
spawn_particles_sphere(self.object:getpos(), self.initial_properties.explosion_texture)
|
||||
self.object:remove()
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
--Funzione che si attiva quando si aggiunge una entità con add_entity
|
||||
--Il parametro staticdata è una stringa che viene passata come parametro e viene spiegata nel moddingbook di rubenwardy
|
||||
--Utile per settare parametri come l'utente.
|
||||
--Funzione che si attiva quando si aggiunge un'entità con add_entity
|
||||
function bulletentity:on_activate(staticdata)
|
||||
if staticdata ~= "" and staticdata ~= nil then
|
||||
self.p_name = staticdata --staticdata in questo caso è l'username.
|
||||
self.p_name = staticdata -- nome utente come staticdata
|
||||
self.shooter = minetest.get_player_by_name(staticdata)
|
||||
end
|
||||
|
||||
|
@ -65,22 +67,21 @@ function quake.register_bullet(name, def)
|
|||
end
|
||||
|
||||
|
||||
--Funzione che si attiva ad ogni step
|
||||
|
||||
function bulletentity:on_step(dtime)
|
||||
|
||||
--incrementa il lifetime
|
||||
-- incremento tempo di vita
|
||||
self.lifetime = self.lifetime + dtime
|
||||
local pos = self.object:getpos()
|
||||
--ottiene il nodo in cui è l'entità in quello step
|
||||
|
||||
local pos = self.object:get_pos()
|
||||
local node = minetest.env:get_node(pos)
|
||||
local dir = vector.normalize(self.object:get_velocity()) --ottiene la direzione in cui punta l'entità
|
||||
local dir = vector.normalize(self.object:get_velocity())
|
||||
|
||||
--check per vedere che il lifetime sia maggiore di un certo valore e minore della vita in aria del proiettile
|
||||
--se rispetta queste cose allora il proiettile è sufficientemente lontano dal player e può colpire il player stesso ed è ancora vivo.
|
||||
if self.lifetime > (1/(2*self.initial_properties.speed)) and self.lifetime < self.initial_properties.duration then
|
||||
-- se il proiettile è pronto a colpire
|
||||
if self.lifetime > self.initial_properties.no_collision_time and self.lifetime < self.initial_properties.duration then
|
||||
|
||||
--ottine gli oggetti in un raggio rispetto alla posizione dell'entità
|
||||
--il raggio è piccolo così prende solo quando è realmente nel corpo.
|
||||
-- ottiene gli oggetti in un raggio rispetto alla posizione dell'entità
|
||||
-- il raggio è piccolo così prende solo quando è realmente nel corpo.
|
||||
local objs = minetest.env:get_objects_inside_radius({x=pos.x,y=pos.y-1.475,z=pos.z},0.5)
|
||||
|
||||
if objs then
|
||||
|
@ -88,9 +89,9 @@ function quake.register_bullet(name, def)
|
|||
for k, obj in ipairs(objs) do
|
||||
--check per vedere che l'oggetto non sia l'entità stessa e che sia un giocatore
|
||||
if (obj:get_entity_name() ~= self.object:get_entity_name() and obj:is_player()) then
|
||||
--fa lo shoote del player colpito
|
||||
--fa lo shoot del player colpito
|
||||
quake.shoot(1, self.p_name, obj, self.initial_properties.damage, false)
|
||||
--chiama la funzione _destroy() e distrugge il proiettile facendollo epslodere ins to caso
|
||||
--chiama la funzione _destroy() e distrugge il proiettile facendolo esplodere in 'sto caso
|
||||
self:_destroy();
|
||||
return;
|
||||
end
|
||||
|
@ -162,7 +163,7 @@ end
|
|||
|
||||
|
||||
|
||||
--aggiungeleparticelle dell'esplosione
|
||||
--aggiunge le particelle dell'esplosione
|
||||
function spawn_particles_sphere(pos, particle_texture)
|
||||
|
||||
minetest.add_particlespawner({
|
||||
|
@ -181,34 +182,22 @@ function spawn_particles_sphere(pos, particle_texture)
|
|||
collisiondetection = false,
|
||||
vertical = false,
|
||||
texture = particle_texture,
|
||||
|
||||
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
--Aggiunge l'entità orientata correttamente.
|
||||
function quake.shoot_bullet(shooter, pointed_thing, bullet_name, pos_head, dir)
|
||||
local username = shooter:get_player_name()
|
||||
|
||||
--add_entity has 3 params:
|
||||
-- position where the entity will be spawned
|
||||
-- name of the entity to spawna
|
||||
-- staticdata, is optional and is a string that gets parsed to the on_activate
|
||||
local bullet = minetest.add_entity(
|
||||
pos_head,
|
||||
bullet_name,
|
||||
username
|
||||
)
|
||||
function quake.shoot_bullet(shooter, pointed_thing, bullet, pos_head, dir)
|
||||
|
||||
local username = shooter:get_player_name()
|
||||
local bullet = minetest.add_entity(pos_head, bullet, username) -- spawna il proiettile dalla testa e passo il nick come staticdata
|
||||
local yaw = shooter:get_look_horizontal()
|
||||
local pitch = shooter:get_look_vertical()
|
||||
|
||||
|
||||
bullet:set_rotation({x = -pitch, y = yaw, z = 0})
|
||||
|
||||
local speed = bullet:get_luaentity().initial_properties.speed
|
||||
--imposta la velocità all'entità
|
||||
bullet:setvelocity({
|
||||
bullet:set_velocity({
|
||||
x=(dir.x * speed),
|
||||
y=(dir.y * speed),
|
||||
z=(dir.z * speed),
|
||||
|
@ -218,6 +207,7 @@ function quake.shoot_bullet(shooter, pointed_thing, bullet_name, pos_head, dir)
|
|||
end
|
||||
|
||||
|
||||
|
||||
-- ottiene la distanza tra proiettile e cosa che sta puntando
|
||||
function get_dist(hit_pos, pos_ent)
|
||||
local lenx = math.abs(hit_pos.x - pos_ent.x)
|
||||
|
@ -228,10 +218,12 @@ function get_dist(hit_pos, pos_ent)
|
|||
return dist
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ottiene la cosa puntata dall'entità. Inizia da dietro l'entità perchè serve a verificare che non abbia attraversato un player senza colpirlo
|
||||
function get_pointed_thing(pos_buillet, dir, username)
|
||||
local p1 = vector.add(pos_buillet, vector.multiply(dir, -1))
|
||||
local p2 = vector.add(pos_buillet, vector.multiply(dir, 1))
|
||||
function get_pointed_thing(pos_bullet, dir, username)
|
||||
local p1 = vector.add(pos_bullet, vector.multiply(dir, -1))
|
||||
local p2 = vector.add(pos_bullet, vector.multiply(dir, 1))
|
||||
local ray = minetest.raycast(p1, p2, true, true)
|
||||
|
||||
for hit in ray do
|
||||
|
|
|
@ -69,9 +69,9 @@ function quake.register_weapon(name, def)
|
|||
end
|
||||
else
|
||||
local has_knockback = def.knockback
|
||||
local bullet_name = def.bullet
|
||||
local bullet = 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)
|
||||
quake.shoot_bullet(user, pointed_thing, bullet, pos_head, dir)
|
||||
end
|
||||
|
||||
end,
|
||||
|
|
Loading…
Reference in New Issue