What do you need help with? V3

I’m trying to put a grappling hook on a friend’s TTT server but I’m awful at lua (really, really awful) and I need some help. I used this grappling hook for most of the code, and I only made a shared.lua file and put it in my entities/weapons/weapon_ttt_grapple folder because I didn’t know if I needed to make anything else other than the shared file :v:

When I try using it ingame everything works fine up until trying to shoot it, then it just makes a noise and won’t grapple on to anything.

shared.lua
[lua]SWEP.Base = “weapon_tttbase”

SWEP.Spawnable = true
SWEP.AdminSpawnable = true
SWEP.AutoSpawnable = false

SWEP.Kind = WEAPON_PISTOL
SWEP.CanBuy = {ROLE_TRAITOR, ROLE_DETECTIVE}
SWEP.AllowDrop = true
SWEP.PrintName = “Grappling Hook”
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = true
SWEP.ViewModel = “models/weapons/v_crossbow.mdl”
SWEP.WorldModel = “models/weapons/w_crossbow.mdl”
SWEP.Primary.Ammo = “none”
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1

local sndPowerUp = Sound(“weapons/crossbow/hit1.wav”)
local sndPowerDown = Sound(“Airboat.FireGunRevDown”)
local sndTooFar = Sound(“buttons/button10.wav”)
//local sndShot = Sound(“weapons/357/357_fire2.wav”)

if CLIENT then
SWEP.PrintName = “Grappling Hook”
SWEP.Slot = 1

SWEP.Icon = “VGUI/ttt/icon_fall”

SWEP.EquipMenuData = {
type = “Weapon”,
desc = “Lets you use a rope to maneuver around a map.”
};
end

if SERVER then
AddCSLuaFile( “shared.lua” )
end

function SWEP:Initialize()

    nextshottime = CurTime()
    self:SetWeaponHoldType( "smg" )
    self.zoomed = false

end

function SWEP:Think()

    if (!self.Owner || self.Owner == NULL) then return end
   
    if ( self.Owner:KeyPressed( IN_ATTACK ) ) then
   
            self:StartAttack()
           
    elseif ( self.Owner:KeyDown( IN_ATTACK ) && inRange ) then
   
            self:UpdateAttack()
           
    elseif ( self.Owner:KeyReleased( IN_ATTACK ) && inRange ) then
   
            self:EndAttack( true )
   
    end
   
    --Changed from KeyDown to prevent random stuck-in-zoom bug.
    if ( self.Owner:KeyPressed( IN_ATTACK2 ) ) then
   
            self:Attack2()
           
    end

end

function SWEP:DoTrace( endpos )
local trace = {}
trace.start = self.Owner:GetShootPos()
trace.endpos = trace.start + (self.Owner:GetAimVector() * 14096) --14096 is length modifier.
if(endpos) then trace.endpos = (endpos - self.Tr.HitNormal * 7) end
trace.filter = { self.Owner, self.Weapon }

    self.Tr = nil
    self.Tr = util.TraceLine( trace )

end

function SWEP:StartAttack()
–Get begining and end poins of trace.
local gunPos = self.Owner:GetShootPos() --Start of distance trace.
local disTrace = self.Owner:GetEyeTrace() --Store all results of a trace in disTrace.
local hitPos = disTrace.HitPos --Stores Hit Position of disTrace.

    --Calculate Distance
    --Thanks to rgovostes for this code.
    local x = (gunPos.x - hitPos.x)^2;
    local y = (gunPos.y - hitPos.y)^2;
    local z = (gunPos.z - hitPos.z)^2;
    local distance = math.sqrt(x + y + z);
   
    --Only latches if distance is less than distance CVAR
    local distanceCvar = GetConVarNumber("grapple_distance")
    inRange = false
    if distance < 0 or distance <= distanceCvar then
            inRange = true
    end
   
    if inRange then
            if (SERVER) then
                   
                    if (!self.Beam) then --If the beam does not exist, draw the beam.
                            --grapple_beam
                            self.Beam = ents.Create( "trace1" )
                                    self.Beam:SetPos( self.Owner:GetShootPos() )
                            self.Beam:Spawn()
                    end
                   
                    self.Beam:SetParent( self.Owner )
                    self.Beam:SetOwner( self.Owner )
           
            end
           
            self:DoTrace()
            self.speed = 10000 --Rope latch speed. Was 3000.
            self.startTime = CurTime()
            self.endTime = CurTime() + self.speed
            self.ddt = -1
           
            if (SERVER && self.Beam) then
                    self.Beam:GetTable():SetEndPos( self.Tr.HitPos )
            end
           
            self:UpdateAttack()
           
            self.Weapon:EmitSound( sndPowerDown )
    else
            --Play A Sound
            self.Weapon:EmitSound( sndTooFar )
    end

end

function SWEP:UpdateAttack()

    self.Owner:LagCompensation( true )
   
    if (!endpos) then endpos = self.Tr.HitPos end
   
    if (SERVER && self.Beam) then
            self.Beam:GetTable():SetEndPos( endpos )
    end

    lastpos = endpos
   
   
                    if ( self.Tr.Entity:IsValid() ) then
                   
                                    endpos = self.Tr.Entity:GetPos()
                                    if ( SERVER ) then
                                    self.Beam:GetTable():SetEndPos( endpos )
                                    end
                   
                    end
                   
                    local vVel = (endpos - self.Owner:GetPos())
                    local Distance = endpos:Distance(self.Owner:GetPos())
                   
                    local et = (self.startTime + (Distance/self.speed))
                    if(self.ddt != 0) then
                            self.ddt = (et - CurTime()) / (et - self.startTime)
                    end
                    if(self.ddt < 0) then
                            self.Weapon:EmitSound( sndPowerUp )
                            self.ddt = 0
                    end
                   
                    if(self.ddt == 0) then
                    zVel = self.Owner:GetVelocity().z
                    vVel = vVel:GetNormalized()*(math.Clamp(Distance,0,7))
                            if( SERVER ) then
                            local gravity = GetConVarNumber("sv_Gravity")
                            vVel:Add(Vector(0,0,(gravity/100)*3.5)) --Player speed. DO NOT MESS WITH THIS VALUE!
                            if(zVel < 0) then
                                    vVel:Sub(Vector(0,0,zVel/100))
                            end
                            self.Owner:SetVelocity(vVel)
                            end
                    end
   
    endpos = nil
   
    self.Owner:LagCompensation( false )

end

function SWEP:EndAttack( shutdownsound )

    if ( shutdownsound ) then
            self.Weapon:EmitSound( sndPowerDown )
    end
   
    if ( CLIENT ) then return end
    if ( !self.Beam ) then return end
   
    self.Beam:Remove()
    self.Beam = nil

end

function SWEP:Attack2() --Zoom.

if self.zoomed then
    self.zoomed = false
    if SERVER then
        self.Owner:SetFOV(0, 0.1)
    end
else
    self.zoomed = true
    if SERVER then
        self.Owner:SetFOV(30, 0.1)
    end
end

end

function SWEP:Holster()
self:EndAttack( false )
return true
end

function SWEP:OnRemove()
self:EndAttack( false )
return true
end

function SWEP:PrimaryAttack()
end

function SWEP:SecondaryAttack()
end[/lua]

Yes I know I’m bad at lua and my friend should probably get a real lua coder but hopefully this isn’t too bad

This was also in the original grappling hook and it looked like it was pretty useful but I didn’t know what to do with it

[lua]
AddCSLuaFile( “cl_init.lua” )
AddCSLuaFile( “shared.lua” )
include(‘shared.lua’)

– Distance CVAR
CreateConVar(“grapple_distance”, -1, false)[/lua]

How do I get DListView:SortByColumn to work?

I added 3 columns and I want it to sort by the first one I added.

I tried DListView:SortByColumn(1) and nothing happened.

-snip, no merge-

if I have GM.Box = {} in init.lua and I have include(“server/main.lua”) in init.lua, if I were to refer to GM.Box in main.lua it wouldn’t be nil, correct?

Because it’s nil.

are you including it before or after you assign it?

PEOPLE, I NEED HELP!

How can I allow certain steam ids in a txt file be able to have access to donator privelages, without being in the donator group? (Because some admins on the server i work on are donators and some are not)

I made a txt file in the data folder, so in game I could add steam ids to it using a derma menu and the file.Write function. I just need to know how a Lua file can read that txt file (using file.read) and then give those steam ids permissions.

Perhaps I could make an ulx donator group which nobody is in, and then let the steam ids inherit from that (but let them still be in anotherulx group in game)

I would like to do it by using this method:

and maybe change it to something like:

[lua] local a = CTeam.admin
if a > 0 and not ply:IsAdmin()
or a > 1 and not ply:IsSuperAdmin()
or a > 3 and not ply:SteamID() == file.read(“file.txt”)
then
Notify(ply, 1, 4, string.format(LANGUAGE.need_admin, CTeam.name))
return “”
end
[/lua]
Would this even work?

http://puu.sh/1PXTw

After. main.lua errors with attempt to index global ‘GM’

I just thought of something…Instead of doing this, which is still a great script:


local haspushed = false
hook.Add("Think", "fill", function()
    if input.IsKeyDown(KEY_G) then
        if !haspushed then
            haspushed = true
            RunConsoleCommand("This")
        end
    else
        haspushed = false
    end
end)

Couldn’t of I just done:


RunConsoleCommand( bind G This )

You can’t bind keys through RunConsoleCommand,

I have a playx player that I’d like to just be completely static, so players have no interaction with it at all.

I’ve found that any player can remove it with the remove tool, what have I missed.

[lua]function makeplayx()
local scr = ents.Create(“prop_physics”)
scr:SetModel(“models/props_phx/construct/metal_plate1.mdl”)
scr:SetPos(Vector(-1022.4390,-15.2193,-12451.202))
scr:SetAngles(Angle(90,0,180))
scr:Spawn()
scr:GetPhysicsObject():EnableMotion(false)

local playx = ents.Create(“gmod_playx”)
playx:SetModel(“models/dav0r/camera.mdl”)
playx:SetPos(Vector(-1970.9372,-7.8194,-12430.418))
playx:SetAngles(Angle(0,0,0))
playx:Spawn()
playx:SetUnFreezable(false)
playx:GetPhysicsObject():EnableMotion(false)
end
hook.Add( “InitPostEntity”, “MapStartTrigger”, makeplayx )
[/lua]


[ERROR] addons/combinification/lua/weapons/stunbaton/shared.lua:99: ')' expected near 'end'
  1. unknown - addons/combinification/lua/weapons/stunbaton/shared.lua:0

Code:


SWEP.Author            = "LuaVirusFree"
SWEP.Contact            = "sabarbee@wccnet.edu"
SWEP.Purpose            = "Stun, don't kill!"
SWEP.Instructions        = "Primary smacks someone and stuns them."
 
SWEP.Spawnable            = false
SWEP.AdminSpawnable        = true
 
SWEP.ViewModel            = "models/weapons/v_stunstick.mdl"
SWEP.WorldModel        = "models/weapons/w_stunstick.mdl"
 
SWEP.Primary.ClipSize        = -1
SWEP.Primary.DefaultClip    = -1
SWEP.Primary.Automatic        = false
SWEP.Primary.Ammo        = "GaussEnergy"
 
SWEP.Secondary.ClipSize    = -1
SWEP.Secondary.DefaultClip    = -1
SWEP.Secondary.Automatic    = false
SWEP.Secondary.Ammo        = "none"
 
