Use dot notation for api methods, closes #18
This commit is contained in:
parent
cff296d70b
commit
e415b0b9cc
6 changed files with 27 additions and 27 deletions
|
@ -22,7 +22,7 @@ local shooting = {}
|
||||||
local config = shooter.config
|
local config = shooter.config
|
||||||
local server_step = minetest.settings:get("dedicated_server_step")
|
local server_step = minetest.settings:get("dedicated_server_step")
|
||||||
|
|
||||||
function shooter:register_weapon(name, def)
|
shooter.register_weapon = function(name, def)
|
||||||
shooter.registered_weapons[name] = def
|
shooter.registered_weapons[name] = def
|
||||||
-- Fix definition table
|
-- Fix definition table
|
||||||
def.sounds = def.sounds or {}
|
def.sounds = def.sounds or {}
|
||||||
|
@ -42,7 +42,7 @@ function shooter:register_weapon(name, def)
|
||||||
description = def.description,
|
description = def.description,
|
||||||
inventory_image = def.inventory_image,
|
inventory_image = def.inventory_image,
|
||||||
on_use = function(itemstack, user)
|
on_use = function(itemstack, user)
|
||||||
if shooter:fire_weapon(user, itemstack, def.spec) then
|
if shooter.fire_weapon(user, itemstack, def.spec) then
|
||||||
itemstack:add_wear(def.spec.wear)
|
itemstack:add_wear(def.spec.wear)
|
||||||
if itemstack:get_count() == 0 then
|
if itemstack:get_count() == 0 then
|
||||||
itemstack = def.unloaded_item.name
|
itemstack = def.unloaded_item.name
|
||||||
|
@ -74,7 +74,7 @@ function shooter:register_weapon(name, def)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
function shooter:spawn_particles(pos, texture)
|
shooter.spawn_particles = function(pos, texture)
|
||||||
if config.enable_particle_fx == true then
|
if config.enable_particle_fx == true then
|
||||||
if type(texture) ~= "string" then
|
if type(texture) ~= "string" then
|
||||||
texture = config.explosion_texture
|
texture = config.explosion_texture
|
||||||
|
@ -99,7 +99,7 @@ function shooter:spawn_particles(pos, texture)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function shooter:play_node_sound(node, pos)
|
shooter.play_node_sound = function(node, pos)
|
||||||
local item = minetest.registered_items[node.name]
|
local item = minetest.registered_items[node.name]
|
||||||
if item then
|
if item then
|
||||||
if item.sounds then
|
if item.sounds then
|
||||||
|
@ -112,7 +112,7 @@ function shooter:play_node_sound(node, pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function shooter:punch_node(pos, spec)
|
shooter.punch_node = function(pos, spec)
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
if not node then
|
if not node then
|
||||||
return
|
return
|
||||||
|
@ -131,10 +131,10 @@ function shooter:punch_node(pos, spec)
|
||||||
local level = item.groups[k] or 0
|
local level = item.groups[k] or 0
|
||||||
if level >= v then
|
if level >= v then
|
||||||
minetest.remove_node(pos)
|
minetest.remove_node(pos)
|
||||||
shooter:play_node_sound(node, pos)
|
shooter.play_node_sound(node, pos)
|
||||||
if item.tiles then
|
if item.tiles then
|
||||||
if item.tiles[1] then
|
if item.tiles[1] then
|
||||||
shooter:spawn_particles(pos, item.tiles[1])
|
shooter.spawn_particles(pos, item.tiles[1])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
break
|
break
|
||||||
|
@ -143,7 +143,7 @@ function shooter:punch_node(pos, spec)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function shooter:is_valid_object(object)
|
shooter.is_valid_object = function(object)
|
||||||
if object then
|
if object then
|
||||||
if object:is_player() == true then
|
if object:is_player() == true then
|
||||||
return config.allow_players
|
return config.allow_players
|
||||||
|
@ -169,17 +169,17 @@ local function process_round(round)
|
||||||
if pointed_thing.type == "node" then
|
if pointed_thing.type == "node" then
|
||||||
if config.allow_nodes == true then
|
if config.allow_nodes == true then
|
||||||
local pos = minetest.get_pointed_thing_position(pointed_thing, false)
|
local pos = minetest.get_pointed_thing_position(pointed_thing, false)
|
||||||
shooter:punch_node(pos, round.spec)
|
shooter.punch_node(pos, round.spec)
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
elseif pointed_thing.type == "object" then
|
elseif pointed_thing.type == "object" then
|
||||||
local object = pointed_thing.ref
|
local object = pointed_thing.ref
|
||||||
if shooter:is_valid_object(object) == true then
|
if shooter.is_valid_object(object) == true then
|
||||||
local player = minetest.get_player_by_name(round.spec.user)
|
local player = minetest.get_player_by_name(round.spec.user)
|
||||||
if player then
|
if player then
|
||||||
object:punch(player, nil, round.spec.tool_caps, round.dir)
|
object:punch(player, nil, round.spec.tool_caps, round.dir)
|
||||||
local pos = pointed_thing.intersection_point or object:get_pos()
|
local pos = pointed_thing.intersection_point or object:get_pos()
|
||||||
shooter:spawn_particles(pos, config.explosion_texture)
|
shooter.spawn_particles(pos, config.explosion_texture)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
|
@ -236,7 +236,7 @@ local function fire_weapon(player, itemstack, spec, extended)
|
||||||
end, player, itemstack, spec)
|
end, player, itemstack, spec)
|
||||||
end
|
end
|
||||||
|
|
||||||
function shooter:fire_weapon(player, itemstack, spec)
|
shooter.fire_weapon = function(player, itemstack, spec)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local time = minetest.get_us_time() / 1000000
|
local time = minetest.get_us_time() / 1000000
|
||||||
if shots[name] and time <= shots[name] then
|
if shots[name] and time <= shots[name] then
|
||||||
|
@ -252,7 +252,7 @@ function shooter:fire_weapon(player, itemstack, spec)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function shooter:blast(pos, radius, fleshy, distance, user)
|
shooter.blast = function(pos, radius, fleshy, distance, user)
|
||||||
if not user then
|
if not user then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -290,7 +290,7 @@ function shooter:blast(pos, radius, fleshy, distance, user)
|
||||||
end
|
end
|
||||||
local objects = minetest.get_objects_inside_radius(pos, distance)
|
local objects = minetest.get_objects_inside_radius(pos, distance)
|
||||||
for _,obj in ipairs(objects) do
|
for _,obj in ipairs(objects) do
|
||||||
if shooter:is_valid_object(obj) then
|
if shooter.is_valid_object(obj) then
|
||||||
local obj_pos = obj:get_pos()
|
local obj_pos = obj:get_pos()
|
||||||
local dist = vector.distance(obj_pos, pos)
|
local dist = vector.distance(obj_pos, pos)
|
||||||
local damage = (fleshy * 0.5 ^ dist) * 2
|
local damage = (fleshy * 0.5 ^ dist) * 2
|
||||||
|
|
|
@ -32,7 +32,7 @@ The API works with tools and items that represent a weapon,
|
||||||
then you should register the weapon and another support items (like ammo).
|
then you should register the weapon and another support items (like ammo).
|
||||||
|
|
||||||
### Methods
|
### Methods
|
||||||
* `shooter:register_weapon(weapon_name, {Weapon Definitions})`: Register a weapon item
|
* `shooter.register_weapon(weapon_name, {Weapon Definitions})`: Register a weapon item
|
||||||
`weapon_name` is the itemstring for a tool to be registered
|
`weapon_name` is the itemstring for a tool to be registered
|
||||||
|
|
||||||
Global Tables
|
Global Tables
|
||||||
|
@ -42,7 +42,7 @@ Global Tables
|
||||||
Definition tables
|
Definition tables
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
### Weapon Definitions (`shooter:register_weapon`)
|
### Weapon Definitions (`shooter.register_weapon`)
|
||||||
|
|
||||||
{
|
{
|
||||||
description = "Rifle", -- Weapon description name
|
description = "Rifle", -- Weapon description name
|
||||||
|
|
|
@ -58,12 +58,12 @@ local function strike(arrow, pointed_thing, name)
|
||||||
local dir = vector.normalize(object:get_velocity())
|
local dir = vector.normalize(object:get_velocity())
|
||||||
if pointed_thing.type == "object" then
|
if pointed_thing.type == "object" then
|
||||||
local target = pointed_thing.ref
|
local target = pointed_thing.ref
|
||||||
if shooter:is_valid_object(target) then
|
if shooter.is_valid_object(target) then
|
||||||
local puncher = minetest.get_player_by_name(name)
|
local puncher = minetest.get_player_by_name(name)
|
||||||
if puncher and puncher ~= target then
|
if puncher and puncher ~= target then
|
||||||
local groups = target:get_armor_groups() or {}
|
local groups = target:get_armor_groups() or {}
|
||||||
if groups.fleshy then
|
if groups.fleshy then
|
||||||
shooter:spawn_particles(hit_pos,
|
shooter.spawn_particles(hit_pos,
|
||||||
shooter.config.explosion_texture)
|
shooter.config.explosion_texture)
|
||||||
end
|
end
|
||||||
target:punch(object, nil, arrow_tool_caps, dir)
|
target:punch(object, nil, arrow_tool_caps, dir)
|
||||||
|
@ -85,7 +85,7 @@ local function strike(arrow, pointed_thing, name)
|
||||||
hit_pos = vector.subtract(hit_pos, vector.multiply(dir, 0.25))
|
hit_pos = vector.subtract(hit_pos, vector.multiply(dir, 0.25))
|
||||||
arrow.node_pos = pos
|
arrow.node_pos = pos
|
||||||
arrow.state = "stuck"
|
arrow.state = "stuck"
|
||||||
shooter:play_node_sound(node, pos)
|
shooter.play_node_sound(node, pos)
|
||||||
else
|
else
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
|
@ -27,7 +27,7 @@ minetest.register_entity("shooter_grenade:grenade_entity", {
|
||||||
if self.user then
|
if self.user then
|
||||||
local player = minetest.get_player_by_name(self.user)
|
local player = minetest.get_player_by_name(self.user)
|
||||||
if player then
|
if player then
|
||||||
shooter:blast(above, 2, 25, 5, player)
|
shooter.blast(above, 2, 25, 5, player)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
|
@ -50,7 +50,7 @@ minetest.register_tool("shooter_grenade:grenade", {
|
||||||
if pointed_thing.type ~= "nothing" then
|
if pointed_thing.type ~= "nothing" then
|
||||||
local pointed = minetest.get_pointed_thing_position(pointed_thing)
|
local pointed = minetest.get_pointed_thing_position(pointed_thing)
|
||||||
if vector.distance(user:get_pos(), pointed) < 8 then
|
if vector.distance(user:get_pos(), pointed) < 8 then
|
||||||
shooter:blast(pointed, 1, 25, 5)
|
shooter.blast(pointed, 1, 25, 5)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
shooter:register_weapon("shooter_guns:pistol", {
|
shooter.register_weapon("shooter_guns:pistol", {
|
||||||
description = "Pistol",
|
description = "Pistol",
|
||||||
inventory_image = "shooter_pistol.png",
|
inventory_image = "shooter_pistol.png",
|
||||||
spec = {
|
spec = {
|
||||||
|
@ -12,7 +12,7 @@ shooter:register_weapon("shooter_guns:pistol", {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
shooter:register_weapon("shooter_guns:rifle", {
|
shooter.register_weapon("shooter_guns:rifle", {
|
||||||
description = "Rifle",
|
description = "Rifle",
|
||||||
inventory_image = "shooter_rifle.png",
|
inventory_image = "shooter_rifle.png",
|
||||||
spec = {
|
spec = {
|
||||||
|
@ -26,7 +26,7 @@ shooter:register_weapon("shooter_guns:rifle", {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
shooter:register_weapon("shooter_guns:shotgun", {
|
shooter.register_weapon("shooter_guns:shotgun", {
|
||||||
description = "Shotgun",
|
description = "Shotgun",
|
||||||
inventory_image = "shooter_shotgun.png",
|
inventory_image = "shooter_shotgun.png",
|
||||||
spec = {
|
spec = {
|
||||||
|
@ -40,7 +40,7 @@ shooter:register_weapon("shooter_guns:shotgun", {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
shooter:register_weapon("shooter_guns:machine_gun", {
|
shooter.register_weapon("shooter_guns:machine_gun", {
|
||||||
description = "Sub Machine Gun",
|
description = "Sub Machine Gun",
|
||||||
inventory_image = "shooter_smgun.png",
|
inventory_image = "shooter_smgun.png",
|
||||||
spec = {
|
spec = {
|
||||||
|
|
|
@ -33,7 +33,7 @@ minetest.register_entity("shooter_rocket:rocket_entity", {
|
||||||
if self.user then
|
if self.user then
|
||||||
local player = minetest.get_player_by_name(self.user)
|
local player = minetest.get_player_by_name(self.user)
|
||||||
if player then
|
if player then
|
||||||
shooter:blast(above, 4, 50, 8, player)
|
shooter.blast(above, 4, 50, 8, player)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
|
@ -58,7 +58,7 @@ minetest.register_tool("shooter_rocket:rocket_gun_loaded", {
|
||||||
if pointed_thing.type ~= "nothing" then
|
if pointed_thing.type ~= "nothing" then
|
||||||
local pointed = minetest.get_pointed_thing_position(pointed_thing)
|
local pointed = minetest.get_pointed_thing_position(pointed_thing)
|
||||||
if vector.distance(user:get_pos(), pointed) < 8 then
|
if vector.distance(user:get_pos(), pointed) < 8 then
|
||||||
shooter:blast(pointed, 2, 50, 7)
|
shooter.blast(pointed, 2, 50, 7)
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue