• Clientside hooks not working
    5 replies, posted
Title says it all. None of my clientside hooks are being called. shared.lua: [code]SWEP.Author = "BackwardSpy" SWEP.Contact = "Don't" SWEP.Purpose = "Destruction" SWEP.Instructions = "Aim away from face" SWEP.Spawnable = true SWEP.AdminSpawnable = true SWEP.ViewModel = "models/Weapons/v_portalgun.mdl" SWEP.WorldModel = "models/Weapons/w_suitcase_passenger.mdl" SWEP.Primary.Clipsize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "none" SWEP.Secondary.Clipsize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" if(SERVER) then SWEP.Weight = 10 SWEP.AutoSwitchTo = true SWEP.AutoSwitchFrom = true function SWEP:Initialize() self:SetWeaponHoldType("melee") end end if(CLIENT) then SWEP.PrintName = "PARTICLE CANNON" SWEP.Slot = 4 SWEP.SlotPos = 2 SWEP.DrawAmmo = true SWEP.DrawCrosshair = true end function SWEP:PrimaryAttack() print("CLIENT:") print(CLIENT) print("SERVER:") print(SERVER) end[/code] init.lua: [code]include('shared.lua') AddCSLuaFile("shared.lua") AddCSLuaFile("cl_init.lua")[/code] cl_init.lua: [code]include('shared.lua')[/code] Any help is appreciated.
I think it's probably because you don't have any hooks.
If I remember correctly, many shared SWEP hooks aren't called clientside when playing on singleplayer. If you really need the client to do something, use [url=http://wiki.garrysmod.com/?title=User_Messages]usermessages[/url] and [b][url=wiki.garrysmod.com/?title=G.SinglePlayer]SinglePlayer[img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] to check whether you need to send them or not.
_Kilburn: Ok, I thought it may be something like that. Didn't know how to fix it though! Problem is, I want to use a particle emitter, which is only clientside. How can I get it working in singleplayer?
[code] if SinglePlayer( ) then self:CallOnClient( "thisfunc", "" ) end [/code] For no args ( you still need to give at least one or the function errors last I used it ) Eg, [code] function SWEP:PrimaryAttack( ) if SinglePlayer( ) then self:CallOnClient( "PrimaryAttack", "" ) end end [/code] I used to use SendLua in this case until I found an alternative better than sticking a bunch of usermessage hooks on the weapon, which happened to be this.
Ah thanks, that seems very useful :D I'll give it a go, and post back with results.
Sorry, you need to Log In to post a reply to this thread.