• Help with weapon classes
    14 replies, posted
So what I am trying to do is set 2 list of weapons and tell if the player has any of the weapon's and if so return false like [lua] pistol = "PISTOL1" or "PISTOL2" or "PISTOL3" rifles = "rifles1" or "rifles2" or "rifles3" if ply:HasWeapon(rifles) then return false end if ply:HasWeapon(pistole) then return false end [/lua] This wont work . Its an example of what I am trying to do . Can someone show me how to do this please.
Are you trying to make a blacklist for weapons? If yes, all you have to do is use a table with the indexes as the string name for the weapon class and make the value false. [lua] local Rifles = { ["weapon_rifle1"] = false, ["weapon_rifle2"] = false } return Rifles[wepClass] [/lua]
No what I am trying to so is check if a player has that weapon already and if so to return false . btw thank you so much for helping me in the past .I really appreciate it.
Then you can just do this if you have access to the weapon class which I'm assuming you should: [lua] return ply:HasWeapon(wepClass) [/lua] and no problem!
Yeah I did that and for some reason it will only see the first class.that's kinda where I am stuck at right now.so say like [lua] pistol = "PISTOL1" or "PISTOL2" or "PISTOL3" [/lua] it will only see pistol1 not 2 or 3
[QUOTE=gravelhunter;43068185]Yeah I did that and for some reason it will only see the first class.that's kinda where I am stuck at right now.so say like [lua] pistol = "PISTOL1" or "PISTOL2" or "PISTOL3" [/lua] it will only see pistol1 not 2 or 3[/QUOTE] Show all your code. Right now what you're doing doesn't make any sense.
[lua] function PlayerPickupWep( ply, weap ) local trace = util.QuickTrace( ply:GetShootPos(), ply:GetAimVector() * 1000, ply ) if ( CurTime() <= ( ply.weapSpawn or 0 ) ) then return end if ( !ply:KeyDown( IN_USE ) ) then return false end all_rif = "weapon_nc_ak47" or "weapon_nc_aug" or "weapon_nc_galil" or "weapon_nc_m249" or "weapon_nc_m4a1_us" or "weapon_nc_famas" all_pis = "weapon_nc_deserteagle" or "weapon_nc_glock18" or "weapon_nc_p228" or "weapon_nc_mac10" or "weapon_nc_p228" if ply:HasWeapon(all_rif) and trace.Entity:GetClass() == all_rif then return false end if ( !trace.Entity or !trace.Entity:IsValid() or trace.Entity != weap ) then return false end print(all_rif) -- only shows class "weapon_nc_ak47" end[/lua] don't lafe at me :(
You're not using the "or" operator correctly. Read through this and you should understand what you're doing wrong. [URL="http://www.lua.org/pil/3.3.html"]3.3 – Logical Operators[/URL]
[QUOTE=brandonj4;43068725]You're not using the "or" operator correctly. Read through this and you should understand what you're doing wrong. [URL="http://www.lua.org/pil/3.3.html"]3.3 – Logical Operators[/URL][/QUOTE] People often just assume behavior instead of research what something actually does specifically. Amateur mistake.
[QUOTE=EvacX;43069034]People often just assume behavior instead of research what something actually does specifically. Amateur mistake.[/QUOTE] Which is why I said he should read that page and hopefully he would understand that you would use a table for something like that. I even gave a straightforward example as-well [lua] local Rifles = { ["weapon_rifle1"] = false, ["weapon_rifle2"] = false } return Rifles[wepClass] [/lua]
I thought Entity:GetClass() only except strings no ??
I'm not sure how your weapon pickup mechanics work in your gamemode but this is what I'm assuming you could use: [lua] function PlayerPickupWep(ply, wep) return (CurTime() >= (ply.WepSpawn or 0)) and (ply:KeyDown(IN_USE)) and (!ply:HasWeapon(wep:GetClass())) end [/lua]
[QUOTE=brandonj4;43069163]Which is why I said he should read that page and hopefully he would understand that you would use a table for something like that. I even gave a straightforward example as-well [lua] local Rifles = { ["weapon_rifle1"] = false, ["weapon_rifle2"] = false } return Rifles[wepClass] [/lua][/QUOTE] I wasn't criticizing you.
[QUOTE=EvacX;43069905]I wasn't criticizing you.[/QUOTE] I know you aren't :v:
oh :v:
Sorry, you need to Log In to post a reply to this thread.