Do i have to have three seperate files for my sweps lua?
4 replies, posted
Hello, i made a swep, and its pretty cool, but i get clientside errors when playing on multiplayer. I have all of the lua code in one file which is named [QUOTE]weapon_Maglite[/QUOTE]. Do i have to split some of this up into cl_init.lua init.lua and shared.lua? If so what would i need to put in their own files?
Here is the console error: Again i only get this error in multiplayer.
[QUOTE] [Maglite Launcher] lua/weapons/weapon_maglite.lua:54: attempt to call field 'Create' (a nil value)
1. ThrowLight - lua/weapons/weapon_maglite.lua:54
2. unknown - lua/weapons/weapon_maglite.lua:35
[/QUOTE]
Here is my code:[CODE] SWEP.PrintName = "Maglite Launcher"
SWEP.Author = "MagliteUSA"
SWEP.Instructions = "left click and hold to fire an endless stream of Flashlights"
SWEP.Spawnable = true
SWEP.AdminOnly = true
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = true
SWEP.Primary.Ammo = "none"
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
SWEP.Weight = 18
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
SWEP.Icon = "materials/entities/weapons.png"
SWEP.Slot = 1
SWEP.SlotPos = 2
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = true
SWEP.ViewModel = "models/c_flashlight_zm.mdl"
SWEP.WorldModel = "models/w_flashlight_zm.mdl"
if(CLIENT) then
SWEP.WepSelectIcon = surface.GetTextureID( "VGUI/weapon_Maglite" )
end
local ShootSound = Sound( "weapons/Impact_Bund.mp3" )
function SWEP:PrimaryAttack()
self.Weapon :SetNextPrimaryFire( CurTime() + 0.07 )
self:ThrowLight( "models/props_junk/gascan001a.mdl" )
end
function SWEP:SecondaryAttack()
self:ThrowLight( "Models/maxofs2d/lamp_flashlight.mdl" )
end
function SWEP:ThrowLight( lamp_flashlight )
self:EmitSound( ShootSound )
if ( client ) then return end
local ent = ents.Create( "prop_physics" )
if ( !IsValid( ent ) ) then return end
ent:SetModel( "Models/w_flashlight_zm.mdl" )
ent:SetPos( self.Owner:EyePos() + ( self.Owner:GetAimVector() * 16 ) )
ent:SetAngles( self.Owner:EyeAngles() )
ent:Spawn()
local phys = ent:GetPhysicsObject()
if ( !IsValid( phys ) ) then ent :Remove() return end
local velocity = self.Owner:GetAimVector()
velocity = velocity * 99999999990
velocity = velocity + ( VectorRand() * 10 )
phys:ApplyForceCenter( velocity )
cleanup.Add(self.Owner, "props", ent )
undo.Create( "ThrowLight" )
undo.AddEntity( ent )
undo.SetPlayer( self.Owner )
undo.Finish()
end
[/CODE]
Your problem is your if-statement: CLIENT is the clientside global. Lua is case-sensitive for variables.
How would i be able to fix it? copy that section and change it to if server, then paste it in there somewhere?
[QUOTE=Maglite;52246022]How would i be able to fix it? copy that section and change it to if server, then paste it in there somewhere?[/QUOTE]
[B][I]Bruh[/I][/B]
Change 'client' to 'CLIENT'
lol thx
Sorry, you need to Log In to post a reply to this thread.