• What do you need help with? V3
    6,419 replies, posted
[QUOTE=obliviator;37528790]You need to put function in front of SWEP:Initialize() and SWEP:PrimaryAttack(). function SWEP:Initialize() function SWEP:PrimaryAttack()[/QUOTE] Ah, thanks. I keep idioticly forgetting things like that. xD
Okay, here's another dumb question. I'm trying to return the velocity of the player holding my SWEP, but i get an error saying: [lua\weapons\littlemod\shared.lua:31] attempt to index global 'self' (a nil value) I hope it's not annoying of me to post all these problems. I suck with LUA. :< Here's the code: [CODE]if (SERVER) then AddCSLuaFile( "shared.lua" ) SWEP.HoldType = "ar2" end if (CLIENT) then SWEP.PrintName = "Laser Assault Rifle" SWEP.Author = "Littleboyred1" SWEP.Slot = 3 SWEP.SlotPos = 1 SWEP.IconLetter = "w" killicon.AddFont( "weapon_ak47", "CSKillIcons", SWEP.IconLetter, Color( 255, 80, 0, 255 ) ) end SWEP.DrawCrosshair = true SWEP.DrawAmmo = true SWEP.Spawnable = false SWEP.AdminSpawnable = true SWEP.Weight = 5 SWEP.AutoSwitchTo = false SWEP.AutoSwitchFrom = false function SWEP:Initialize() timer.Create(timer1, 0.2, 0, ConeControl()) end function GetOwnerSpeed(player) return self.Owner:GetVelocity():Length() end function ConeControl() cone = GetOwnerSpeed()*0.004 end function SWEP:PrimaryAttack() if(!self:CanPrimaryAttack())then return end self:ShootBullet(60, 1, cone) self:SetNextPrimaryFire(CurTime()+0.15) end [/CODE]
How does the parenting in lua work? Like if I did Prop:SetParent(self.Owner) Prop:SetPos(Vector(0,0,0)) would it parent to the owners position or would it parent to world coordinates 0,0,0?
Lua has completely baffled me. The following code is clientside and tested IN GARRYSMOD with the "start multiplayer" [lua] if not v == LocalPlayer() then chat.AddText(Color(255,255,255,255), v:Name()) end [/lua] The if not argument always is returning false. I am testing it on bots.
Show us the whole code. Is v a valid variable?
[QUOTE=JustSoFaded;37531472]Show us the whole code. Is v a valid variable?[/QUOTE] [lua] for k, v in pairs(ents.FindInSphere(LocalPlayer():GetPos() + Vector(0,0,80), Metres2Units(dist))) do if v:IsPlayer() then if not v == LocalPlayer() then chat.AddText(Color(255,255,255,255), v:Name()) end end end [/lua]
Vector(x, y, z) is the format. Z is typically the third dimension (as seen below) [img]http://www.developria.com/upload/2008/02/papervision3d_part_1_foundatio/xyz_map.jpg[/img] However, since Valve is dumb they treat Z as Y. So basically that loop will be printing all entities that are "Found in that sphere", 80 units in the air. Now I'm not sure if that's what's causing the issue or not, but you should try removing the + Vector(0, 0, 80).
[QUOTE=JustSoFaded;37532163]Vector(x, y, z) is the format. Z is typically the third dimension (as seen below) [img]http://www.developria.com/upload/2008/02/papervision3d_part_1_foundatio/xyz_map.jpg[/img] However, since Valve is dumb they treat Z as Y. So basically that loop will be printing all entities that are "Found in that sphere", 80 units in the air. Now I'm not sure if that's what's causing the issue or not, but you should try removing the + Vector(0, 0, 80).[/QUOTE] That isn't the problem because without the [lua] if not v == LocalPlayer() then [/lua] it works perfectly fine.
[QUOTE=Blackfire76;37532216]That isn't the problem because without the [lua] if not v == LocalPlayer() then [/lua] it works perfectly fine.[/QUOTE] if v ~= LocalPlayer() then
They are the same statement. [img]http://puu.sh/11S7s[/img]
[QUOTE=Greetings;37532252]if v ~= LocalPlayer() then[/QUOTE] It worked... :pwn:
[QUOTE=JustSoFaded;37532455]They are the same statement. [img]http://puu.sh/11S7s[/img][/QUOTE] Try without the () around it. The not might be executed before the ==, which would make it (not v) == LocalPlayer(), instead of the example you gave...
Could someone tell me what is wrong with this? [code] concommand.Add("kill_all", killall) function killall() for _, v in pairs( player.GetAll() ) do v:Kill() end end [/code]
You're trying to use the "killall" function before it's defined, move the concommand.Add call after the function.
Well I got it to work the thing is that I was running the command clientside when I tryed running it on the server it worked.
I've run into a bit of a problem with my custom HUD for a gamemode I'm making. I'm working on the gamemode from two different computers, which isn't as big of a problem as it sounds: whenever I finish modifying the lua files, I just copy and overwrite the files onto the second computer. Everything works perfectly except for my custom HUD. The code is extremely simple and shouldn't be causing any problems. [lua] function DrawHudBackground() surface.SetTexture(surface.GetTextureID("MonopolyInterface/hudfinal")) surface.SetDrawColor(255, 255, 255, 255) surface.DrawTexturedRect(0, 0, ScrW(), ScrH()) end [/lua] The function is later called with a typical HUDPaint hook. On my primary computer, the HUD works perfectly. On the secondary computer, I get a missing texture. The file is most definitely there and follows the same filepath on both computers. I can't think of anything else that would be causing an issue. Any thoughts? I don't get any lua errors at all - just a missing texture screen.
[QUOTE=teras23;37535271]Well I got it to work the thing is that I was running the command clientside when I tryed running it on the server it worked.[/QUOTE] That's because Kill() is a server function
Is it possible to make a CSEnt or class CPhysPropClientside gib? If so how? Calling e:GibBreakClient seems to do nothing.
-solved-
[QUOTE=ROFLBURGER;37538789]For some reason my headcrab script doesn't seem to be working as I expected This is serverside [lua] timer.Create("hurttimer", 1, 0, function() ply:SetHealth(plyAttacker:Health()-10) crab:EmitSound("npc/headcrab/headbite.wav",500,100) end) if !ply:IsValid() or !ply:Alive() or ply:Health() < 1 then timer.Destroy("hurttimer") moan:Stop() --part of something else in the script prop:Remove() --part of something else in the script if ply:IsValid() && ply:Alive() then ply:Kill() end [/lua] I keep getting stuck at 0 health, it's not killing me or anything. Is there another way to do this?[/QUOTE] Well for one, you're missing an end.
[QUOTE=skar;37540207]Well for one, you're missing an end.[/QUOTE] Yeah it's in the complete code, I just forgot to include it in my paste. Also I've solved my problems. I just put lines 6 through 10 in the timer function.
I have an automatic SWEP and when I shoot, the sound only plays half of the time. Is this an Emit Sound glitch or what? [lua] SWEP.Primary.Sound = Sound("weapons/mp7/mp7.wav") -- Shooting functions largely copied from weapon_cs_base function SWEP:PrimaryAttack(worldsnd) self.Weapon:SetNextSecondaryFire( CurTime() + self.Primary.Delay ) self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay ) if not self:CanPrimaryAttack() then return end if not worldsnd then self.Weapon:EmitSound( self.Primary.Sound, self.Primary.SoundLevel ) elseif SERVER then WorldSound(self.Primary.Sound, self:GetPos(), self.Primary.SoundLevel) end self:ShootBullet( self.Primary.Damage, self.Primary.Recoil, self.Primary.NumShots, self:GetPrimaryCone() ) self:TakePrimaryAmmo( 1 ) local owner = self.Owner if not ValidEntity(owner) or owner:IsNPC() or (not owner.ViewPunch) then return end owner:ViewPunch( Angle( math.Rand(-0.2,-0.1) * self.Primary.Recoil, math.Rand(-0.1,0.1) *self.Primary.Recoil, 0 ) ) end [/lua] Also how do i make it so you can't shoot for at least 5 seconds when you deploy a weapon.
[QUOTE=brandonj4;37542270] [lua] SWEP.Primary.Sound = Sound("weapons/mp7/mp7.wav") -- Shooting functions largely copied from weapon_cs_base function SWEP:PrimaryAttack(worldsnd) self.Weapon:SetNextSecondaryFire( CurTime() + self.Primary.Delay ) self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay ) if not self:CanPrimaryAttack() then return end if not worldsnd then self.Weapon:EmitSound( self.Primary.Sound, self.Primary.SoundLevel ) elseif SERVER then WorldSound(self.Primary.Sound, self:GetPos(), self.Primary.SoundLevel) end self:ShootBullet( self.Primary.Damage, self.Primary.Recoil, self.Primary.NumShots, self:GetPrimaryCone() ) self:TakePrimaryAmmo( 1 ) local owner = self.Owner if not ValidEntity(owner) or owner:IsNPC() or (not owner.ViewPunch) then return end owner:ViewPunch( Angle( math.Rand(-0.2,-0.1) * self.Primary.Recoil, math.Rand(-0.1,0.1) *self.Primary.Recoil, 0 ) ) end [/lua] [/QUOTE] util.PrecacheSound(sound)
[QUOTE=PencilOnDesk;37543784]util.PrecacheSound(sound)[/QUOTE] Alright i'll try that later. What about delaying it for 5 seconds when you deploy instead of automatically shooting when you pull the weapon out? SetNextPrimaryFire() solved it
How can I check to see if there is atleast 2 players in a game before I start a timer and a round, I have a small timer script, I also need to know how to make it so all players cannot spawn until there are atleast two and then the round will start. Here's the small script for the round timer I have, not great. [LUA] if CLIENT then local timeleft = 0 local function TimerStatus() usermessage.Hook("TimeLeft", function(um) timeleft = um:ReadShort() end) if timeleft > 0 then return timeleft else return "Round Finished." end end local function DrawTime() draw.SimpleText(TimerStatus(), "HUDNumber5", ScrW() / 2, 20, Color(255, 0, 0, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER) end hook.Add("HUDPaint", "drawtime", DrawTime) else local roundtime = 120 local roundstart = 0 local timeleft = 0 local function SetupNewRound() timeleft = 0 roundstart = CurTime() end local function SendTimeLeft() timeleft = roundtime - (CurTime() - roundstart) umsg.Start("TimeLeft") umsg.Short(timeleft) umsg.End() if timeleft <= 0 then for _, v in pairs(player.GetAll()) do v:StripWeapons() v:StripAmmo() v:Kill() v:Spawn() end SetupNewRound() end end hook.Add("Tick", "sendtimeleft", SendTimeLeft) end [/LUA]
so well getting an issue with draw priorities as you can see in the LOWER RIGHT of the screen where the GREEN ENERGY text is, its getting drawn BEHIND the black bar,how can i make it so it draws Above it? [IMG]http://img207.imageshack.us/img207/8388/27493869.png[/IMG] and as last any hint to how to recreate an flicker effect? i.e lerp or use math.approach to reach a specific value, then now on the new value, repeat it but go backwards instead, then forward a SPECIFIC number of times i was thinking about keeping the 2 values into a function and keep a track of how much times i have reached the value but i got easly confused hate maths
[QUOTE=Oaksin;37546388]-snip-[/QUOTE] [lua] local players = player.GetAll() if #players < 2 then return end [/lua]
In Fretta how would I go about setting 25% of the players on server to change to team 2 after a random selection of them? Thanks for any help
[QUOTE=werewolf0020;37546399]so well getting an issue with draw priorities as you can see in the LOWER RIGHT of the screen where the GREEN ENERGY text is, its getting drawn BEHIND the black bar,how can i make it so it draws Above it? [IMG]http://img207.imageshack.us/img207/8388/27493869.png[/IMG] and as last any hint to how to recreate an flicker effect? i.e lerp or use math.approach to reach a specific value, then now on the new value, repeat it but go backwards instead, then forward a SPECIFIC number of times i was thinking about keeping the 2 values into a function and keep a track of how much times i have reached the value but i got easly confused hate maths[/QUOTE] Stuff always draws in the order it's called, if you want the text on top of the bar, draw the bar before the text? For things like flickering it's best to use sin/cos on CurTime(), if you want it faster/slower change the frequency (multiply CurTime by a constant before you take sin/cos of it).
[QUOTE=georgeface;37547146]In Fretta how would I go about setting 25% of the players on server to change to team 2 after a random selection of them? Thanks for any help[/QUOTE] [lua] local plys = player.GetAll() for i=1, #plys/4 do table.remove(plys,math.random(#plys)):SetTeam(2) end [/lua]
Sorry, you need to Log In to post a reply to this thread.