• Problem Scripting A Weapon (yeah, it's me... pls don't ignore)
    6 replies, posted
Hi, I was modifying that popular Black-Ops C4 SWEP, but when I run the game, I get this error: [ERROR] lua/weapons/bubstock9/shared.lua:197: function arguments expected near '='   1. unknown - lua/weapons/bubstock9/shared.lua:0 [ERROR] lua/weapons/bubstock9/shared.lua:197: function arguments expected near '='   1. unknown - lua/weapons/bubstock9/shared.lua:0 I've searched on Google for " function arguments expected near '=' ", but I can't find anything useful. Here's the code: AddCSLuaFile( "shared.lua" ) SWEP.Author = "Hoff (Modified by bubstock9)" SWEP.Instructions = "Fire to throw C4. Reload to detonate." SWEP.Category = "007" SWEP.Spawnable = true SWEP.AdminSpawnable = true SWEP.ViewModel = "models/hoff/weapons/seal6_c4/v_c4.mdl" SWEP.WorldModel = "models/hoff/weapons/seal6_c4/w_c4_0-5.mdl" SWEP.ViewModelFOV = 70 SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Automatic = true SWEP.Primary.Ammo = "slam" SWEP.Primary.Delay = 0.9 SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = true SWEP.Secondary.Ammo = "slam" SWEP.Secondary.Delay = 0.084 SWEP.Weight = 5 SWEP.AutoSwitchTo = true SWEP.AutoSwitchFrom = false SWEP.PrintName = "Ace's C4" SWEP.Slot = 1 SWEP.SlotPos = 1 SWEP.DrawAmmo = false SWEP.DrawCrosshair = false -- game.AddAmmoType( { -- name = "b9_c4", -- dmgtype = DMG_BULLET, -- tracer = TRACER_LINE, -- plydmg = 0, -- npcdmg = 0, -- force = 2000, -- minsplash = 10, -- maxsplash = 5 -- } ) hook.Add("Initialize","createc4convar",function() if ConVarExists( "c4_infinite" ) == false then CreateConVar("c4_infinite", 1)  end end) SWEP.Offset = { Pos = { Up = 0, Right = -2, Forward = 0, }, Ang = { Up = 0, Right = 0, Forward = -45, } } function SWEP:DrawWorldModel( ) local hand, offset, rotate if not IsValid( self.Owner ) then self:DrawModel( ) return end if not self.Hand then self.Hand = self.Owner:LookupAttachment( "anim_attachment_rh" ) end hand = self.Owner:GetAttachment( self.Hand ) if not hand then self:DrawModel( ) return end offset = hand.Ang:Right( ) * self.Offset.Pos.Right + hand.Ang:Forward( ) * self.Offset.Pos.Forward + hand.Ang:Up( ) * self.Offset.Pos.Up hand.Ang:RotateAroundAxis( hand.Ang:Right( ), self.Offset.Ang.Right ) hand.Ang:RotateAroundAxis( hand.Ang:Forward( ), self.Offset.Ang.Forward ) hand.Ang:RotateAroundAxis( hand.Ang:Up( ), self.Offset.Ang.Up ) self:SetRenderOrigin( hand.Pos + offset ) self:SetRenderAngles( hand.Ang ) self:DrawModel( ) end function SWEP:Deploy() --if !IsValid(self.Owner.C4s) then self.Owner.C4s = {} end end local reg = debug.getregistry() local GetVelocity = reg.Entity.GetVelocity local Length = reg.Vector.Length local GetAimVector = reg.Player.GetAimVector local inRun = false function SWEP:Think() vel = Length(GetVelocity(self.Owner)) if self.Owner:OnGround() then if !inRun and vel > 2.4 and self.Owner:KeyDown(IN_SPEED) then self.Weapon:SendWeaponAnim(ACT_VM_PULLPIN) inRun = true elseif( inRun and !self.Owner:KeyDown(IN_SPEED) ) then self:SendWeaponAnim(ACT_VM_IDLE) inRun = false end if self.Owner:KeyDown(IN_SPEED) and vel == 0 then self:SendWeaponAnim(ACT_VM_IDLE) inRun = false end end end   function SWEP:Equip(NewOwner) if self.Owner.C4s == nil then self.Owner.C4s = {} end if GetConVar("c4_infinite"):GetInt() == 0 then self.Owner:GiveAmmo(5,"slam") end end function SWEP:PrimaryAttack() if not IsFirstTimePredicted() then return end if GetConVar("c4_infinite"):GetInt() == 0 then if ( self:Ammo1() <= 0 ) then  return false end end self:SendWeaponAnim(ACT_VM_THROW) self:EmitSound("hoff/mpl/seal_c4/whoosh_00.wav") --self:TakePrimaryAmmo(1) local tr = self.Owner:GetEyeTrace() if SERVER then local ent = ents.Create("ace-c4") ent:SetPos(self.Owner:GetShootPos()) ent:SetAngles(Angle(1,0,0)) ent:Spawn() ent.C4Owner = self.Owner local phys = ent:GetPhysicsObject() phys:SetMass(0.6) local shot_length = tr.HitPos:Length() local aimvector = self.Owner:GetAimVector() -- phys:ApplyForceCenter (self.Owner:GetAimVector():GetNormalized() * math.pow (shot_length, 3)); -- phys:ApplyForceCenter(aimvector*500000) phys:ApplyForceCenter( self.Owner:GetAimVector()*1500) local angvel = Vector(0,math.random(-5000,-2000),math.random(-100,-900)) //The positive z coordinate emulates the spin from a right-handed overhand throw angvel:Rotate(-1*ent:EyeAngles()) angvel:Rotate(Angle(0,self.Owner:EyeAngles().y,0)) phys:AddAngleVelocity(angvel) --ent:SetVelocity(ent:GetForward()*50000 + ent:GetRight()*50 + ent:GetUp()*50) ent:SetGravity(50) table.insert( self.Owner.C4s, ent ) end if GetConVar("c4_infinite"):GetInt() == 0 then self.Owner:RemoveAmmo(1,"slam") end self:SetNextPrimaryFire(CurTime() + 1.1) self:SetNextSecondaryFire(CurTime() + 1.2) end function SWEP:SecondaryAttack() if not IsFirstTimePredicted() then return end if GetConVar("c4_infinite"):GetInt() == 0 then if ( self:Ammo1() <= 0 ) then  return false end end self:SendWeaponAnim(ACT_VM_THROW) self:EmitSound("hoff/mpl/seal_c4/whoosh_00.wav") --self:TakePrimaryAmmo(1) local tr = self.Owner:GetEyeTrace() if SERVER then local ent = ents.Create("ace-c4") ent:SetPos(self.Owner:GetShootPos()) ent:SetAngles(Angle(1,0,0)) ent:Spawn() ent:C4Owner = self.Owner local phys = ent:GetPhysicsObject() phys:SetMass(0.6) local shot_length = tr.HitPos:Length() local aimvector = self.Owner:GetAimVector() -- phys:ApplyForceCenter (self.Owner:GetAimVector():GetNormalized() * math.pow (shot_length, 3)); -- phys:ApplyForceCenter(aimvector*500000) phys:ApplyForceCenter( self.Owner:GetAimVector()*1500) local angvel = Vector(0,math.random(-5000,-2000),math.random(-100,-900)) //The positive z coordinate emulates the spin from a right-handed overhand throw angvel:Rotate(-1*ent:EyeAngles()) angvel:Rotate(Angle(0,self.Owner:EyeAngles().y,0)) phys:AddAngleVelocity(angvel) --ent:SetVelocity(ent:GetForward()*50000 + ent:GetRight()*50 + ent:GetUp()*50) ent:SetGravity(50) table.insert( self.Owner.C4s, ent ) end if GetConVar("c4_infinite"):GetInt() == 0 then self.Owner:RemoveAmmo(1,"slam") end self:SetNextPrimaryFire(CurTime() + 1.1) self:SetNextSecondaryFire(CurTime() + 1.2) end function SWEP:ShouldDropOnDie() return false end function SWEP:OnRemove() local owner = self.Owner --[[ timer.Simple(0.5,function() if owner:IsValid() == false then if SERVER then for k, v in pairs( owner.C4s ) do timer.Simple( .05 * k, function() if IsValid( v ) then v:Remove() end end) end end end end) ]] end function SWEP:Reload() if not IsFirstTimePredicted() then return end self:SendWeaponAnim(ACT_VM_PRIMARYATTACK) timer.Simple(0.1,function()  if IsValid(self) then  self:EmitSound("bubstock9/c4_click_mono.wav")  end  end) if self.Owner:Alive() and self.Owner:IsValid() then -- thanks chief tiger local Owner = self.Owner if SERVER then for k, v in pairs( Owner.C4s ) do timer.Simple( .05 * k, function() if IsValid( v ) then v:Explode() table.remove( Owner.C4s, k ) Owner.C4s[k] = null end end ) end end end self:SetNextPrimaryFire(CurTime() + 1.1) self:SetNextSecondaryFire(CurTime() + 1.2) end function SWEP:DrawHUD() surface.SetDrawColor( 255, 255, 255, 255 ) surface.SetMaterial( Material("models/hoff/weapons/seal6_c4/c4_reticle.png") ) surface.DrawTexturedRect( ScrW() / 2 - 16, ScrH() / 2 - 16, 32, 32 ) end If anyone can help, please reply. Thanks.
Try switching ent:C4Owner = self.Owner with self:GetOwner()
Thank you so much, but now it's giving me this: [ERROR] lua/weapons/bubstock9/shared.lua:149: Tried to use a NULL entity!   1. SetPos - [C]:-1    2. unknown - lua/weapons/bubstock9/shared.lua:149
function SWEP:PrimaryAttack()          if not IsFirstTimePredicted() then return end     if GetConVar("c4_infinite"):GetInt() == 0 then         if ( self:Ammo1() <= 0 ) then             return false         end     end     self:SendWeaponAnim(ACT_VM_THROW)         self:EmitSound("hoff/mpl/seal_c4/whoosh_00.wav")     --self:TakePrimaryAmmo(1)     local tr = self.Owner:GetEyeTrace()     if SERVER then         local ent = ents.Create("ace-c4")         if IsValid(ent) then         ent:SetPos(self.Owner:GetShootPos())         ent:SetAngles(Angle(1,0,0))         ent:Spawn()         ent.C4Owner = self.Owner         local phys = ent:GetPhysicsObject()         phys:SetMass(0.6)         local shot_length = tr.HitPos:Length()         local aimvector = self.Owner:GetAimVector()     --    phys:ApplyForceCenter (self.Owner:GetAimVector():GetNormalized() * math.pow (shot_length, 3));     --    phys:ApplyForceCenter(aimvector*500000)         phys:ApplyForceCenter( self.Owner:GetAimVector()*1500)         local angvel = Vector(0,math.random(-5000,-2000),math.random(-100,-900)) //The positive z coordinate emulates the spin from a right-handed overhand throw         angvel:Rotate(-1*ent:EyeAngles())         angvel:Rotate(Angle(0,self.Owner:EyeAngles().y,0))         phys:AddAngleVelocity(angvel)         --ent:SetVelocity(ent:GetForward()*50000 + ent:GetRight()*50 + ent:GetUp()*50)         ent:SetGravity(50)         table.insert( self.Owner.C4s, ent )     end end     if GetConVar("c4_infinite"):GetInt() == 0 then         self.Owner:RemoveAmmo(1,"slam")     end          self:SetNextPrimaryFire(CurTime() + 1.1)     self:SetNextSecondaryFire(CurTime() + 1.2) end I think IsValid should fix it, I added it under the "if SERVER then" part.
Thanks again, but... [ERROR] lua/weapons/bubstock9/shared.lua:152: function arguments expected near '='   1. unknown - lua/weapons/bubstock9/shared.lua:0 [ERROR] lua/weapons/bubstock9/shared.lua:152: function arguments expected near '='   1. unknown - lua/weapons/bubstock9/shared.lua:0 Attempted to create unknown entity type ace-c4! [ERROR] lua/weapons/bubstock9/shared.lua:193: Tried to use a NULL entity!   1. SetPos - [C]:-1    2. unknown - lua/weapons/bubstock9/shared.lua:193 ...it's just one of those days, isn't it? Maybe it's a problem with the entity it's trying to create, here's the code for that: -- This is init.lua function ENT:SpawnFunction( ply, tr ) if ( !tr.Hit ) then return end local SpawnPos = tr.HitPos + tr.HitNormal * 16 local ent = ents.Create( "ace-c4" ) ent:SetPos( SpawnPos ) ent:Spawn() ent:Activate() ent:GetOwner(self.C4Owner) return ent end function ENT:Initialize() self.Entity:SetModel( "models/bubstock9/weapons/c4.mdl" ) self.Entity:PhysicsInit( SOLID_VPHYSICS ) self.Entity:SetMoveType( MOVETYPE_VPHYSICS ) self.Entity:SetSolid( SOLID_VPHYSICS ) self.Entity:DrawShadow(true) -- self.Entity:SetModelScale( 0.5, 0 )   local phys = self.Entity:GetPhysicsObject()   if (phys:IsValid()) then phys:Wake()   end self.Hit = false self:SetDTFloat( 0, math.Rand( 0.5, 1.3 ) ) self:SetDTFloat( 1, math.Rand( 0.3, 1.2 ) ) end function ENT:SetupDataTables() self:DTVar( "Float", 0, "RotationSeed1" ) self:DTVar( "Float", 1, "RotationSeed2" ) end function ENT:Explode() self.Entity:EmitSound( "bubstock9/pow_explode.wav" ) self.Entity:SetOwner(self.C4Owner) local detonate = ents.Create( "env_explosion" ) detonate:SetOwner(self.C4Owner) detonate:SetPos( self.Entity:GetPos() ) detonate:SetKeyValue( "iMagnitude", "175" ) detonate:Spawn() detonate:Activate() detonate:Fire( "Explode", "", 0 ) local shake = ents.Create( "env_shake" ) shake:SetOwner( self.Owner ) shake:SetPos( self.Entity:GetPos() ) shake:SetKeyValue( "amplitude", "2000" ) shake:SetKeyValue( "radius", "400" ) shake:SetKeyValue( "duration", "2.5" ) shake:SetKeyValue( "frequency", "255" ) shake:SetKeyValue( "spawnflags", "4" ) shake:Spawn() shake:Activate() shake:Fire( "StartShake", "", 0 ) local c4pos = self.Entity:GetPos() self.Entity:Remove() for k,v in pairs(ents.FindInSphere(c4pos,100)) do if v:GetClass() == "ace-c4" then if !v:GetOwner():IsValid() then timer.Simple(0.1,function() if (type(v.Explode) == "function") then v:Explode() end end) end end end end function ENT:PhysicsCollide(data,phys) self:EmitSound("hoff/mpl/seal_c4/satchel_plant.wav") if self:IsValid() && !self.Hit then self:SetCollisionGroup(COLLISION_GROUP_DEBRIS) self.Hit = true end if data.HitEntity:IsWorld() == false and data.HitEntity:GetClass() ~= "ace-c4" and data.HitEntity:IsNPC() == false and data.HitEntity:IsPlayer() == false and  data.HitEntity:IsValid() then self:SetSolid(SOLID_NONE) self:SetMoveType(MOVETYPE_NONE) self:SetParent(data.HitEntity) self.Stuck = true self.Hit = true end if data.HitEntity:IsWorld() then self:SetMoveType(MOVETYPE_NONE) end local angs = self:GetAngles() -- self:SetAngles(Angle(0,0,0)) local ang = data.HitNormal:Angle()         ang.p = ang.p + 90 self:SetPos(data.HitPos + ((data.HitNormal / 5) * -11)) local pos = self.C4Owner:GetPos() - self:GetPos() local normalized = pos:Angle() if (ang.p == 180 and ang.y == 0 and ang.r == 0) or (ang.p == 360 and ang.y == 0 and ang.r == 0) then self:SetAngles(Angle(0,normalized.y,0)) else self:SetAngles(ang) end timer.Simple(.001,function()  local get = self:GetPos() -- print(math.Round(get.x,-2)) -- local rounded = math.Round(get.x,-2) -- self:SetPos(Vector(rounded,get.y,get.z)) local getx = get.x local gety = get.y local getz = get.z local roundx = math.Round(get.x,-2) local roundy = math.Round(get.y) local roundz = math.Round(get.z) -- if roundy > roundx and roundy > roundz then -- self:SetPos(Vector(getx,roundy,getz)) -- elseif roundx > roundy and roundx > roundz then -- self:SetPos(Vector(roundx,gety,getz)) -- elseif self:GetAngles() == Angle(360,0,0) then -- self:SetPos(oldpos + Vector(0,0,8)) -- elseif self:GetAngles() == Angle(90,90,0) then -- self:SetPos(oldpos + Vector(0,15,0)) -- elseif self:GetAngles() == Angle(90,270,0) then -- self:SetPos(oldpos + Vector(0,-18,0)) -- elseif self:GetAngles() == Angle(90,180,0) then -- self:SetPos(oldpos + Vector(-15,0,0)) -- end -- print(self:GetAngles()) end) end function ENT:OnTakeDamage( dmginfo ) self.Entity:TakePhysicsDamage( dmginfo ) end function ENT:Touch(ent) if IsValid(ent) && !self.Stuck then if ( ent && IsValid( self.C4Owner ) ) then return false end if ent:IsNPC() || (ent:IsPlayer() && ent != self:GetOwner()) || ent:IsVehicle() then self:SetSolid(SOLID_NONE) self:SetMoveType(MOVETYPE_NONE) self:SetParent(ent) self.Stuck = true self.Hit = true end end end function ENT:Use( activator, caller ) -- if activator == self.C4Owner then -- self.Hit = false -- self.Stuck = false -- self:Remove() -- if activator:HasWeapon("ace-c4") == false then activator:Give("ace-c4") end -- activator:GiveAmmo(1,"slam") -- end end
The first error can be fixed by doing ent.C4Owner = self.Owner
Where do I put that?
Sorry, you need to Log In to post a reply to this thread.