• Scripted weapon freezes server/client
    0 replies, posted
Hi there. I need some help, because I have hit a brick wall trying to fix this. I am trying to code a crowbar with altered damage and a method of slaying the player if they are outside. The problem: No matter what I try... either the server or the client will never load the game... while i use that god forsaken loop. [CODE]if SERVER then AddCSLuaFile ("shared.lua") SWEP.Weight = 5 SWEP.AutoSwitchTo = false SWEP.AutoSwitchFrom = false elseif CLIENT then SWEP.PrintName = "Demon Crowbar (v 0.4a)" SWEP.Slot = 0 SWEP.SlotPos = 0 SWEP.DrawAmmo = false SWEP.DrawCrosshair = false end SWEP.Author = "Super Rainbow Dash!" SWEP.Contact = "nathan.rockman@gmail.com" SWEP.Purpose = "Offers a standard crowbar for sewer demons on MLSRP, except it kills them when they are on the surface." SWEP.Instructions = "Left click for a fast attack of 10 damage. Right click for a slow attack of 40 damage." SWEP.Category = "Coded for MLSRP" SWEP.Spawnable = true -- Whether regular players can see it SWEP.AdminSpawnable = true -- Whether Admins/Super Admins can see it SWEP.ViewModel = "models/weapons/v_crowbar.mdl" -- This is the model used for clients to see in first pony. SWEP.WorldModel = "models/weapons/w_crowbar.mdl" -- This is the model shown to all other clients and in third-pony. SWEP.Primary.Damage = 10 SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Automatic = true SWEP.Primary.Delay = 0.5 SWEP.Primary.Ammo = "none" SWEP.Secondary.Damage = 40 SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = true SWEP.Secondary.Ammo = "none" SWEP.Secondary.Delay = 3 local sound_single = Sound("Weapon_Crowbar.Single") local sound_open = Sound("DoorHandles.Unlocked3") i = 0 function SWEP:Reload() end function SWEP:Think() end function SWEP:PrimaryAttack() self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay ) if not IsValid(self.Owner) then return end if self.Owner.LagCompensation then -- for some reason not always true self.Owner:LagCompensation(true) end local spos = self.Owner:GetShootPos() local sdest = spos + (self.Owner:GetAimVector() * 70) local tr_main = util.TraceLine({start=spos, endpos=sdest, filter=self.Owner, mask=MASK_SHOT_HULL}) local hitEnt = tr_main.Entity self.Weapon:EmitSound(sound_single) if IsValid(hitEnt) or tr_main.HitWorld then self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER ) if not (CLIENT and (not IsFirstTimePredicted())) then local edata = EffectData() edata:SetStart(spos) edata:SetOrigin(tr_main.HitPos) edata:SetNormal(tr_main.Normal) --edata:SetSurfaceProp(tr_main.MatType) --edata:SetDamageType(DMG_CLUB) edata:SetEntity(hitEnt) if hitEnt:IsPlayer() or hitEnt:GetClass() == "prop_ragdoll" then util.Effect("BloodImpact", edata) -- does not work on players rah --util.Decal("Blood", tr_main.HitPos + tr_main.HitNormal, tr_main.HitPos - tr_main.HitNormal) -- do a bullet just to make blood decals work sanely -- need to disable lagcomp because firebullets does its own self.Owner:LagCompensation(false) self.Owner:FireBullets({Num=1, Src=spos, Dir=self.Owner:GetAimVector(), Spread=Vector(0,0,0), Tracer=0, Force=1, Damage=0}) else util.Effect("Impact", edata) end end else self.Weapon:SendWeaponAnim( ACT_VM_MISSCENTER ) end end function SWEP:SecondaryAttack() end if CLIENT then for i = 0, 1, 0 do function CheckSky() local tr = LocalPlayer():GetPos() local tracedata = {} tracedata.start = tr + Vector(0,0,0) tracedata.endpos = tr + Vector(0,0,50000) tracedata.filter = ents.GetAll() local trace = util.TraceLine(tracedata) if trace.HitSky == true then hitsky = true else hitsky = false end -- if hitsky == true then -- self:SetNextPrimaryFire(CurTime() + self.Primary.Delay) -- self:EmitSound( ShootSound1 ) -- self:EmitSound( ShootSound2 ) -- else -- self:EmitSound( FailSound ) -- end // The rest is only done on the server if (!SERVER) then return end if hitsky == true then RunConsoleCommand("say", "kill") i = 1 end --function() CheckSky() end end end end[/CODE] There are a number of things wrong with that already, i just need someone to tell me how i can get that loop to stop activating before the client has connected. And yes, i want it to be an infinite loop. or at least i think i do. Also if you are feeling generous enough, perhaps you could be so kind as to make my crowbar actually do damage? I'm not asking anyone to do it, but I would appreciate it if someone did do it. EDIT: I should point out i stole the code for the attack from the TTT crowbar. Simply a place holder at this point in time, if anything. I was filling the attack section because my theory of "Leave it blank and it should work fine" was delusional at best.
Sorry, you need to Log In to post a reply to this thread.