local ShootSound = Sound( "Weapon_StunStick.Swing" )
local Hitworld = Weapon_StunStick.Melee_HitWorld
local Hitobject = Weapon_StunStick.Melee_Hit
local WeMissed = Weapon_StunStick.Melee_Miss
local Activated = Weapon_StunStick.Activate
local Deactivated = Weapon_StunStick.Deactivate
 
/*---------------------------------------------------------
    Reload does nothing
---------------------------------------------------------*/
function SWEP:Reload()
end
 
/*---------------------------------------------------------
  Think reloads energy
---------------------------------------------------------*/
local LastTime = curtime()
function SWEP:Think()
    local OurAmmo = self.Owner:GetAmmoCount(self:GetPrimaryAmmoType())
    if OurAmmo < 100 && curtime() >= LastTime + 0.1 then
        self.Owner:SetAmmo( math.min( OurAmmo + math.random(1, 14), 100 ), self:GetPrimaryAmmoType() )    -- Resupply over time. Biggest jump is 14 per decisecond.
    end
end
 
/*---------------------------------------------------------
    PrimaryAttack
---------------------------------------------------------*/
local ATKPower = math.random(7,13)
function SWEP:PrimaryAttack()

    if self:CanPrimaryAttack() then
     
        local tr = self.Owner:GetEyeTrace()
        if ( tr.HitWorld ) then
            self:EmitSound( Hitworld )
        elseif ( tr.Hit ) then
            self:EmitSound( Hitobject )
        else
            self:EmitSound( WeMissed )
        end  -- We want to hit the world. Do damage? NO!
     
        local effectdata = EffectData()
        effectdata:SetOrigin( tr.HitPos )
        effectdata:SetNormal( tr.HitNormal )
    --    effectdata:SetMagnitude( 8 )
        effectdata:SetScale( math.Rand(0.7,1.3) )
        effectdata:SetRadius( math.Rand(15,17) )
        util.Effect( "StunstickImpact", effectdata )    -- Stun Baton effect.
     
        self.Weapon:EmitSound( ShootSound )
    --    self.BaseClass.ShootEffects( self )
    
        if tr.Entity:IsPlayer() or tr.Entity:IsNPC() then
        self:DoDMG(tr.Entity)
        
        end
        
    end
 
end

function SWEP:DoDMG(EntHit)
    local OldHealth = EntHit:GetHealth()
    local dmginfo = DamageInfo()
        local DMGToDo=math.min(OldHealth-1,ATKPower)
        local LostDmg = OldHealth-DMGToDo
        dmginfo:SetDamage( DMGToDo ) -- 7 damage or whatever is left-1
        dmginfo:SetDamageType( DMG_STUN ) --Stun damage
        dmginfo:SetAttacker( self.Owner ) --You.
        dmginfo:SetSetInflictor( self )
        dmginfo:SetDamageForce( self.Owner:EyeAngles()*20 ) --Launch away
    
    local HealSteps=OldHealth-LostDmg
      EntHit:TakeDamageInfo( dmginfo )
        self.Owner:TakePrimaryAmmo(ATKPower)
    local i=1
    for i=1,HealSteps do
99:        timer.Simple(0.05*i,function() EntHit:SetHealth( OldHealth + 1*i end ) )    -- In at most 0.65 seconds, replenish health damage. TODO? Is it dead?
    end
end
 
/*---------------------------------------------------------
    SecondaryAttack
---------------------------------------------------------*/
function SWEP:SecondaryAttack()

    if self:CanPrimaryAttack() then
     
        local tr = self.Owner:GetEyeTrace()
        if ( tr.HitWorld ) then
            self:EmitSound( Hitworld )
        elseif ( tr.Hit ) then
            self:EmitSound( Hitobject )
        else
            self:EmitSound( WeMissed )
        end  -- We want to hit the world. Do damage? NO!
     
        local effectdata = EffectData()
        effectdata:SetOrigin( tr.HitPos )
        effectdata:SetNormal( tr.HitNormal )
    --    effectdata:SetMagnitude( 8 )
        effectdata:SetScale( math.Rand(0.7,1.3) )
        effectdata:SetRadius( math.Rand(15,17) )
        util.Effect( "StunstickImpact", effectdata )    -- Stun Baton effect.
     
        self.Weapon:EmitSound( ShootSound )
    --    self.BaseClass.ShootEffects( self )
    
        if tr.Entity:IsPlayer() or tr.Entity:IsNPC() then
        self:DoDMG(tr.Entity)
        
        end
        
    end
 
end

function SWEP:Initialize()
    self:EmitSound( Activated )
end

function SWEP:Holster()
    self:EmitSound( Deactivated )
end

function SWEP:OnRemove()
    self:EmitSound( Deactivated )
end

Please use Lua tags so we don’t have to copy that into an editor to see what line is the issue

[lua]timer.Simple(0.05i,function() EntHit:SetHealth( OldHealth + 1i end ) )[/lua]

Should be

[lua]timer.Simple(0.05i,function() EntHit:SetHealth( OldHealth + 1i ) end )[/lua]

when did
lua tags get added?

[editline]20th January 2013[/editline]

And also, I’m having trouble getting my sweps to realize that self.Owner is real…

