Difference between revisions of "Module:DetectWeaponType"
Jump to navigation
Jump to search
m |
(use this module for check weapon type) |
||
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, [firerate|reload|minspread|maxspread] = medgun | |||
firerate|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.GetWeaponType( frame ) | function p.GetWeaponType( frame ) | ||
-- Check if frame exists (to avoid errors) -- | |||
if not frame then return end | if not frame then return end | ||
if not frame.args then return end | |||
-- Check if "forcereturn" exists, if so, it will return itself. | |||
if frame.args["forcereturn"] then return frame.args["forcereturn"] end | if frame.args["forcereturn"] then return frame.args["forcereturn"] end | ||
if frame.args["impactdelay"] or frame.args["range"] or frame.args["knockback"] then | -- It should happen on starting, since it includes "and" comparison | ||
-- Check if is a melee with healing. | |||
if frame.args["healing"] and (frame.args["impactdelay"] or frame.args["range"] or frame.args["knockback"]) then | |||
return "medmelee" | |||
-- Check if is melee. | |||
elseif frame.args["impactdelay"] or frame.args["range"] or 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 frame.args["healing"] and (frame.args["firerate"] or frame.args["reload"] or frame.args["minspread"] or frame.args["maxspread"]) then | |||
return "medgun" | |||
-- Check if is a gun. | |||
elseif frame.args["firerate"] or frame.args["reload"] or frame.args["minspread"] or frame.args["maxspread"] then | |||
return "gun" | return "gun" | ||
-- Since all conditions above haven been parsed, then it will check if repair | |||
elseif frame.args["repair"] then | elseif frame.args["repair"] then | ||
return " | return "repairtool" | ||
elseif frame.args["healing"] then | elseif frame.args["healing"] then | ||
return "medtool" | return "medtool" | ||
-- If all conditions fail, it will check "else". | |||
else | else | ||
return frame.args["else"] or | return frame.args["else"] or "unknown" | ||
end | end | ||
end | end | ||
return p | return p |
Revision as of 17:39, 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, [firerate|reload|minspread|maxspread] = medgun firerate|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.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 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 frame.args["healing"] and (frame.args["impactdelay"] or frame.args["range"] or frame.args["knockback"]) then return "medmelee" -- Check if is melee. elseif frame.args["impactdelay"] or frame.args["range"] or frame.args["knockback"] then return "melee" -- The same as above, but if is a gun with healing. elseif frame.args["healing"] and (frame.args["firerate"] or frame.args["reload"] or frame.args["minspread"] or frame.args["maxspread"]) then return "medgun" -- Check if is a gun. elseif frame.args["firerate"] or frame.args["reload"] or frame.args["minspread"] or frame.args["maxspread"] then return "gun" -- Since all conditions above haven been parsed, then it will check if repair elseif frame.args["repair"] then return "repairtool" elseif frame.args["healing"] then return "medtool" -- If all conditions fail, it will check "else". else return frame.args["else"] or "unknown" end end return p