add "playername" parameter to spacecannon.can_shoot so it can be overridden elsewhere

fixes #10
This commit is contained in:
BuckarooBanzay 2021-02-25 19:40:40 +01:00
parent bfca9a27e7
commit 8450e4ac70
3 changed files with 16 additions and 5 deletions

@ -110,7 +110,9 @@ local register_spacecannon = function(def)
mesecons = {effector = { mesecons = {effector = {
action_on = function (pos) action_on = function (pos)
spacecannon.fire(pos, def.color, def.speed, def.range) local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner")
spacecannon.fire(pos, owner, def.color, def.speed, def.range)
end end
}}, }},
@ -175,7 +177,7 @@ local register_spacecannon = function(def)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
if fields.fire then if fields.fire then
spacecannon.fire(pos, def.color, def.speed, def.range) spacecannon.fire(pos, playername, def.color, def.speed, def.range)
end end
if fields.set_digiline_channel and fields.digiline_channel then if fields.set_digiline_channel and fields.digiline_channel then

@ -83,6 +83,15 @@ Example response from a "fire" request:
} }
``` ```
# Api
Modify the ability to shoot depending on position or playername:
```lua
spacecannon.can_shoot = function(pos, playername)
return true
end
```
# Contributors # Contributors
* @BuckarooBanzay * @BuckarooBanzay

@ -28,7 +28,7 @@ spacecannon.update_formspec = function(meta)
end end
spacecannon.can_shoot = function() spacecannon.can_shoot = function()
-- arguments: pos -- arguments: pos, playername
return true return true
end end
@ -37,9 +37,9 @@ spacecannon.can_destroy = function()
return true return true
end end
spacecannon.fire = function(pos, color, speed, range) spacecannon.fire = function(pos, playername, color, speed, range)
if not spacecannon.can_shoot(pos) then if not spacecannon.can_shoot(pos, playername) then
return return
end end