• Need help fetching information from SWEPS
    2 replies, posted
Hello friends! I know almost nothing, I will admit, and so it is to you I come for help. I'm trying to fetch the AmmoType and DefaultClip size from a weapon, but I'm getting a couple of errors. This is my script, currently: [CODE]local wep = 'weapon_ttt_walther' local ammoamt = wep.Primary.DefaultClip local ammotype = wep.Primary.AmmoType hook.Add("PlayerSpawn", "playerspawnweapon", function(ply) GivePlayerWeapon(ply,wep) end) function GivePlayerWeapon(ply,wep) if not ply:IsSpec() then ply:Give(wep) ply:SelectWeapon(wep) ply:GiveAmmo( ammoamt, true ) end end[/CODE] It spawns the weapon, but I get no additional ammo and it returns this error: [CODE][ERROR] lua/autorun/weapons.lua:2: bad key to string index (number expected, got string) 1. error - [C]:-1 2. __index - lua/includes/extensions/string.lua:310 3. unknown - lua/autorun/weapons.lua:2 [/CODE] Any help would be greatly appreciated!
You'll want to use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/weapons/Get]weapons.Get[/url]; [lua] local wepClass = 'weapon_ttt_walther' local wep = weapons.Get(wepClass) local ammoamt = wep.Primary.DefaultClip local ammotype = wep.Primary.AmmoType [/lua]
Thank you so much for pointing me in the right direction. After a little bit of fiddling, it works.
Sorry, you need to Log In to post a reply to this thread.