[Support] Get weapon category from weapon array
-
I have the following matrix, where all the weapons are, in which I would like a function to which I give the weapon and it returns the category
level.WeaponArray["Assault Rifle"][0] = "tar21_mp"; level.WeaponArray["Assault Rifle"][1] = "type95_mp"; level.WeaponArray["Assault Rifle"][2] = "sig556_mp"; level.WeaponArray["Assault Rifle"][3] = "sa58_mp"; level.WeaponArray["Assault Rifle"][4] = "hk416_mp"; level.WeaponArray["Assault Rifle"][5] = "scar_mp"; level.WeaponArray["Assault Rifle"][6] = "saritch_mp"; level.WeaponArray["Assault Rifle"][7] = "xm8_mp"; level.WeaponArray["Assault Rifle"][8] = "an94_mp"; level.WeaponArray["Assault Rifle"][9] = "peacekeeper_mp"; level.WeaponArray["Shotgun"][0] = "870mcs_mp"; level.WeaponArray["Shotgun"][1] = "saiga12_mp"; level.WeaponArray["Shotgun"][2] = "ksg_mp"; level.WeaponArray["Shotgun"][3] = "srm1216_mp"; level.WeaponArray["LMG"][0] = "mk48_mp"; level.WeaponArray["LMG"][1] = "qbb95_mp"; level.WeaponArray["LMG"][2] = "lsat_mp"; level.WeaponArray["LMG"][3] = "hamr_mp"; level.WeaponArray["SMG"][0] = "mp7_mp"; level.WeaponArray["SMG"][1] = "pdw57_mp"; level.WeaponArray["SMG"][2] = "vector_mp"; level.WeaponArray["SMG"][3] = "insas_mp"; level.WeaponArray["SMG"][4] = "qcw05_mp"; level.WeaponArray["SMG"][5] = "evoskorpion_mp"; level.WeaponArray["Sniper"][0] = "svu_mp"; level.WeaponArray["Sniper"][1] = "dsr50_mp"; level.WeaponArray["Sniper"][2] = "ballista_mp"; level.WeaponArray["Sniper"][3] = "as50_mp"; level.WeaponArray["Pistol"][0] = "fiveseven_mp"; level.WeaponArray["Pistol"][1] = "fnp45_mp"; level.WeaponArray["Pistol"][2] = "beretta93r_mp"; level.WeaponArray["Pistol"][3] = "judge_mp"; level.WeaponArray["Pistol"][4] = "kard_mp"; level.WeaponArray["Launcher"][0] = "smaw_mp"; level.WeaponArray["Launcher"][1] = "usrpg_mp"; level.WeaponArray["Launcher"][2] = "fhj18_mp"; level.WeaponArray["Special"][0] = "crossbow_mp"; level.WeaponArray["Special"][1] = "knife_ballistic_mp"; level.WeaponArray["Special"][2] = "knife_held_mp"; level.WeaponArray["Lethal"][0] = "frag_grenade_mp"; level.WeaponArray["Lethal"][1] = "hatchet_mp"; level.WeaponArray["Lethal"][2] = "sticky_grenade_mp"; level.WeaponArray["Lethal"][3] = "satchel_charge_mp"; level.WeaponArray["Lethal"][4] = "bouncingbetty_mp"; level.WeaponArray["Lethal"][5] = "claymore_mp"; level.WeaponArray["Tactical"][0] = "flash_grenade_mp"; level.WeaponArray["Tactical"][1] = "smoke_center_mp"; level.WeaponArray["Tactical"][2] = "concussion_grenade_mp"; level.WeaponArray["Tactical"][3] = "emp_grenade_mp"; level.WeaponArray["Tactical"][4] = "sensor_grenade_mp"; level.WeaponArray["Tactical"][5] = "pda_hack_mp"; level.WeaponArray["Tactical"][6] = "tactical_insertion_mp"; level.WeaponArray["Tactical"][7] = "proximity_grenade_mp";
-
Kalitos For example,
getWeaponCategory("tar21_mp")
would return"Assault Rifle"
? -
TheHiddenHour You read my mind.
How would you do it? -
Kalitos You could get the weapon name and check over each item in the array to see if it contains that weapon, but that's not very efficient lol. If I were to write a system where I needed to know what category a weapon was using strings like "Assault Rifle" or "Shotgun", I would do something like this:
getWeaponClass(weapon)
is a function that does what the name says, it gets the class of a weapon. It returns strings like"weapon_sniper"
, or"weapon_smg"
iirc.Instead of writing out an array of weapons, I would just make a function like this:
getWeaponCategory(weapon) { weap_class = getWeaponClass(weapon); switch(weap_class) { case "weapon_sniper": return "Sniper"; case "weapon_smg": return "SMG"; case "weapon_rifle": return "Assault Rifle"; // etc, etc, etc... } }
The other method I mentioned would allow you to have your own custom categories however, which is one of the downfalls of this approach.
Just for shits and giggles, here's how I'd do the first method:
getWeaponCategory(weapon) { weapon_arrs = strTok("Assault Rifle;Shotgun;LMG;SMG;Sniper;Pistol;Launcher;Special;Lethal;Tactical", ";"); foreach(arr in weapon_arrs) { if(isInArray(level.WeaponArray[arr], weapon)) { return arr; } } return "unknown_category"; }
-
TheHiddenHour Good answer. I agree with you.
I will use the existing function
And I will change the array names I showed to match this function:getWeaponCategory(weapon) { weap_class = getWeaponClass(weapon); switch(weap_class) { case "weapon_sniper": return "Sniper"; case "weapon_smg": return "SMG"; case "weapon_rifle": return "Assault Rifle"; // etc, etc, etc... } }
-
Kalitos You might want to do some testing with
getWeaponClass()
though, I don't know the exact strings it returns. Do a test with an AR, an SMG, a shotgun, etc and see what it returns.