SWEP.Author = "LuaVirusFree"SWEP.Contact = "sabarbee@wccnet.edu"SWEP.Purpose = "Aim, shoot, dispatch."SWEP.Instructions = “Primary shoots.” SWEP.Spawnable = falseSWEP.AdminSpawnable = true SWEP.ViewModel = "models/weapons/v_pistol.mdl"SWEP.WorldModel = “models/weapons/w_pistol.mdl” SWEP.Primary.ClipSize = 18SWEP.Primary.DefaultClip = 0 – We don’t want to start loaded.SWEP.Primary.Automatic = falseSWEP.Primary.Ammo = “AlyxGun” SWEP.Secondary.ClipSize = -1SWEP.Secondary.DefaultClip = -1SWEP.Secondary.Automatic = falseSWEP.Secondary.Ammo = "none"local OwnerGuy = self local ShootSound = Sound( “Weapon_Pistol.NPC_Single” )local ReloadSound = Sound( “Weapon_Pistol.NPC_Reload” )local EmptySound = Sound( “Weapon_Pistol.Empty” )local BurstSound = Sound( “Weapon_Pistol.Burst” )local SwitchSingleSound = Sound( “Weapon_Pistol.Special1” )local SwitchBurstSound = Sound( “Weapon_Pistol.Special2” ) /--------------------------------------------------------- Reload reloads.---------------------------------------------------------/function SWEP:Reload() if self:Clip1() == 18 then self.Clip1 = 19 end self.Weapon:EmitSound( ReloadSound ) self:DefaultReload( ACT_VM_RELOAD )end local ReloadTime = CurTime()/--------------------------------------------------------- Think reloads---------------------------------------------------------/local ReloadTime = CurTime()function SWEP:Think() if self:Clip1() < 18 && CurTime() > ReloadTime then self.Owner:SetAmmo( 19, “Pistol” ) self:Reload() end if self.Owner:KeyPressed( IN_ATTACK ) then ReloadTime = CurTime() + 7 endend–function SWEP:CanPrimaryAttack()-- if self:Clip1 < 8 then return false end–end /--------------------------------------------------------- PrimaryAttack---------------------------------------------------------/function SWEP:PrimaryAttack() if !self:CanPrimaryAttack() then self.Weapon:EmitSound( EmptySound ) return end – TODO: Make and shoot bullet entity. Reduce ammo. if !BurstFireMode then local Player = self.Owner Player:TakePrimaryAmmo(1) local Bullet = {} if SERVER then Bullet.Nine = ents.Create( “bullet_Nine” ) Bullet.Nine:SetPos( Player:GetShootPos() ) – TODO: Get the world model’s muzzle? Bullet.Nine:SetAngles( self.Owner:GetAngles() ) Bullet.Nine:Spawn() Bullet.Nine:Activate() Bullet.Nine:SetOwner( Player ) local bulPhy = Bullet.Nine:GetPhysicsObject() bulPhy:SetVelocity((self.Owner:GetAngles()+ Angle(1, 0, 0)):Forward() * 33600 ) – 5.7mm Muzzle Velocity. Bullet.Nine:SetVar(“Velocity”,33600) – Bullet.Nine:SetVar(“Acceleration”,accel) – local Force = Angle:__add(Player:GetAimVector(), Angle(-30, 0, 0) )256 – bulPhy:SetVelocity((self.Owner:GetAngles()+ Angle(45, 0, 0)):Forward() * 1 * CurTime() * 1) end – Bullet.AngTr = Angle(self.Owner:GetAngles()+ Angle(45, 0, 0))–:Forward() – Bullet.AngTr2 = Angle(self.Owner:GetAngles()+Angle(-45, 0, 0))–:Forward() self.Weapon:EmitSound( ShootSound ) self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) – timer.Simple( 0.3, self.Weapon.SendWeaponAnim, self, ACT_VM_IDLE ) self.Weapon:SetNextPrimaryFire( CurTime()+0.4 ) self.Weapon:SetNextSecondaryFire( CurTime()+2 ) self:ApplyRecoil(0.93,NewSpray) elseif BurstFireMode then local Player = self.Owner local Bullet = {} local function ShootBurret() if self:Clip1() < 1 then return end if self:Clip1() < 3 then self:EmitSound( ShootSound ) end Player:TakePrimaryAmmo(1) if SERVER then Bullet.Nine = ents.Create( “bullet_Nine” ) Bullet.Nine:SetPos( Player:GetShootPos() ) – TODO: Get the world model’s muzzle? Bullet.Nine:SetAngles( self.Owner:GetAngles() ) Bullet.Nine:Spawn() Bullet.Nine:Activate() Bullet.Nine:SetOwner( Player ) local bulPhy = Bullet.Nine:GetPhysicsObject() bulPhy:SetVelocity((self.Owner:GetAngles()+ Angle(1, 0, 0)):Forward() * 33600 ) end self:ApplyRecoil(0.73,NewSpray) – Lil less kick for burst. end ShootBurret() timer.Simple(0.1, ShootBurret()) timer.Simple(0.2, ShootBurret()) if self:Clip1() >= 3 then self.Weapon:EmitSound( BurstSound ) end self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) self.Weapon:SetNextPrimaryFire( CurTime()+0.4 ) self.Weapon:SetNextSecondaryFire( CurTime()+2 ) end if self:Clip1()-1 <= 0 then timer.Simple(0.4, self:Reload()) end eBullet:SetPos(PlayerPos) eBullet:SetVar(“Velocity”,Velocity) eBullet:SetVar(“Acceleration”,accel) local tBullet = {} – This is the bullet our bullet SENT will be firing when it hits something. Everything except force and damage is determined by the bullet SENT tBullet.Force = 0.153 tBullet.Damage = 3 local tTrace = {} --This is the trace the bullet SENT uses to see if it has hit something tTrace.filter = filter or {self.Owner,eBullet} tTrace.mask = mask eBullet:SetVar(“Bullet”,tBullet) eBullet:SetVar(“Trace”,tTrace) eBullet:SetVar(“Owner”,self.Owner) eBullet:Spawn() eBullet:Spawn()endfunction SWEP:ApplyRecoil(recoil) – Kick your view. if self.OwnerIsNPC or (SERVER and not self.Owner:IsListenServerHost()) then return end local EyeAng = Angle( recoilmath.Rand(-1,-0.7), – Up/Down recoil recoilmath.Rand(-0.4,0.4), – Left/Right recoil 0) – Punch the player’s view self.Owner:ViewPunch(EyeAng) – This smooths out the player’s screen movement when recoil is applied self.Owner:SetEyeAngles(self.Owner:EyeAngles() + EyeAng) end–[[function SWEP:DoDMG(EntHit) local OldHealth = EntHit:GetHealth() local dmginfo = DamageInfo() local DMGToDo=math.min(OldHealth-1,ATKPower) local LostDmg = OldHealth-DMGToDo dmginfo:SetDamage( DMGToDo ) – 7 damage or whatever is left-1 dmginfo:SetDamageType( DMG_STUN ) --Stun damage dmginfo:SetAttacker( self.Owner ) --You. dmginfo:SetSetInflictor( self ) dmginfo:SetDamageForce( self.Owner:EyeAngles()20 ) --Launch away local HealSteps=OldHealth-LostDmg EntHit:TakeDamageInfo( dmginfo ) Player:GiveAmmo( ATKPower, “GaussEnergy”, true ) for i=1,HealSteps do timer.Simple(0.05i,function() EntHit:SetHealth( OldHealth + 1i end ) ) – In at most 0.65 seconds, replenish health damage. TODO? Is it dead? endend ]]–/--------------------------------------------------------- SecondaryAttack switches fire mode.---------------------------------------------------------*/local BurstFireMode = falsefunction SWEP:SecondaryAttack() if !BurstFireMode then BurstFireMode = true self.Weapon:EmitSound( SwitchBurstSound ) end if BurstFireMode then BurstFireMode = false self.Weapon:EmitSound( SwitchSingleSound ) end self.Weapon:SetNextPrimaryFire( CurTime()+0.4 ) self.Weapon:SetNextSecondaryFire( CurTime()+2 )endfunction SWEP:Initialize() OwnerGuy = self.Owner-- self:EmitSound( Activated ) OwnerGuy:SetAmmo( math.max(19, Player:GetAmmoCount(“Pistol”)), “Pistol” )end–[[function SWEP:Holster() self:EmitSound( Deactivated )endfunction SWEP:OnRemove() self:EmitSound( Deactivated )end]]–

