• How to write the ActiveWeapon?
    4 replies, posted
Hi, me agian, still making a gui. I was wondering how I could go about writing a current weapon. I tried [code] ActiveWeapon = LocalPlayer():GetActiveWeapon() print(tostring(ActiveWeapon)) [/code] and that just gave me this. Weapon [81][weapon_physgun] So is there anyway to do this? Thanks in advance! :)
:GetClass() writes weapon_physgun, edit: [LUA] ActiveWeapon = weapons.GetStored( LocalPlayer():GetActiveWeapon():GetClass() ).PrintName; [/LUA]
I copy pasted that code, I get a attempt to Index nil value err. [code] [ERROR] addons/mg's hud/lua/darkrp_modules/hudreplacement/cl_hudreplacement.lua:119: attempt to index a nil value 1. v - addons/mg's hud/lua/darkrp_modules/hudreplacement/cl_hudreplacement.lua:119 2. unknown - lua/includes/modules/hook.lua:82 [/code]
[QUOTE=WolfNinja2;42460214]I copy pasted that code, I get a attempt to Index nil value err. [code] [ERROR] addons/mg's hud/lua/darkrp_modules/hudreplacement/cl_hudreplacement.lua:119: attempt to index a nil value 1. v - addons/mg's hud/lua/darkrp_modules/hudreplacement/cl_hudreplacement.lua:119 2. unknown - lua/includes/modules/hook.lua:82 [/code][/QUOTE] To me, it seems to work for every weapon except for physgun and gravity gun, so I guess you can use this, but it's not a great solution: [LUA] ActiveWeapon = LocalPlayer():GetActiveWeapon():GetClass(); if ( !weapons.GetStored( ActiveWeapon ) ) then weaponName = ActiveWeapon; else weaponName = weapons.GetStored( ActiveWeapon ).PrintName; end [/LUA] then weaponName is either weapon_physgun or for example .357 Magnum
Your beautiful. Thanks so much! SOLVED!
Sorry, you need to Log In to post a reply to this thread.