Module:DetectWeaponType
Jump to navigation
Jump to search
This module is used by Template:Infobox_Weapon, this will return the weapon type if one of values if filled.
Usage
| Parameter | Result |
|---|---|
| reload minspread maxspread |
gun |
| impactdelay range knockback |
melee |
| any gun value + healing | medgun |
| any melee value + healing | medmelee |
| healing (without healing values) | medtool |
| repair | repairtool |
| else (If any of values above fails) | unknown |
| forcereturn | (the value of forcereturn is returned always.) |
--[[
Module for detecting weapon type
Parameters:
healing, [impactdelay|range|knockback] = medmelee
impactdelay|range|knockback = melee
healing, [reload|minspread|maxspread] = medgun
reload|minspread|maxspread = gun
healing = medtool (if medmelee and medgun failed.)
repair = repairtool
Others parameters:
forcereturn: force the function to return the value inputted ; e.g.: p.GetWeaponType({args={healing=30,impactdelay=30,repair=30,forcereturn="medtool"}})
else: happens if all conditions fail; by default "unknown"
]]
local p = {} -- p stands for package
function p._isValid(v)
if v ~= "" and string.len( v or "") >= 1 then return true end
return false
end
function p.GetWeaponType( frame )
-- Check if frame exists (to avoid errors) --
if not frame then return end
if not frame.args then return end
-- Check if "forcereturn" exists, if so, it will return itself.
if p._isValid(frame.args["forcereturn"]) then return frame.args["forcereturn"] end
-- It should happen on starting, since it includes "and" comparison
-- Check if is a melee with healing.
if p._isValid(frame.args["healing"]) and (p._isValid(frame.args["impactdelay"]) or p._isValid(frame.args["range"]) or p._isValid(frame.args["knockback"])) then
return "medmelee"
-- Check if is melee.
elseif p._isValid(frame.args["impactdelay"]) or p._isValid(frame.args["range"]) or p._isValid(frame.args["knockback"]) then
return "melee"
-- The same as above, but if is a gun with healing.
elseif p._isValid(frame.args["healing"])
and ( p._isValid(frame.args["minspread"]) or
p._isValid(frame.args["reload"]) or
p._isValid(frame.args["maxspread"]) "") then
return "medgun"
-- Check if is a gun.
elseif p._isValid(frame.args["minspread"]) or p._isValid(frame.args["reload"]) or p._isValid(frame.args["maxspread"]) then
return "gun"
-- Since all conditions above haven been parsed, then it will check if repair
elseif p._isValid(frame.args["repair"]) then
return "repairtool"
elseif p._isValid(frame.args["healing"]) then
return "medtool"
-- If all conditions fail, it will check "else".
else
return p._isValid(frame.args["else"]) or "unknown"
end
end
return p