Line 203. It does this even if I just use self.Owner, rather than a varia[highble.



[ERROR] addons/combinification/lua/weapons/pistol/shared.lua:203: attempt to index upvalue 'OwnerGuy' (a nil value)
  1. unknown - addons/combinification/lua/weapons/pistol/shared.lua:203


[editline]20th January 2013[/editline]

It’s the SetAmmo that returns the error.
Okay, now I get this:


[ERROR] addons/combinification/lua/weapons/pistol/shared.lua:202: attempt to call method 'GetAmmoCount' (a nil value)  1. unknown - addons/combinification/lua/weapons/pistol/shared.lua:202

The new code:

[lua]SWEP.Author = "LuaVirusFree"SWEP.Contact = “sabarbee@wccnet.edu”
SWEP.Purpose = “Aim, shoot, dispatch.”
SWEP.Instructions = “Primary shoots.”

SWEP.Spawnable = false
SWEP.AdminSpawnable = true

SWEP.ViewModel = “models/weapons/v_pistol.mdl”
SWEP.WorldModel = “models/weapons/w_pistol.mdl”

SWEP.Primary.ClipSize = 18
SWEP.Primary.DefaultClip = 0 – We don’t want to start loaded.
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = “AlyxGun”

SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = “none”

local ShootSound = Sound( “Weapon_Pistol.NPC_Single” )
local ReloadSound = Sound( “Weapon_Pistol.NPC_Reload” )
local EmptySound = Sound( “Weapon_Pistol.Empty” )
local BurstSound = Sound( “Weapon_Pistol.Burst” )
local SwitchSingleSound = Sound( “Weapon_Pistol.Special1” )
local SwitchBurstSound = Sound( “Weapon_Pistol.Special2” )

/---------------------------------------------------------
Reload reloads.
---------------------------------------------------------
/
function SWEP:Reload()
if self:Clip1() == 18 then self.Clip1 = 19 end
self.Weapon:EmitSound( ReloadSound )
self:DefaultReload( ACT_VM_RELOAD )
end

local ReloadTime = CurTime()
/---------------------------------------------------------
Think reloads
---------------------------------------------------------
/
local ReloadTime = CurTime()
function SWEP:Think()
if self:Clip1() < 18 && CurTime() > ReloadTime then
self.Owner:SetAmmo( 19, “Pistol” )
self:Reload()
end
if self.Owner:KeyPressed( IN_ATTACK ) then
ReloadTime = CurTime() + 7
end
end

–function SWEP:CanPrimaryAttack()
– if self:Clip1 < 8 then return false end
–end

/---------------------------------------------------------
PrimaryAttack
---------------------------------------------------------
/
function SWEP:PrimaryAttack()

if !self:CanPrimaryAttack() then self.Weapon:EmitSound( EmptySound ) return end
 
	-- TODO: Make and shoot bullet entity. Reduce ammo.
if !BurstFireMode then 
	local Player = self.Owner
	Player:TakePrimaryAmmo(1)
	local Bullet = {}
	if SERVER then
		Bullet.Nine = ents.Create( "bullet_Nine" )
		Bullet.Nine:SetPos( Player:GetShootPos() )	-- TODO: Get the world model's muzzle?
		Bullet.Nine:SetAngles( self.Owner:GetAngles() )
		Bullet.Nine:Spawn()
		Bullet.Nine:Activate()
		Bullet.Nine:SetOwner( Player )
		 
		local bulPhy = Bullet.Nine:GetPhysicsObject()
		bulPhy:SetVelocity((self.Owner:GetAngles()+ Angle(1, 0, 0)):Forward() * 33600 )	-- 5.7mm Muzzle Velocity.
		Bullet.Nine:SetVar("Velocity",33600)
	--	Bullet.Nine:SetVar("Acceleration",accel)
	--  local Force = Angle:__add(Player:GetAimVector(), Angle(-30, 0, 0) )*256
	--  bulPhy:SetVelocity((self.Owner:GetAngles()+ Angle(45, 0, 0)):Forward() * 1 * CurTime() * 1)
	end
	--	Bullet.AngTr = Angle(self.Owner:GetAngles()+ Angle(45, 0, 0))--:Forward()
	--	Bullet.AngTr2 = Angle(self.Owner:GetAngles()+Angle(-45, 0, 0))--:Forward()
			 
		self.Weapon:EmitSound( ShootSound )
		self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK  )
	--  timer.Simple( 0.3, self.Weapon.SendWeaponAnim, self, ACT_VM_IDLE )
	 
		self.Weapon:SetNextPrimaryFire( CurTime()+0.4 )
		self.Weapon:SetNextSecondaryFire( CurTime()+2 )
	self:ApplyRecoil(0.93,NewSpray)
