• What do you need help with? V3
    6,419 replies, posted
Hey guys, I am trying to get a keypad cracker working but I am having some issues... This is the lua code [CODE]if (SERVER) then AddCSLuaFile("shared.lua") end if (CLIENT) then SWEP.PrintName = "Keypad Cracker" SWEP.Slot = 4 SWEP.SlotPos = 1 SWEP.DrawAmmo = false SWEP.DrawCrosshair = true end -- Variables that are used on both client and server SWEP.Author = "Chief Tiger" SWEP.Instructions = "Left click to crack a keypad" SWEP.Contact = "" SWEP.Purpose = "" SWEP.ViewModelFOV = 62 SWEP.ViewModelFlip = false SWEP.ViewModel = Model("models/weapons/v_c4.mdl") SWEP.WorldModel = Model("models/weapons/w_c4.mdl") SWEP.Spawnable = false SWEP.AdminSpawnable = true SWEP.Sound = Sound("weapons/deagle/deagle-1.wav") SWEP.Primary.ClipSize = -1 -- Size of a clip SWEP.Primary.DefaultClip = 0 -- Default number of bullets in a clip SWEP.Primary.Automatic = false -- Automatic/Semi Auto SWEP.Primary.Ammo = "" SWEP.Secondary.ClipSize = -1 -- Size of a clip SWEP.Secondary.DefaultClip = -1 -- Default number of bullets in a clip SWEP.Secondary.Automatic = false -- Automatic/Semi Auto SWEP.Secondary.Ammo = "" SWEP.KeyCrackTime = 15 /*--------------------------------------------------------- Name: SWEP:Initialize() Desc: Called when the weapon is first loaded ---------------------------------------------------------*/ function SWEP:Initialize() if (SERVER) then self:SetWeaponHoldType("normal") end end /*--------------------------------------------------------- Name: SWEP:PrimaryAttack() Desc: +attack1 has been pressed ---------------------------------------------------------*/ function SWEP:PrimaryAttack() self.Weapon:SetNextPrimaryFire(CurTime() + .4) if self.IsCracking then return end local trace = self.Owner:GetEyeTrace() local e = trace.Entity if IsValid(e) and trace.HitPos:Distance(self.Owner:GetShootPos()) <= 300 and (e:GetClass() == "sent_keypad") then self.IsCracking = true self.StartCrack = CurTime() self.EndCrack = CurTime() + self.KeyCrackTime if SERVER then self:SetWeaponHoldType("pistol") timer.Create("KeyCrackSounds", 1, self.KeyCrackTime, function(wep) wep:EmitSound("buttons/blip2.wav", 100, 100) end, self) end if CLIENT then self.Dots = self.Dots or "" timer.Create("KeyCrackDots", 0.5, 0, function(wep) if not wep:IsValid() then timer.Destroy("KeyCrackDots") return end local len = string.len(wep.Dots) local dots = {[0]=".", [1]="..", [2]="...", [3]=""} wep.Dots = dots[len] end, self) end end end function SWEP:Holster() self.IsCracking = false if SERVER then timer.Destroy("KeyCrackSounds") end if CLIENT then timer.Destroy("KeyCrackDots") end return true end function SWEP:Succeed() self.IsCracking = false local trace = self.Owner:GetEyeTrace() if IsValid(trace.Entity) and trace.Entity:GetClass() == "sent_keypad" then local owner = trace.Entity:GetNWEntity("keypad_owner") trace.Entity:SetNWBool("keypad_access", true) trace.Entity:SetNWBool("keypad_showaccess", true) if (SERVER) then trace.Entity:EmitSound("buttons/button11.wav") owner:SendLua("LocalPlayer():ConCommand(\"+gm_special "..trace.Entity:GetNWInt("keypad_keygroup1").."\")") timer.Simple(trace.Entity:GetNWInt("keypad_length1"), function() owner:SendLua("LocalPlayer():ConCommand(\"-gm_special "..trace.Entity:GetNWInt("keypad_keygroup1").."\")") end) end timer.Simple(2, function() trace.Entity:SetNWBool("keypad_showaccess", false) end) end if SERVER then timer.Destroy("KeyCrackSounds") end if CLIENT then timer.Destroy("KeyCrackDots") end end function SWEP:Fail() self.IsCracking = false if SERVER then self:SetWeaponHoldType("normal") timer.Destroy("KeyCrackSounds") end if CLIENT then timer.Destroy("KeyCrackDots") end end function SWEP:Think() if self.IsCracking then local trace = self.Owner:GetEyeTrace() if not IsValid(trace.Entity) then self:Fail() end if trace.HitPos:Distance(self.Owner:GetShootPos()) > 300 or (trace.Entity:GetClass() != "sent_keypad") then self:Fail() end if self.EndCrack <= CurTime() then self:Succeed() end end end function SWEP:DrawHUD() if self.IsCracking then self.Dots = self.Dots or "" local w = ScrW() local h = ScrH() local x,y,width,height = w/2-w/10, h/3, w/5, h/15 draw.RoundedBox(8, x, y, width, height, Color(10,10,10,120)) local time = self.EndCrack - self.StartCrack local curtime = CurTime() - self.StartCrack local status = curtime/time local BarWidth = status * (width - 16) + 8 draw.RoundedBox(8, x+8, y+8, BarWidth, height - 16, Color(255-(status*255), 0+(status*255), 0, 255)) draw.SimpleText("Cracking"..self.Dots, "Trebuchet24", w/2, h/2 + height/2, Color(255,255,255,255), 1, 1) end end function SWEP:SecondaryAttack() self:PrimaryAttack() end[/CODE] This is also one of my errors I am getting xD pretty new to all this so sorry if this is something stupid >.< [QUOTE][ERROR] gamemodes/darkrp/entities/weapons/keypad_cracker/shared.lua:69: attempt to index local 'wep' (a nil value) 1. unknown - gamemodes/darkrp/entities/weapons/keypad_cracker/shared.lua:69 Timer Failed! [KeyCrackSounds][@gamemodes/darkrp/entities/weapons/keypad_cracker/shared.lua (line 68)][/QUOTE] I appreciate any help ^^
I have a simple question. I was going through these yesterday and I heard that _R was removed, How would I go about replacing this? [lua] -- Meta function function _R.Player:GetCash() return tonumber(self:GetNWInt("Cash")) end meta = nil [/lua] Thanks in advance.
[lua]local meta = FindMetaTable( "Player" ); function meta:GetCash( )[/lua]
How to type CapabilitiesAdd in GMod13? [lua] function ENT:Initialize() self:CapabilitiesAdd( CAP_MOVE_GROUND | CAP_ANIMATEDFACE | CAP_TURN_HEAD | CAP_USE_SHOT_REGULATOR | CAP_USE | CAP_WEAPON_RANGE_ATTACK1 | CAP_USE_WEAPONS | CAP_MOVE_SHOOT | CAP_WEAPON_RANGE_ATTACK2 | CAP_WEAPON_MELEE_ATTACK1 | CAP_WEAPON_MELEE_ATTACK2 | CAP_INNATE_RANGE_ATTACK1 | CAP_INNATE_RANGE_ATTACK2 | CAP_INNATE_MELEE_ATTACK1 | CAP_INNATE_MELEE_ATTACK2 ) end [/lua] tells [b]')' expected near '|'[/b]
I believe | is a bitwise operator [url]http://wiki.garrysmod.com/page/Libraries/bit[/url] You need something from there but unfortunately I don't know which function (one of the ors?), sorry! Try [b][url=http://wiki.garrysmod.com/page/Libraries/bit/bor]Libraries/bit/bor[img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] though
You should just be able to use + instead, even though its a bad practice and breaks down if two flags overlap [editline]3rd November 2012[/editline] Alternativly the non-hacky way is [lua]self:CapabilitiesAdd(bit.bor(CAP_MOVE_GROUND, CAP_ANIMATEDFACE, CAP_TURN_HEAD, CAP_USE_SHOT_REGULATOR, CAP_USE, CAP_WEAPON_RANGE_ATTACK1, CAP_USE_WEAPONS, CAP_MOVE_SHOOT, CAP_WEAPON_RANGE_ATTACK2, CAP_WEAPON_MELEE_ATTACK1, CAP_WEAPON_MELEE_ATTACK2, CAP_INNATE_RANGE_ATTACK1, CAP_INNATE_RANGE_ATTACK2, CAP_INNATE_MELEE_ATTACK1, CAP_INNATE_MELEE_ATTACK2))[/lua]
Another problem. How NPC schedules are done now? [lua] local schdHide = ai_schedule.New( "Hide" ) schdHide:EngTask( "TASK_FIND_COVER_FROM_ENEMY", 0 ) schdHide:EngTask( "TASK_FACE_REASONABLE", 0 ) ... self:StartSchedule( schdHide ) [/lua] Tells [code] [ERROR] lua/includes/modules/ai_task.lua:91: bad argument #1 to 'StartEngineTask' (number expected, got nil) 1. StartEngineTask - [C]:-1 2. Start - lua/includes/modules/ai_task.lua:91 3. StartTask - gamemodes/base/entities/entities/base_ai/schedules.lua:137 4. SetTask - gamemodes/base/entities/entities/base_ai/schedules.lua:104 5. StartSchedule - gamemodes/base/entities/entities/base_ai/schedules.lua:59 6. SelectSchedule - addons/mynpc/lua/entities/npc_mytest/init.lua:421 7. unknown - gamemodes/base/entities/entities/base_ai/schedules.lua:28 [ERROR] lua/includes/modules/ai_task.lua:117: bad argument #1 to 'RunEngineTask' (number expected, got nil) 1. RunEngineTask - [C]:-1 2. Run - lua/includes/modules/ai_task.lua:117 3. RunTask - gamemodes/base/entities/entities/base_ai/schedules.lua:148 4. DoSchedule - gamemodes/base/entities/entities/base_ai/schedules.lua:71 5. unknown - gamemodes/base/entities/entities/base_ai/schedules.lua:22 [/code] Where to find all Lua changes for GMod13?
I think the SNPC stuff was removed and will be replaced later on.
Is there a way to use ACT_ animations on ClientsideModels?
What is required in making Getscriptedvehicle a function?
#1 [ERROR] ... attempt to index local 'pl' (a nil value) [LUA]function GM:SetPlayerSpeed(pl, walk) pl.WalkSpeed = walk --Here problem occured-- pl:SetWalkSpeed(walk) pl:SetRunSpeed(walk) end[/LUA] #2 [ERROR] ... attempt to index global 'arg' (a nil value) [LUA]for i=1, arg.n do --And here :D-- local str = arg[i] if not CachedMarkups[str] then CachedMarkups[str] = markup.Parse(str) end end[/LUA]
Did the latest update break ShouldCollide? This shit isn't working: [lua] function ShouldCollideWithPlayer( ent1, ent2 ) if ( ent1:IsPlayer() and ent2:IsPlayer() ) then return false end return true end hook.Add("ShouldCollide", "ShouldCollideWithPlayer", ShouldCollideWithPlayer) [/lua] And it worked last update. :<
Having some issues with GetModelScale and SetModelScale in GMod 13. So i'm fully aware of the changes for SetModelScale in GMod 13, when scaling a Vector you need to use the Matrix thing. This works okay to being with: [lua] local scale = Vector( 0.3, 0.3, 0.3 ) local mat = Matrix() mat:Scale( scale ) entity.EnableMatrix( "RenderMultiply", mat ) [/lua] Now when i want to enlarger my prop by a bit from time to time, i want to use GetModelScale + a vector. This does not work like it used to. [lua] local scale = self:GetModelScale() + Vector( .05, .05, .05 ) local mat = Matrix() mat:Scale( scale ) self:EnableMatrix( "RenderMultiply", mat ) [/lua] It says for this line "local scale = self:GetModelScale() + Vector( .05, .05, .05 )": bad arguement to #2 to '__add' (Vector expected, got number) Apparently its the GetModelScale() that returns a number. Does anybody know how i would get around to fixing this issue? Thank you.
GetModelScale now returns a number, what you used in SetModelScale. Store the matrix on the entity, and change that, since EnableMatrix does not provide any way to read the set matrix.
[QUOTE=ollie;38290251]Does anyone know why was Player.GetScriptedVehicle() removed and what to use now?[/QUOTE] I'm needing this really badly.. Does anyone have the old gmod server-side files saved to somewhere?
[QUOTE=Lukikot;38301281]#2 [ERROR] ... attempt to index global 'arg' (a nil value) [LUA]for i=1, arg.n do --And here :D-- local str = arg[i] if not CachedMarkups[str] then CachedMarkups[str] = markup.Parse(str) end end[/LUA][/QUOTE] [lua] for _, str in pairs { ... } do if not CachedMarkups[str] then CachedMarkups[str] = markup.Parse(str) end end [/lua] arg was removed.
I guess I'm doing timers right now, but I found this error through one being called. [code][ERROR] addons/warmelons/lua/autorun/server/wmrtscommands.lua:223: attempt to index local 'ply' (a nil value) 1. unknown - addons/warmelons/lua/autorun/server/wmrtscommands.lua:223 Timer Failed! [Simple][@addons/warmelons/lua/autorun/server/wmrtscommands.lua (line 202)][/code] Right now, I want to address line 202: [code] timer.Simple(2, WMInitialJoin)[/code] The function follows right after and is only called when a player joins the game [code]function WMInitialJoin(ply) for i=1,6 do local teammemcount = 0 local colors = {} colors[0] = "admin" colors[1] = "red" colors[2] = "blue" colors[3] = "green" colors[4] = "yellow" colors[5] = "magenta" colors[6] = "cyan" local allplayers = player.GetAll() for k, v in pairs (allplayers) do if v:GetNetworkedInt( "melonteam") == i then teammemcount = teammemcount + 1 end end if teammemcount < GetConVarNumber( "WM_PlayersPerTeam", 1) then 223- ply:SetNetworkedInt( "melonteam" , i); for x, y in pairs (allplayers) do local message = ply:GetName() .. " has joined team " .. i .. ", (" ..colors[i].. ")." Msg(ply:GetName() .. " joined team " .. i .. ", (" .. colors[i].. ").") y:PrintMessage(HUD_PRINTTALK, message); end return end end end[/code] It seems line 223 is the source of the problem in the timer. I've looked, and apparently there is no instance when SetNetworkedInt uses "ply:" however ply is declared as a value for the function. Is this maybe a deprecated variable?
Quick question about args, I have seen in timer code and others a "for" statement with no arg but just a "_," after it what does this mean should there be a arg there or is this how it works in lua? What exactly does the _, do if it is suppost to be there if it is not what arg should take the place? Here are some code examples: [LUA]for _, str in pairs { ... } do if not CachedMarkups[str] then CachedMarkups[str] = markup.Parse(str) end end[/LUA] [LUA]local function resupplyplayers() for _, ply in pairs(player.GetHumans()) do -- make sure he's alive -- we're not interested in resupplying ghosts if ply:Alive then ply:GiveAmmo(60, "Pistol", true) -- feel free to change this value ply:ChatPrint("Resupplied!") end end timer.Create("Resupply", 60, 0, resupplyplayers)[/LUA]
I want to set up for the very first time a particle effect on a ViewModel of a weapon. [lua] function SWEP:Initialize() self:SetWeaponHoldType( self.HoldType ) ParticleEffectAttach("natur_gem", PATTACH_POINT_FOLLOW, self, 1) end [/lua] I basicaly don't know how I should do it. It seems that he just can't find the ViewModel, as he doesn't throw any errors. Help please?
[QUOTE=Lexic;38302877][lua] for _, str in pairs { ... } do if not CachedMarkups[str] then CachedMarkups[str] = markup.Parse(str) end end [/lua] arg was removed.[/QUOTE] Thank you.
[QUOTE=Jeffman12;38303602]I've looked, and apparently there is no instance when SetNetworkedInt uses "ply:" however ply is declared as a value for the function. Is this maybe a deprecated variable?[/QUOTE] It's because timer.Simple doesn't pass an argument to the function. If you're creating the timer in PlayerSpawn or PlayerInitialSpawn or somewhere you have access to the player in question, it'd be easier to make a local function specific to that player. Also, you should not be doing it the way you're doing it. [lua] -- Shared TEAM_RED = 1 TEAM_BLUE = 2 TEAM_GREEN = 3 TEAM_YELLOW = 4 TEAM_MAGENTA = 5 TEAM_CYAN = 6 TEAM_ADMIN = 7 team.SetUp(TEAM_RED, "Communists", Color(255, 90, 90)) team.SetUp(TEAM_BLUE, "Frostbite Party", Color(90, 90, 255)) team.SetUp(TEAM_GREEN, "League of Envy", Color(90, 255, 90)) team.SetUp(TEAM_YELLOW, "Banana Bunch", Color(255, 255, 90)) team.SetUp(TEAM_MAGENTA, "Magicians", Color(255, 90, 255)) team.SetUp(TEAM_CYAN, "Cyan Tribe", Color(90, 255, 90)) team.SetUp(TEAM_ADMIN, "Admin League", Color(255, 255, 255)) -- Serverside function GM:PlayerInitialSpawn(ply) timer.Simple(2, function() -- We'd use team.BestAutoJoinTeam() but that wouldn't exclude TEAM_ADMINS local smallestteam, smallestplayers = TEAM_RED, team.NumPlayers(TEAM_RED) for id, tm in pairs(team.GetAllTeams()) do if id ~= TEAM_SPECTATOR and id ~= TEAM_UNASSIGNED and id ~= TEAM_CONNECTING and id ~= TEAM_ADMIN then local count = team.NumPlayers(id) -- smaller than the last one we checked? if count < smallestplayers then smallestteam = id smallestplayers = count end end -- set his team, broadcast to all players. -- if all the teams were even, he'll be placed in Red by default ply:SetTeam(smallestteam) PrintMessage(HUD_PRINTTALK, ply:Nick() .. " has joined the " .. team.GetName(smallestteam) .. "!") end end [/lua]
[QUOTE=Nazban;38303953]Quick question about args, I have seen in timer code and others a "for" statement with no arg but just a "_," after it what does this mean should there be a arg there or is this how it works in lua?[/QUOTE] I use a _ because it's unimportant and never used. _ is just a name of the variable.
[QUOTE=Nazban;38303953]Quick question about args, I have seen in timer code and others a "for" statement with no arg but just a "_," after it what does this mean should there be a arg there or is this how it works in lua? What exactly does the _, do if it is suppost to be there if it is not what arg should take the place?[/QUOTE] The basic method of table iteration is to use something like this: [lua]table = {1, 2, 3} for key, value in pairs(table) do print("Key:", key, "Value:", value) end --[[ Key: 1 Value: 1 Key: 2 Value: 2 Key: 3 Value: 3 --]][/lua] This works even if you're using strings for keys: [lua]complex_table = { key_one = 1, key_two = 2, key_three = 3 } for key, value in pairs(complex_table) do print("Key:", key, "Value:", value) end --[[ Key: key_one Value: 1 Key: key_two Value: 2 Key: key_three Value: 3 --]] [/lua] But sometimes you don't care about what the keys in the table are, because they don't matter. The only thing that matters is the contents of the table. To save typing and confusion, you simply set the name of the key variable to be _. [lua] keyless_table = { 5, 7, 9 } for _, value in pairs(keyless_table) do print("Value:", value) end --[[ Value: 5 Value: 7 Value: 9 --]] [/lua] _ is a valid Lua variable name, and is often used when ignoring arguments in hooks or callbacks, such as [lua]concommand.Add("mycommand", function(ply, _, args) -- bla end)[/lua] or [lua]datastream.Hook("mystream", function(ply, _, _, _, data) -- not that anyone actually uses datastream end)[/lua]
[lua] Table = {} Table.String = "" Table.subTable = {} Table.subTable["Key"] = "Testing 1 2" [/lua] My question is, does Table = nil efficiently get rid of the table and everything in it? I'm assuming yes but I've never known for sure.
[IMG]http://puu.sh/1m6Al[/IMG] Is this impossible to trace? It happens when player spawns. I think Player.SendLua is causing it, but I am just trying to fix this gamemode. E: The problem fixed itself somehow, don't ask me why.
[QUOTE=find me;38305857][lua] Table = {} Table.String = "" Table.subTable = {} Table.subTable["Key"] = "Testing 1 2" [/lua] My question is, does Table = nil efficiently get rid of the table and everything in it? I'm assuming yes but I've never known for sure.[/QUOTE] Unless there are other references to the subtable, yes. It'll all get picked off the next time the garbage collector runs. [editline]3rd November 2012[/editline] [QUOTE=ollie;38305903][IMG]http://puu.sh/1m6Al[/IMG] Is this impossible to trace? It happens when player spawns. I think Player.SendLua is causing it, but I am just trying to fix this gamemode.[/QUOTE] Yeah that's caused by SendLua or BroadcastLua. Just do a find in files.
[QUOTE=Luni;38304912]It's because timer.Simple doesn't pass an argument to the function. If you're creating the timer in PlayerSpawn or PlayerInitialSpawn or somewhere you have access to the player in question, it'd be easier to make a local function specific to that player. Also, you should not be doing it the way you're doing it. [lua] -- Shared TEAM_RED = 1 TEAM_BLUE = 2 TEAM_GREEN = 3 TEAM_YELLOW = 4 TEAM_MAGENTA = 5 TEAM_CYAN = 6 TEAM_ADMIN = 7 team.SetUp(TEAM_RED, "Communists", Color(255, 90, 90)) team.SetUp(TEAM_BLUE, "Frostbite Party", Color(90, 90, 255)) team.SetUp(TEAM_GREEN, "League of Envy", Color(90, 255, 90)) team.SetUp(TEAM_YELLOW, "Banana Bunch", Color(255, 255, 90)) team.SetUp(TEAM_MAGENTA, "Magicians", Color(255, 90, 255)) team.SetUp(TEAM_CYAN, "Cyan Tribe", Color(90, 255, 90)) team.SetUp(TEAM_ADMIN, "Admin League", Color(255, 255, 255)) -- Serverside function GM:PlayerInitialSpawn(ply) timer.Simple(2, function() -- We'd use team.BestAutoJoinTeam() but that wouldn't exclude TEAM_ADMINS local smallestteam, smallestplayers = TEAM_RED, team.NumPlayers(TEAM_RED) for id, tm in pairs(team.GetAllTeams()) do if id ~= TEAM_SPECTATOR and id ~= TEAM_UNASSIGNED and id ~= TEAM_CONNECTING and id ~= TEAM_ADMIN then local count = team.NumPlayers(id) -- smaller than the last one we checked? if count < smallestplayers then smallestteam = id smallestplayers = count end end -- set his team, broadcast to all players. -- if all the teams were even, he'll be placed in Red by default ply:SetTeam(smallestteam) PrintMessage(HUD_PRINTTALK, ply:Nick() .. " has joined the " .. team.GetName(smallestteam) .. "!") end end [/lua][/QUOTE] It's not my code, I'm trying to fix it and update it. I don't think I have the skill to do this over from scratch.
Is there any way to make players not collide now? I tried using [url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexa58d.html[/url] The example didn't work, also tried: [lua] function GM:ShouldCollide( ent1, ent2 ) if ent1:IsPlayer() and ent2:IsPlayer() then return (ent1:Team() != ent2:Team()) end return true end [/lua] Any help?
Hey. [CODE] function GM:ShowSpare1( ply ) local DermaPanel = vgui.Create( "DFrame" ) DermaPanel:SetPos( 50,50 ) DermaPanel:SetSize( 500, 700 ) DermaPanel:SetTitle( "Testing Derma Stuff" ) DermaPanel:SetVisible( true ) DermaPanel:SetDraggable( true ) DermaPanel:ShowCloseButton( true ) DermaPanel:MakePopup() local DermaListView = vgui.Create("DListView") DermaListView:SetParent(DermaPanel) DermaListView:SetPos(25, 50) DermaListView:SetSize(450, 625) DermaListView:SetMultiSelect(false) DermaListView:AddColumn("Name") -- Add column DermaListView:AddColumn("Amount of kills") for k,v in pairs(player.GetAll()) do DermaListView:AddLine(v:Nick(),v:Frags()) -- Add lines end end[/CODE] The above code consistently returns: [CODE][ERROR] gamemodes/testmode/gamemode/blah.lua:42: attempt to index global 'vgui' (a nil value)[/CODE] Even though I've seen people in other threads with incredibly similar code and theirs works fine. My code doesn't work at all regardless of where I put it. It always returns that error. Anyone have any ideas or want me to post any other info?
The ShowHelp, ShowTeam, and ShowSpare hooks are serverside, and UI elements are clientside. You'll have to send a usermessage from server to client that tells the client to create/open a panel.
Sorry, you need to Log In to post a reply to this thread.