• Executing both server side code and client side code on a SWEP?
    6 replies, posted
Im trying to make a swep which prints something to the players chat locally client side. I have tried this: [lua] if SERVER then AddCSLuaFile("shared.lua") end if CLIENT then SWEP.PrintName = "My first swep" SWEP.Slot = 1 SWEP.SlotPos = 6 SWEP.DrawAmmo = false SWEP.DrawCrosshair = false end SWEP.Author = "Chizbang" SWEP.Instructions = "Test" SWEP.Contact = "" SWEP.Purpose = "" SWEP.ViewModel = Model("models/weapons/v_hands.mdl") SWEP.WorldModel = "models/props_lab/huladoll.mdl" SWEP.ViewModelFOV = 62 SWEP.ViewModelFlip = false SWEP.AnimPrefix = "rpg" SWEP.Spawnable = false SWEP.AdminSpawnable = true SWEP.Sound = "doors/door_latch3.wav" SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = 0 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "" SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = 0 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "" function SWEP:Initialize() self:SetWeaponHoldType("normal") end function SWEP:Deploy() local owner = self.Owner self:SendWeaponAnim(ACT_VM_DRAW) return true end function SWEP:PrimaryAttack() if CLIENT then self.Owner:ChatPrint("Blahy") end -- server side works finer end function SWEP:SecondaryAttack() if CLIENT then self.Owner:ChatPrint("Blah") end -- server side code works totaly fine end function SWEP:Holster(wep) -- server side works fdine end [/lua] None of the client side stuff works at all. The files name is shared.lua if that helps. If anyone could shed some light on this, id really appreciate it
instead of self.Owner use LocalPlayer():ChatPrint().
Tried that aswell to no avail :c
What file is it in ?
darkrpcustomaddon\lua\weapons\mfw\shared.lua
Make it darkrpcustomaddon\lua\weapons\myweapon.lua, then [code] if SERVER then AddCSLuaFile() end[/code] And launch the game in local multiplayer. In single player, most SWEP functions are not called on client, because there is no need for them do. In multiplayer, they are, for prediction.
Also, you did AddCSLuaFile, but you didn't really do if CLIENT then include('shared.lua') end
Sorry, you need to Log In to post a reply to this thread.