elseif BurstFireMode then 
	local Player = self.Owner
	local Bullet = {}
	local function ShootBurret()
		if self:Clip1() < 1 then return end
		if self:Clip1() < 3 then
			self:EmitSound( ShootSound )
		end
		Player:TakePrimaryAmmo(1)
		if SERVER then
			Bullet.Nine = ents.Create( "bullet_Nine" )
			Bullet.Nine:SetPos( Player:GetShootPos() )	-- TODO: Get the world model's muzzle?
			Bullet.Nine:SetAngles( self.Owner:GetAngles() )
			Bullet.Nine:Spawn()
			Bullet.Nine:Activate()
			Bullet.Nine:SetOwner( Player )
			 
			local bulPhy = Bullet.Nine:GetPhysicsObject()
			bulPhy:SetVelocity((self.Owner:GetAngles()+ Angle(1, 0, 0)):Forward() * 33600 )
		end
		self:ApplyRecoil(0.73,NewSpray)	-- Lil less kick for burst.
	end
		ShootBurret()
		timer.Simple(0.1, ShootBurret())
		timer.Simple(0.2, ShootBurret())
		if self:Clip1() >= 3 then
			self.Weapon:EmitSound( BurstSound )
		end
		self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK  )
	 
		self.Weapon:SetNextPrimaryFire( CurTime()+0.4 )
		self.Weapon:SetNextSecondaryFire( CurTime()+2 )
end 
if self:Clip1()-1 <= 0 then timer.Simple(0.4, self:Reload()) end


		eBullet:SetPos(PlayerPos)
		eBullet:SetVar("Velocity",Velocity)
		eBullet:SetVar("Acceleration",accel)
		
		local tBullet = {} -- This is the bullet our bullet SENT will be firing when it hits something.  Everything except force and damage is determined by the bullet SENT
		tBullet.Force	= 0.15*3
		tBullet.Damage	= 3
		
		local tTrace = {} --This is the trace the bullet SENT uses to see if it has hit something
		tTrace.filter = filter or {self.Owner,eBullet}
		tTrace.mask = mask
		
		eBullet:SetVar("Bullet",tBullet)
		eBullet:SetVar("Trace",tTrace)
		eBullet:SetVar("Owner",self.Owner)
		eBullet:Spawn()


		eBullet:Spawn()

end
function SWEP:ApplyRecoil(recoil) – Kick your view.

if self.OwnerIsNPC or (SERVER and not self.Owner:IsListenServerHost()) then return end

local EyeAng = Angle(
recoil*math.Rand(-1,-0.7), -- Up/Down recoil
recoil*math.Rand(-0.4,0.4), -- Left/Right recoil
0)

-- Punch the player's view
self.Owner:ViewPunch(EyeAng) -- This smooths out the player's screen movement when recoil is applied
self.Owner:SetEyeAngles(self.Owner:EyeAngles() + EyeAng)

end
–[[
function SWEP:DoDMG(EntHit)
local OldHealth = EntHit:GetHealth()
local dmginfo = DamageInfo()
local DMGToDo=math.min(OldHealth-1,ATKPower)
local LostDmg = OldHealth-DMGToDo
dmginfo:SetDamage( DMGToDo ) – 7 damage or whatever is left-1
dmginfo:SetDamageType( DMG_STUN ) --Stun damage
dmginfo:SetAttacker( self.Owner ) --You.
dmginfo:SetSetInflictor( self )
dmginfo:SetDamageForce( self.Owner:EyeAngles()*20 ) --Launch away

local HealSteps=OldHealth-LostDmg
  EntHit:TakeDamageInfo( dmginfo )
	Player:GiveAmmo( ATKPower, "GaussEnergy", true )
for i=1,HealSteps do
	timer.Simple(0.05*i,function() EntHit:SetHealth( OldHealth + 1*i end ) )	-- In at most 0.65 seconds, replenish health damage. TODO? Is it dead?
end

end
]]–
/---------------------------------------------------------
SecondaryAttack switches fire mode.
---------------------------------------------------------
/
local BurstFireMode = false
function SWEP:SecondaryAttack()
if !BurstFireMode then
BurstFireMode = true
self.Weapon:EmitSound( SwitchBurstSound )
end
if BurstFireMode then
BurstFireMode = false
self.Weapon:EmitSound( SwitchSingleSound )
end
self.Weapon:SetNextPrimaryFire( CurTime()+0.4 )
self.Weapon:SetNextSecondaryFire( CurTime()+2 )
end

function SWEP:Initialize()
– self:EmitSound( Activated )
local Player=self.Owner
self.Owner:SetAmmo( math.max(19, Player:GetAmmoCount(“Pistol”)), “Pistol” ) – The REAL line 202
end
–[[
function SWEP:Holster()
self:EmitSound( Deactivated )
end

function SWEP:OnRemove()
self:EmitSound( Deactivated )
end]]–[/lua]

