• Lua Code Problem
    15 replies, posted
Hi, I just finished a simple SWep. I tried it out and it worked. Then i wanted to add a function that, when you press Primary/Secondary Fire + E (Use), switches between automatic firing for Primary/Secondary Fire. i did that but as i wanted to try it ingame, the SWep didn't show up in the menu. :( here is the code of the function: Primary: [lua]function SWEP:PrimaryAttack() if ( !self:CanPrimaryAttack() ) then return end //SWEP Mode if self.Owner:KeyDown(IN_USE) then if self.Primary.Automatic == false then self.Primary.Automatic = true self.Weapon:EmitSound("weapons/smg1/switch_burst.wav") else self.Primary.Automatic = false self.Weapon:EmitSound("weapons/smg1/switch_single.wav") end end end[/lua] Secondary: [lua]function SWEP:SecondaryAttack() if ( !self:CanPrimaryAttack() ) then return end //SWEP Mode if self.Owner:KeyDown(IN_USE) then if self.Secondary.Automatic == false then self.Secondary.Automatic = true self.Weapon:EmitSound("weapons/smg1/switch_burst.wav") else self.Secondary.Automatic = false self.Weapon:EmitSound("weapons/smg1/switch_single.wav") end end end[/lua] Is there something wrong?
Any errors?
[QUOTE=Willox;24588218]Any errors?[/QUOTE] nope this is what happened when i tried to run the shared.lua: [code]] lua_run "weapons/bestgun2/shared.lua" > "weapons/bestgun2/shared.lua"... :1: unexpected symbol near '"weapons/bestgun2/shared.lua"'[/code]
That... is called an error.
hmmmmmmmmmmm , why not use values to know witch firemode to use. and change evry time he presses use?
[QUOTE=dingusnin;24589559]hmmmmmmmmmmm , why not use values to know witch firemode to use. and change evry time he presses use?[/QUOTE] Translation : Thats quite a problem you got there , But what about using a true and false value and evertime you need to switch mode, do this : [LUA] local firemode = false function change_firmode() firemode = !firemode end function getfiremode() if firemode = true then return "firemode1" else return "firmore2" end end [/LUA]
[QUOTE=>_> Ubercake;24588324]nope this is what happened when i tried to run the shared.lua: [code]] lua_run "weapons/bestgun2/shared.lua" > "weapons/bestgun2/shared.lua"... :1: unexpected symbol near '"weapons/bestgun2/shared.lua"'[/code][/QUOTE] you're doing it wrong. lua_run is for lua commands. try doing "lua_openscript "weapons/bestgun2/shared.lua""
[QUOTE=PortalGod;24593241]you're doing it wrong. lua_run is for lua commands. try doing "lua_openscript "weapons/bestgun2/shared.lua""[/QUOTE] This is what happens: [code]] lua_openscript "weapons/bestgun2/shared.lua" Running script weapons/bestgun2/shared.lua... lua\weapons\bestgun2\shared.lua:166: '<eof>' expected near 'end'[/code]
Sounds like you put an extra end in your script.
snipp
[QUOTE=adorablepuppy;24594989]Sounds like you put an extra end in your script.[/QUOTE] I removed the extra end and this is what happened: [code] ] lua_openscript "weapons/bestgun2/shared.lua" Running script weapons/bestgun2/shared.lua... lua\weapons\bestgun2\shared.lua:1: attempt to index global 'SWEP' (a nil value)[/code]
Executing the SWEP script isn't what you want. If you want to give the gun to yourself, do "give bestgun2". If you want to apply the changes to the SWEP after editing the script while the game is running, do "lua_reloadents".
[QUOTE=>_> Ubercake;24588324]nope this is what happened when i tried to run the shared.lua: [code]] lua_run "weapons/bestgun2/shared.lua" > "weapons/bestgun2/shared.lua"... :1: unexpected symbol near '"weapons/bestgun2/shared.lua"'[/code][/QUOTE] [lua]lua_run include("weapons/bestgun2/shared.lua")[/lua]
Use lua_reloadents for weapon reloading.
ok it worked but the SWep does not switch between automatic/non-automatic... but i hear the sound
Sorry, you need to Log In to post a reply to this thread.