Im working on dark rp class in which the player is slender man. I’m trying to create a SWEP that will make slendy appear in front of a victim/target and be seen by no one else. However, I’m currently stuck due to my lack of knowledge on how clients and servers interact. I have the general just but im struggling to understand when a client side code is being executed and when server side code is being executed and how the two work together.
This is my attempt but you’ll see that i thought parenting would attach an ent to its target client so that it would only be rendered for him
I thought about it as well as tested some thing and found out thats not how it works.
if SERVER then -- This is where the init.lua stuff goes. AddCSLuaFile ("shared.lua") SWEP.Weight = 1 SWEP.AutoSwitchTo = false SWEP.AutoSwitchFrom = false elseif CLIENT then -- This is where the cl_init.lua stuff goes --The name of the SWep, as appears in the weapons tab in the spawn menu(Q Menu) SWEP.PrintName = "Slender SWEP" --Sets the position of the weapon in the switching menu --(appears when you use the scroll wheel or keys 1-6 by default) SWEP.Slot = 4 SWEP.SlotPos = 1 --Sets drawing the ammuntion levels for this weapon SWEP.DrawAmmo = false --Sets the drawing of the crosshair when this weapon is deployed SWEP.DrawCrosshair = false language.Add("Undone_Thrown_SWEP_Entity","Undone Thrown SWEP Entity") end SWEP.Author = "gononono64" SWEP.Contact = " " SWEP.Purpose = "This SWEP is for the slender class." SWEP.Instructions = "Left click uncloak for a ply. " --The category that you SWep will be shown in, in the Spawn (Q) Menu --(This can be anything, GMod will create the categories for you) SWEP.Category = "Slender" SWEP.Spawnable = true -- Whether regular players can see it SWEP.AdminSpawnable = true -- Whether Admins/Super Admins can see it SWEP.ViewModel = "models/weapons/v_hands.mdl" -- This is the model used for clients to see in first person. SWEP.WorldModel = "" -- This is the model shown to all other clients and in third-person. 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" --When the script loads, the sound ''Metal.SawbladeStick'' will be precached, local ShootSound = Sound("Metal.SawbladeStick") function GhostSlendy( ply, target ) local c_Model = ents.CreateClientProp() c_Model:SetPos( ply:GetPos() ) c_Model:SetModel( "models/props_borealis/bluebarrel001.mdl" ) c_Model:SetParent( target ) --this doesnt do what i was hoping it would do :( c_Model:Spawn() end function SWEP:Reload() end function SWEP:Think() end function SWEP:Scare () --Get an eye trace. This basically draws an invisible line from --the players eye. local ply = self.Owner local tr = ply:GetEyeTrace() local target = nil if (tr.Entity:IsPlayer())then target = tr.Entity target:EmitSound(ShootSound) --will play spooky noises GhostSlendy(ply, target) else GhostSlendy(ply, ply) end end -- primary attack function SWEP:PrimaryAttack() self:Scare() end --secondary attack function SWEP:SecondaryAttack() self:Scare() end
A lot of this is copy pasta. Sorry I’m just learning
If anyone can help me better understand this I would really appreciate it.