[editline]20th January 2013[/editline]

Awe, it removed the Lua tags from the old example…

[editline]20th January 2013[/editline]

And without that Variable, just using self.Owner, I get this:



[ERROR] addons/combinification/lua/weapons/pistol/shared.lua:201: attempt to call method 'GetAmmoCount' (a nil value)
  1. unknown - addons/combinification/lua/weapons/pistol/shared.lua:201


How do you find a hammer entity by it’s name through Lua?

@Mattjeanes what do you mean by hammer enity?

Question for myself:
Is there a way to see if a player has mounted games?

For example I want to make a turret that uses Portal; however, if they do not have it, use a cardboard box

  1. Browse the wiki yourself
  2. Get a quicker solution

[editline]20th January 2013[/editline]

  1. Browse the wiki yourself
  2. Get a quicker solution

Hey all.

I’m searching a Color Picker in LUA.

I already try this :

[lua]local DRGBBar = vgui.Create( “DRGBBar” )
DRGBBar:SetParent( ParentPanel )
DRGBBar:SetPos( 5, 28 )
DRGBBar:SetSize( 340, 268 )

local colorCircle = vgui.Create( “DColorCircle”, frame )
colorCircle:SetPos( 10, 30 )
colorCircle:SetSize( 100, 100 )
colorCircle.PaintOver = function()
local color = colorCircle:GetRGB()
end

local colorCube = vgui.Create( “DColorCube”, frame )
colorCube:SetPos( 10, 30 )
colorCube:SetSize( 100, 100 )
colorCube:SetColor( Color( 255, 0, 0, 255 ))
colorCube:SetBaseRGB( Color( 255, 0, 0 ) )

colorCube.OnUserChanged = function()
local color = colorCube:GetRGB()
end[/lua]

This code doesn’t work. Someone can help me?

Somethings like this :

http://image.noelshack.com/fichiers/2013/03/1358706955-peinture.png

Thank

[lua]
hook.Add(“CanTool”, “”, function(_, trace, tool)
local ent = trace.Entity
if tool == “remover” and ent:GetClass() == “gmod_playx” then
//Disallow Tool Usage
return false
end
end)[/lua]

Hammer entity by name means a map entity by “Targetname”. Help this kid, please, because I don’t know either. Also, please help me!
[lua]SWEP.Author = "LuaVirusFree"SWEP.Contact = “sabarbee@wccnet.edu”
SWEP.Purpose = “Aim, shoot, dispatch.”
SWEP.Instructions = “Primary shoots.”

SWEP.Spawnable = false
SWEP.AdminSpawnable = true

SWEP.ViewModel = “models/weapons/v_pistol.mdl”
SWEP.WorldModel = “models/weapons/w_pistol.mdl”

SWEP.Primary.ClipSize = 18
SWEP.Primary.DefaultClip = 0 – We don’t want to start loaded.
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = “AlyxGun”

SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = “none”

local ShootSound = Sound( “Weapon_Pistol.NPC_Single” )
local ReloadSound = Sound( “Weapon_Pistol.NPC_Reload” )
local EmptySound = Sound( “Weapon_Pistol.Empty” )
local BurstSound = Sound( “Weapon_Pistol.Burst” )
local SwitchSingleSound = Sound( “Weapon_Pistol.Special1” )
local SwitchBurstSound = Sound( “Weapon_Pistol.Special2” )

/---------------------------------------------------------
Reload reloads.
---------------------------------------------------------
/
function SWEP:Reload()
if self:Clip1() == 18 then self.Clip1 = 19 end
self.Weapon:EmitSound( ReloadSound )
self:DefaultReload( ACT_VM_RELOAD )
end

local ReloadTime = CurTime()
/---------------------------------------------------------
Think reloads
---------------------------------------------------------
/
local ReloadTime = CurTime()
function SWEP:Think()
if self:Clip1() < 18 && CurTime() > ReloadTime then
self.Owner:SetAmmo( 19, “Pistol” )
self:Reload()
end
if self.Owner:KeyPressed( IN_ATTACK ) then
ReloadTime = CurTime() + 7
end
end

–function SWEP:CanPrimaryAttack()
– if self:Clip1 < 8 then return false end
–end

/---------------------------------------------------------
PrimaryAttack
---------------------------------------------------------
/
function SWEP:PrimaryAttack()

if !self:CanPrimaryAttack() then self.Weapon:EmitSound( EmptySound ) return end
  
    -- TODO: Make and shoot bullet entity. Reduce ammo.
if !BurstFireMode then
    local Player = self.Owner
    Player:TakePrimaryAmmo(1)
    local Bullet = {}
    if SERVER then
        Bullet.Nine = ents.Create( "bullet_Nine" )
        Bullet.Nine:SetPos( Player:GetShootPos() )  -- TODO: Get the world model's muzzle?
        Bullet.Nine:SetAngles( self.Owner:GetAngles() )
        Bullet.Nine:Spawn()
        Bullet.Nine:Activate()
        Bullet.Nine:SetOwner( Player )
          
        local bulPhy = Bullet.Nine:GetPhysicsObject()
        bulPhy:SetVelocity((self.Owner:GetAngles()+ Angle(1, 0, 0)):Forward() * 33600 ) -- 5.7mm Muzzle Velocity.
        Bullet.Nine:SetVar("Velocity",33600)
    --  Bullet.Nine:SetVar("Acceleration",accel)
    --  local Force = Angle:__add(Player:GetAimVector(), Angle(-30, 0, 0) )*256
    --  bulPhy:SetVelocity((self.Owner:GetAngles()+ Angle(45, 0, 0)):Forward() * 1 * CurTime() * 1)
    end
    --  Bullet.AngTr = Angle(self.Owner:GetAngles()+ Angle(45, 0, 0))--:Forward()
    --  Bullet.AngTr2 = Angle(self.Owner:GetAngles()+Angle(-45, 0, 0))--:Forward()
              
        self.Weapon:EmitSound( ShootSound )
        self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK  )
    --  timer.Simple( 0.3, self.Weapon.SendWeaponAnim, self, ACT_VM_IDLE )
      
        self.Weapon:SetNextPrimaryFire( CurTime()+0.4 )
        self.Weapon:SetNextSecondaryFire( CurTime()+2 )
    self:ApplyRecoil(0.93,NewSpray)
