• What do you need help with? V3
    6,419 replies, posted
[QUOTE=Hyper Iguana;39280944]I wasn't paying attention, try this. [lua] local haspushed = false hook.Add("Think", "imgay", function() if input.IsKeyDown(KEY_G) then if !haspushed then haspushed = true RunConsoleCommand("This") end else haspushed = false end end)[/lua][/QUOTE] Awesome! It worked, thanks so much.
[QUOTE=JetBoom;39276160]override the Paint function?[/QUOTE] Can you show me an example of how I'd get the exact same effect as before, just a different color?
[QUOTE=fairy;39281791]Can you show me an example of how I'd get the exact same effect as before, just a different color?[/QUOTE] Best thing to do when modifying any derma stuff is just to [url=http://glua.me/bin/?path=/lua/vgui/]look at the source[/url]
[QUOTE=Drakehawke;39282421]Best thing to do when modifying any derma stuff is just to [url=http://glua.me/bin/?path=/lua/vgui/]look at the source[/url][/QUOTE] I already did that, but it just uses a SkinHook. I don't know how to fuck with those.
Trying to work out when a func_door takes damage (with entitytakedamage). For some reason this is only called when a prop_door_rotating is hit- does anyone know why, or of an easy workaround? [lua] hook.Add("EntityTakeDamage","doordmgtest",function( ent, dmginfo ) print(ent,"took damage") end) [/lua]
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 [URL="http://www.garrysmod.org/downloads/?a=view&id=126280"]this grappling hook[/URL] 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 an
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?
[B]PEOPLE, I NEED HELP![/B] 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: [QUOTE=Science;30044500]Go to [B]sh_commands.lua[/B] [B]Line 494[/B] [lua] local a = CTeam.admin if a > 0 and not ply:IsAdmin() or a > 1 and not ply:IsSuperAdmin() then Notify(ply, 1, 4, string.format(LANGUAGE.need_admin, CTeam.name)) return "" end[/lua][/quote] 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?
[QUOTE=PortalGod;39286057]are you including it before or after you assign it?[/QUOTE] [url]http://puu.sh/1PXTw[/url] 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: [CODE]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)[/CODE] Couldn't of I just done: [CODE]RunConsoleCommand( bind G This )[/CODE]
[QUOTE=pilot;39289506]I just thought of something...Instead of doing this, which is still a great script: [CODE]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)[/CODE] Couldn't of I just done: [CODE]RunConsoleCommand( bind G This )[/CODE][/QUOTE] 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]
[highlight][ERROR] addons/combinification/lua/weapons/stunbaton/shared.lua:99: ')' expected near 'end' 1. unknown - addons/combinification/lua/weapons/stunbaton/shared.lua:0[/highlight] Code: [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[/code]
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.05*i,function() EntHit:SetHealth( OldHealth + 1*i end ) )[/lua] Should be [lua]timer.Simple(0.05*i,function() EntHit:SetHealth( OldHealth + 1*i ) 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.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()endfunction 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? 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 va
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
[QUOTE=MattJeanes;39291611]How do you find a hammer entity by it's name through Lua?[/QUOTE] [url]http://wiki.garrysmod.com/page/Libraries/ents/FindByName[/url] 1. Browse the wiki yourself 2. Get a quicker solution [editline]20th January 2013[/editline] [QUOTE=Pandaman09;39291676]@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[/QUOTE] [url]http://wiki.garrysmod.com/page/Libraries/engine/GetGames[/url] 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 : [IMG]http://image.noelshack.com/fichiers/2013/03/1358706955-peinture.png[/IMG] Thank
[QUOTE=Bilsta1000;39290467]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][/QUOTE] [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() < 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:I
[QUOTE=Didileking;39291940]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 : [IMG]http://image.noelshack.com/fichiers/2013/03/1358706955-peinture.png[/IMG] Thank[/QUOTE] [url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index7b85.html[/url]
Thank ! :)
In init.lua, I have: [lua]GM.Hits = {} include("server/main.lua")[/lua] In main.lua, I refer to GM.Hits and it thinks that GM is a nil value/table. Why is it doing that if it's all put into one script?
shared.lua [LUA]ENT.Base = "base_gmodentity" ENT.PrintName = "Ammocrate" ENT.Author = "Algebraic" ENT.Spawnable = false --Is it spawnable? ENT.AdminSpawnable = true --Is it an admin spawnable? ENT.NTog = 0[/LUA] cl_init.lua [LUA]include('shared.lua') net.Receive( "crateMenu", Menu ) local function Menu() local DermaPanel = vgui.Create( "DFrame" ) // Create the frame in a local variable DermaPanel:SetPos( 100, 100 ) // Set the position to 100, 100 ( x, y ) DermaPanel:SetSize( 300, 200 ) // Set the size to 300, 200 pixels DermaPanel:SetTitle( "CP Armory" ) // Set the title DermaPanel:SetVisible( true ) // Can you see it? ( Optional - default true ) DermaPanel:SetDraggable( true ) // Can you move/drag it? ( optional - default true ) DermaPanel:ShowCloseButton( true ) // Can you see the close button ( reccomended ) ( optional - default true ) DermaPanel:MakePopup() // Make it popup local Ammo = vgui.Create( "DButton" ) Ammo:SetParent(DermaPanel) Ammo:SetPos( 40, 40 ) Ammo:SetText( "Free Ammunition" ) Ammo:SetSize( 120, 60 ) Ammo.DoClick = function() net.Start( "sendAmmo" ) net.SendToServer() end local mp = vgui.Create( "DButton" ) mp:SetParent(DermaPanel) mp:SetPos( 200, 40 ) mp:SetText( "Purchase MP5 - $300" ) mp:SetSize( 120, 60 ) mp.DoClick = function() net.Start( "sendMP5" ) net.SendToServer() end local deagle = vgui.Create( "DButton" ) deagle:SetParent(DermaPanel) deagle:SetPos( 400, 40 ) deagle:SetText( "Purchase Desert Eagle - $250" ) deagle:SetSize( 120, 60 ) deagle.DoClick = function() net.Start( "sendDeag" ) net.SendToServer() end end[/LUA] init.lua [LUA]AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include('shared.lua') function ENT:Initialize() self:SetModel( "models/Items/ammocrate_smg1.mdl" ) --Set the model self:PhysicsInit( SOLID_VPHYSICS ) self:SetMoveType( MOVETYPE_VPHYSICS ) self:SetSolid( SOLID_VPHYSICS ) local phys = self:GetPhysicsObject() self.NextThink = CurTime() + 1 if (phys:IsValid()) then phys:Wake() end end function ENT:SpawnFunction( ply, tr ) if ( !tr.Hit ) then return end local SpawnPos = tr.HitPos + tr.HitNormal * 36 local ent = ents.Create( self.ClassName ) ent:SetPos( SpawnPos ) ent:Spawn() ent:Activate() return ent end function ENT:Use(activator) ply = activator if ply:IsCP() then util.AddNetworkString( "sendAmmo" ) util.AddNetworkString( "sendMP5" ) util.AddNetworkString( "sendDeag" ) util.AddNetworkString( "crateMenu" ) net.Start( "crateMenu" ) end end net.Receive( "sendAmmo", ggiveAmmo ) function ggiveAmmo() ply:GiveAmmo(200, "pistol") ply:GiveAmmo(200, "smg1") ply:GiveAmmo(200, "buckshot") ply:GiveAmmo(1, "grenade") end net.Receive( "sendMP5", giveMP5 ) function giveMP5() ply:AddMoney(-300) GAMEMODE:Notify(ply, 1, 4, "You bought a MP5 from the PD Armory for $300.") ply:Give("weapon_real_cs_mp5a5_cp") end net.Receive( "sendDeag", giveDeag ) function giveDeag() ply:AddMoney(-250) GAMEMODE:Notify(ply, 1, 4, "You bought a Desert Eagle from the PD Armory for $250.") ply:Give("weapon_real_cs_desert_eagle_cp") end[/LUA] Trying to create a derma menu ammo crate. This is my first time working with derma from scratch. When i click E on the entity it doesn't seem to do anything. Can anyone enlighten me as to what i'm doing wrong?
[QUOTE=MattJeanes;39291611]How do you find a hammer entity by it's name through Lua?[/QUOTE] It depends. Hammer entities such as "info_node" and "func_ladder" are built into the map upon VBSP compiling. You can't find them through LUA because they technically don't exist. You could find that kinda stuff with a module perhaps.
Sorry, you need to Log In to post a reply to this thread.