Difference between revisions of "Module:DetectWeaponType"
Jump to navigation
Jump to search
(Created page with "--Module for detecting weapon type WIP local p = {} -- p stands for package function p.GetWeaponType( frame ) if frame then else return end if frame.args...") |
|||
(6 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
--[[ | --[[ | ||
Module for detecting weapon type | 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 | 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 ) | function p.GetWeaponType( frame ) | ||
if frame then | |||
if frame.args["impactdelay"] or frame.args["range"] or frame.args["knockback"] then | -- 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" | return "melee" | ||
elseif frame.args["reload"] or frame.args["minspread"] or frame.args["maxspread"] then | -- 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" | return "gun" | ||
-- Since all conditions above haven been parsed, then it will check if repair | |||
elseif p._isValid(frame.args["repair"]) then | |||
elseif | return "repairtool" | ||
elseif p._isValid(frame.args["healing"]) then | |||
elseif | |||
return "medtool" | return "medtool" | ||
-- If all conditions fail, it will check "else". | |||
else | |||
return p._isValid(frame.args["else"]) or "unknown" | |||
end | end | ||
end | end | ||
return p | return p |
Latest revision as of 19:13, 23 December 2021
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