elseif BurstFireMode then
    local Player = self.Owner
    local Bullet = {}
    local function ShootBurret()
        if self:Clip1() &lt; 1 then return end
        if self:Clip1() &lt; 3 then
            self:EmitSound( ShootSound )
        end
        Player:TakePrimaryAmmo(1)
        if SERVER then
            Bullet.Nine = ents.Create( "bullet_Nine" )
            Bullet.Nine:SetPos( Player:GetShootPos() )  -- TODO: Get the world model's muzzle?
            Bullet.Nine:SetAngles( self.Owner:GetAngles() )
            Bullet.Nine:Spawn()
            Bullet.Nine:Activate()
            Bullet.Nine:SetOwner( Player )
              
            local bulPhy = Bullet.Nine:GetPhysicsObject()
            bulPhy:SetVelocity((self.Owner:GetAngles()+ Angle(1, 0, 0)):Forward() * 33600 )
        end
        self:ApplyRecoil(0.73,NewSpray) -- Lil less kick for burst.
    end
        ShootBurret()
        timer.Simple(0.1, ShootBurret())
        timer.Simple(0.2, ShootBurret())
        if self:Clip1() &gt;= 3 then
            self.Weapon:EmitSound( BurstSound )
        end
        self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK  )
      
        self.Weapon:SetNextPrimaryFire( CurTime()+0.4 )
        self.Weapon:SetNextSecondaryFire( CurTime()+2 )
end
if self:Clip1()-1 &lt;= 0 then timer.Simple(0.4, self:Reload()) end


        eBullet:SetPos(PlayerPos)
        eBullet:SetVar("Velocity",Velocity)
        eBullet:SetVar("Acceleration",accel)
         
        local tBullet = {} -- This is the bullet our bullet SENT will be firing when it hits something.  Everything except force and damage is determined by the bullet SENT
        tBullet.Force   = 0.15*3
        tBullet.Damage  = 3
         
        local tTrace = {} --This is the trace the bullet SENT uses to see if it has hit something
        tTrace.filter = filter or {self.Owner,eBullet}
        tTrace.mask = mask
         
        eBullet:SetVar("Bullet",tBullet)
        eBullet:SetVar("Trace",tTrace)
        eBullet:SetVar("Owner",self.Owner)
        eBullet:Spawn()


        eBullet:Spawn()

end
function SWEP:ApplyRecoil(recoil) – Kick your view.

if self.OwnerIsNPC or (SERVER and not self.Owner:IsListenServerHost()) then return end
 
local EyeAng = Angle(
recoil*math.Rand(-1,-0.7), -- Up/Down recoil
recoil*math.Rand(-0.4,0.4), -- Left/Right recoil
0)
 
-- Punch the player's view
self.Owner:ViewPunch(EyeAng) -- This smooths out the player's screen movement when recoil is applied
self.Owner:SetEyeAngles(self.Owner:EyeAngles() + EyeAng)

end
–[[
function SWEP:DoDMG(EntHit)
local OldHealth = EntHit:GetHealth()
local dmginfo = DamageInfo()
local DMGToDo=math.min(OldHealth-1,ATKPower)
local LostDmg = OldHealth-DMGToDo
dmginfo:SetDamage( DMGToDo ) – 7 damage or whatever is left-1
dmginfo:SetDamageType( DMG_STUN ) --Stun damage
dmginfo:SetAttacker( self.Owner ) --You.
dmginfo:SetSetInflictor( self )
dmginfo:SetDamageForce( self.Owner:EyeAngles()*20 ) --Launch away

local HealSteps=OldHealth-LostDmg
  EntHit:TakeDamageInfo( dmginfo )
    Player:GiveAmmo( ATKPower, "GaussEnergy", true )
for i=1,HealSteps do
    timer.Simple(0.05*i,function() EntHit:SetHealth( OldHealth + 1*i end ) )    -- In at most 0.65 seconds, replenish health damage. TODO? Is it dead?
end

end
]]–
/---------------------------------------------------------
SecondaryAttack switches fire mode.
---------------------------------------------------------
/
local BurstFireMode = false
function SWEP:SecondaryAttack()
if !BurstFireMode then
BurstFireMode = true
self.Weapon:EmitSound( SwitchBurstSound )
end
if BurstFireMode then
BurstFireMode = false
self.Weapon:EmitSound( SwitchSingleSound )
end
self.Weapon:SetNextPrimaryFire( CurTime()+0.4 )
self.Weapon:SetNextSecondaryFire( CurTime()+2 )
end

function SWEP:Initialize()
– self:EmitSound( Activated )
local Player=self.Owner
self.Owner:SetAmmo( math.max(19, Player:GetAmmoCount(“Pistol”)), “Pistol” ) – The REAL line 202
end[/lua]
The line numbers are wrong after a certain point, so I labeled the actual line “The Real Line”.
[ERROR] addons/combinification/lua/weapons/pistol/shared.lua:201: attempt to call method ‘GetAmmoCount’ (a nil value)

  1. unknown - addons/combinification/lua/weapons/pistol/shared.lua:201

[editline]20th January 2013[/editline]

My old helper got perma-banned, but he would’ve already given me a solution. If that didn’t work, another one. His name was, I believe, Ninjas. Maybe he made a new account?