Move chatcommands to a seperate mod

This commit is contained in:
a-bad-dev 2025-12-12 15:56:50 -04:00
commit 44c1be6a55
292 changed files with 50 additions and 45 deletions

41
mods/misc/ctf_guns/rawf/.gitignore vendored Normal file
View file

@ -0,0 +1,41 @@
# Compiled Lua sources
luac.out
# luarocks build files
*.src.rock
*.zip
*.tar.gz
# Object files
*.o
*.os
*.ko
*.obj
*.elf
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
*.def
*.exp
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

View file

@ -0,0 +1,47 @@
read_globals = {
"DIR_DELIM", "INIT",
"minetest", "core",
"dump", "dump2",
"api",
"Raycast",
"Settings",
"PseudoRandom",
"PerlinNoise",
"VoxelManip",
"SecureRandom",
"VoxelArea",
"PerlinNoiseMap",
"PcgRandom",
"ItemStack",
"AreaStore",
"vector",
table = {
fields = {
"copy",
"indexof",
"insert_all",
"key_value_swap",
"shuffle",
}
},
string = {
fields = {
"split",
"trim",
}
},
math = {
fields = {
"hypot",
"sign",
"factorial"
}
},
}

View file

@ -0,0 +1,23 @@
## Custom item definition values
```lua
{
-- Name of the loaded version of the ranged weapon
-- Used by: load_weapon()
-- Set by: also_register_loaded_tool()
loaded_name = <string>,
-- Name of the unloaded version of the ranged weapon
-- Used by: unload_weapon()
-- Set by: also_register_loaded_tool()
unloaded_name = <string>,
-- Amount of bullets the ranged weapon can shoot.
-- Used by: unload_weapon()
rounds = <number>,
-- Ammo that can be used by the ranged weapon
-- Used by: load_weapon()
ammo = <itemstack | string | list>
}
```

View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021 LoneWolfHT
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,2 @@
# RaWF
A ranged weapon framework for Minetest

View file

@ -0,0 +1,67 @@
local MODNAME = minetest.get_current_modname()
local api = rawget(_G, MODNAME)
function api.also_register_loaded_tool(name, def, user_loaded_def)
local loaded_def = table.copy(def)
if user_loaded_def then
user_loaded_def(loaded_def)
end
loaded_def.unloaded_name = name
def.loaded_name = name.."_loaded"
minetest.register_tool(def.loaded_name, loaded_def)
return name, def
end
function api.unload_weapon(weapon, amount)
local iname = weapon:get_name()
local rounds = assert(
minetest.registered_tools[iname].rounds,
"Must define 'rounds' property for ranged weapon "..dump(iname)
)
local new_wear = (65535 / (rounds)) * (amount or 1)
-- Applies #15 PR
new_wear = weapon:get_wear() + new_wear + 1
if new_wear >= 65535 then
return ItemStack(weapon:get_definition().unloaded_name)
end
weapon:set_wear(new_wear)
return weapon
end
function api.load_weapon(weapon, inv, lists)
local idef = weapon:get_definition()
assert(idef.loaded_name, "Item "..idef.name.." doesn't have 'loaded_name' set!")
assert(idef.ammo, "Item "..idef.name.." doesn't have 'ammo' set!")
if type(idef.ammo) ~= "table" then
idef.ammo = {idef.ammo}
end
if not lists then
lists = {"main"}
elseif type(lists) ~= "table" then
lists = {lists}
end
for _, item in pairs(idef.ammo) do
for _, list in pairs(lists) do
if inv:contains_item(list, item) then
inv:remove_item(list, item)
return ItemStack(idef.loaded_name)
end
end
end
return weapon
end

View file

@ -0,0 +1,87 @@
local MODNAME = minetest.get_current_modname()
local api = rawget(_G, MODNAME)
function api.get_bullet_start_data(player)
local look_dir = player:get_look_dir()
local spawnpos = vector.offset(player:get_pos(), 0, player:get_properties().eye_height, 0)
spawnpos = vector.add(spawnpos, player:get_eye_offset())
spawnpos = vector.add(spawnpos, vector.multiply(look_dir, 0.4))
return spawnpos, look_dir
end
function api.bulletcast(bullet, pos1, pos2, objects, liquids)
minetest.add_particle({
pos = pos1,
velocity = vector.multiply(vector.direction(pos1, pos2), bullet.particle_speed or 400),
acceleration = {x=0, y=0, z=0},
expirationtime = 0.1,
size = 1,
collisiondetection = true,
collision_removal = true,
object_collision = objects,
texture = bullet.texture or bullet,
glow = bullet.glow or 0
})
local raycast = minetest.raycast(pos1, pos2, objects, liquids)
local bulletcast = {
raycast = raycast,
hit_object_or_node = function(self, options)
if not options then
options = {}
end
for hitpoint in self.raycast do
if hitpoint.type == "node" then
if not options.node or options.node(minetest.registered_nodes[minetest.get_node(hitpoint.under).name]) then
return hitpoint
end
elseif hitpoint.type == "object" then
if not options.object or options.object(hitpoint.ref) then
return hitpoint
end
end
end
end,
}
setmetatable(bulletcast, {
__index = function(table, key)
local not_raycast_func = rawget(table, key)
if not_raycast_func then
return not_raycast_func
else
return function(self, ...)
local sraycast = rawget(self, "raycast")
return sraycast[key](sraycast, ...)
end
end
end,
__call = function(table, ...)
return rawget(table, "raycast")(...)
end
})
return bulletcast
end
function api.spread_bulletcast(bullet, pos1, pos2, objects, liquids)
local rays = {}
for i=1, bullet.amount or 1, 1 do
rays[i] = api.bulletcast(
bullet,
pos1, vector.offset(pos2,
math.random(-bullet.spread, bullet.spread),
math.random(-bullet.spread, bullet.spread),
math.random(-bullet.spread, bullet.spread)
),
objects, liquids
)
end
return rays
end

View file

@ -0,0 +1,42 @@
local api = {}
local MODNAME = minetest.get_current_modname()
rawset(_G, MODNAME, api)
local files = {
"bullet.lua",
"ammo.lua"
}
for _, file in ipairs(files) do
dofile(minetest.get_modpath(MODNAME).."/"..file)
end
local checking = {}
-- Returns false if the automatic timer is currently running, returns true otherwise
function api.enable_automatic(fire_interval, itemstack, user)
local pname = user:get_player_name()
if checking[pname] then return false end
checking[pname] = minetest.after(fire_interval, function()
checking[pname] = nil
if user and user:get_player_control().LMB then
local wielded = user:get_wielded_item()
if wielded:get_name() == itemstack:get_name() then
user:set_wielded_item(itemstack:get_definition().on_use(wielded, user, {type = "nothing"}) or wielded)
end
end
end)
return true
end
minetest.register_on_leaveplayer(function(player)
local pname = player:get_player_name()
if checking[pname] then
checking[pname]:cancel()
end
end)

View file

@ -0,0 +1,2 @@
name = rawf