Rename gunslinger.enable_automatic to gunslinger.lite

Make it more generic, and document it in README.md
This commit is contained in:
Anand S 2019-01-04 18:36:51 +05:30
parent db1bc18fbf
commit d8cee030a3
No known key found for this signature in database
GPG Key ID: 3AD8A3C4A51AAB97
2 changed files with 18 additions and 7 deletions

View File

@ -7,6 +7,11 @@ This mod provides an API to add a variety of realistic and enjoyable guns to Min
- **Code**: MIT
- **Media**: CC0
## Settings
- `gunslinger.lite` [`bool`] (defaults to `false`)
- Toggles [lite mode](###Lite-mode)
## Architecture
Gunslinger makes use of gun _types_ in order to ease registration of similar guns. A `type` is made up of a name and a table of default values to be applied to all guns registered with that type. Types are optional, and can also be omitted altogether. Guns are allowed to override their type defaults, for maximum customisability. `Raycast` is used to find target in line-of-sight, and all objects including non-player entities take damage.
@ -17,18 +22,24 @@ Final damage is calculated like so:
- If headshot, damage is increased by 50%
- If shooter was looking through scope, damage is increased by 20%
### Lite mode
Enabling lite mode will disable the realistic/fancy features which are potentially lag-inducing. Recommended for large servers.
> Note: As of now, enabling lite mode will only disable automatic guns, but there are plans to allow lite mode to disable much more.
### Automatic guns
`gunslinger` supports automatic guns out of the box, while not causing excessive lag. This is achieved by adding players who left-click while wielding automatic guns to a special list, and the entry remains in the list only as long as their left mouse button is held down. A globalstep iterates through the table and fires one shot for all players in the list (while also respecting the fire-rate of the wielded guns).
The use of a dedicated list improves performance greatly, as the globalstep would have to otherwise iterate through **all** connected players, check if their mouse button is down, and only then, fire a shot. Nevertheless, disabling automatic guns is recommended on large public servers as it would cause quite a bit of lag, in spite of this optimisation.
The use of a dedicated list improves performance greatly, as the globalstep would have to otherwise iterate through **all** connected players, check if their mouse button is down, and only then, fire a shot. Nevertheless, disabling automatic guns (by enabling [lite mode](###Lite-mode)) is recommended on large public servers as it would still cause quite a bit of lag, in spite of this optimisation.
`gunslinger` provides a setting `"gunslinger.enable_automatic"`. Disabling this setting will throw an error when an automatic gun is registered.
## TODO
- Gun perks (special effects when bullet finds its target)
- Visible projectiles and entity-based collision/damage system.
- Visible projectiles and/or entity-based collision/damage system.
- Customisable recoil per-gun.
### See API.md for the complete gunslinger API reference

10
api.lua
View File

@ -1,7 +1,7 @@
gunslinger = {}
local max_wear = 65534
local enable_auto = minetest.settings:get_bool("gunslinger.enable_automatic")
local lite = minetest.settings:get_bool("gunslinger.lite")
local guns = {}
local types = {}
@ -191,7 +191,7 @@ local function on_step(dtime)
end
end
if enable_auto then
if lite then
minetest.register_globalstep(on_step)
end
@ -227,9 +227,9 @@ function gunslinger.register_gun(name, def)
end
end
if def.style_of_fire:find("automatic") and not enable_auto then
error("gunslinger: Attempt to register gun of disabled type "
.. "'" .. def.style_of_fire .. "''")
if def.style_of_fire:find("automatic") and not lite then
error("gunslinger: Attempt to register gun of disabled type '"
.. def.style_of_fire .. "'")
end
def.itemdef.on_use = on_lclick