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