• Problems That Don't Need Their Own Thread v3.0
    5,003 replies, posted
[QUOTE=PigeonTroll;48643725]1) In a shared autorun file, do I still need the server to AddCSLuaFile? 2) Is there a reason why GetNWInt returns a string?[/QUOTE] 1) For some reasons yes, but if clientside code work in client without AddCSLuaFile - no. 2) tonumber([url=http://wiki.garrysmod.com/page/Entity/GetNWInt]GetNWInt[/url]( Network key ))
[QUOTE=UnkN;48643248][code] local newmat = GetRenderTarget("body"..ent:EntIndex()) local mat = CreateMaterial( "!body"..ent:EntIndex(), "VertexLitGeneric", { [ "$basetexture" ] = newmat:GetName(), [ "$vertexcolor" ] = 1, [ "$vertexalpha" ] = 1, } ) ent:SetSubMaterial(2,mat) [/code] Don't work :C *EDIT* When I use this material in surface.DrawTexturedRect all works fine.[/QUOTE] [lua] local newmat = GetRenderTarget("body"..ent:EntIndex()) local mat = CreateMaterial( "body"..ent:EntIndex(), "VertexLitGeneric", { [ "$basetexture" ] = newmat:GetName(), [ "$vertexcolor" ] = 1, [ "$vertexalpha" ] = 1, } ) ent:SetSubMaterial(2,"!body"..ent:EntIndex()) [/lua]
[QUOTE=Jvs;48644105][lua] local newmat = GetRenderTarget("body"..ent:EntIndex()) local mat = CreateMaterial( "body"..ent:EntIndex(), "VertexLitGeneric", { [ "$basetexture" ] = newmat:GetName(), [ "$vertexcolor" ] = 1, [ "$vertexalpha" ] = 1, } ) ent:SetSubMaterial(2,"!body"..ent:EntIndex()) [/lua][/QUOTE] I try do that, but this material make my model fully transparent... *EDIT* I remove $vertexcolor, $vertexalpha parameters + cut some render code and all work right. Thanks all for help!
Erm, thats joke? [code] ] lua_run print('util.Compress("Teststring123")') > ] [/code] Why util compress return ] !?
[QUOTE=UnkN;48645600]Erm, thats joke? [code] ] lua_run print('util.Compress("Teststring123")') > ] [/code] Why util compress return ] !?[/QUOTE] It's binary data, you won't be able to print it properly. It will still work with networking, etc - don't worry about it. [b]Edit:[/b] If you are networking it, be sure to use net.WriteData and net.ReadData, otherwise it won't work. You could base 64 encode the data as well (bearing in mind, there is no base 64 decode function, you'll have to find one).
[QUOTE=UnkN;48645600]Erm, thats joke? [code] ] lua_run print('util.Compress("Teststring123")') > ] [/code] Why util compress return ] !?[/QUOTE] It's a compressed string, with characters your console can't show. Try to write it to a file or something, and you will see everything properly. (Also, you're code is wrong as you quoted around the compressing, but I'm sure that was just a typo)
Ok so I launched garrysmod today after about a year and a gamemode that used to work now comes up with this error and crashes as soon as I try to start it. [IMG]http://puu.sh/k5oyk/757fc1d510.jpg[/IMG] I quickly went to the wiki and made a test gamemode but it still comes up with the same error. [url]http://wiki.garrysmod.com/page/Gamemode_Creation[/url] This is my gamemode txt file named test.txt [CODE]"test" { "base" "base" "title" "Test Gamemode" "maps" "^gm_|^gmod_" "menusystem" "1" }[/CODE] File is called test as well. [IMG]http://puu.sh/k5qa9/1ff7fc07fc.png[/IMG] My init.lua, cl_init.lua and shared.lua are just copy paste from the wiki. I'm sure it's a real simple fix I just can't work out whats wrong, maybe something has changed since I last coded.
[url]http://wiki.garrysmod.com/page/SANDBOX/PlayerSpawnedProp[/url] This hook says "Called when a player attempts to spawn a prop from the Q menu.", but it also gets called when something is pasted with the duplicator tool, does anyone know how to get around that?
[QUOTE=unrezt;48646174][url]http://wiki.garrysmod.com/page/SANDBOX/PlayerSpawnedProp[/url] This hook says "Called when a player attempts to spawn a prop from the Q menu.", but it also gets called when something is pasted with the duplicator tool, does anyone know how to get around that?[/QUOTE] Check if you use gm_spawn it'll call that hook as well, if it doesn't, then you can edit the way props are being spawned through the duplicator tool. If gm_spawn does trigger it, i think that this hook is being called every time any prop is being spawned.
[QUOTE=tzahush;48646427]Check if you use gm_spawn it'll call that hook as well, if it doesn't, then you can edit the way props are being spawned through the duplicator tool. If gm_spawn does trigger it, i think that this hook is being called every time any prop is being spawned.[/QUOTE] Yes gm_spawn triggers that hook, it's simply an alias for the Q menu spawn functions. Would be very bad if it was its own separate spawn function.
[QUOTE=UnkN;48645600]Erm, thats joke? [code] ] lua_run print('util.Compress("Teststring123")') > ] [/code] Why util compress return ] !?[/QUOTE] lua strings print until the first unprintable char, here's a fun little function I made to print strings and their hex values [lua] local printh = function(str) if not(type(str) == 'string') then str = tostring(str) end for i = 1, math.ceil(#str / 16) do local hex, dec = {}, {} for j = 1, 16 do local c = str[((i - 1) * 16) + j] local b = c:byte() if(#c > 0) then hex[#hex + 1] = string.format('%02X', b) dec[#dec + 1] = (b > 0x1F and b ~= 0x7F) and c or '.' else hex[#hex + 1] = ' ' dec[#dec + 1] = ' ' end end print(table.concat(hex, ' '), '', table.concat(dec)) end end[/lua] [img]https://d.maxfile.ro/hpuyrwebzh.png[/img]
[CODE] if SERVER then hook.Add("PlayerSpawn", "CPArmorStuff", function(ply) --if ply:isCombine() == true then print("A player has been spawned!") ply:SetArmor(250) --end end) end [/CODE] when i spawn, it prints "A player has been spawned". but it doesn't set my armor to 250, i tried restarting server. no luck,
[QUOTE=DaRkWoRlD1337;48647348][CODE] if SERVER then hook.Add("PlayerSpawn", "CPArmorStuff", function(ply) --if ply:isCombine() == true then print("A player has been spawned!") ply:SetArmor(250) --end end) end [/CODE] when i spawn, it prints "A player has been spawned". but it doesn't set my armor to 250, i tried restarting server. no luck,[/QUOTE] Some other player spawn hook might be setting the armor to 0. Try setting it on a simple timer of like, 1-2 seconds.
[QUOTE=PortalGod;48647124] [lua] local c = str[((i - 1) * 16) + j] local b = c:byte() [/lua] [/QUOTE] I know I am nitpicking but why not use string.byte directly? [code] local c = string.byte(str, (i - 1) * 16) + j) [/code]
[QUOTE=Z0mb1n3;48647791]Some other player spawn hook might be setting the armor to 0. Try setting it on a simple timer of like, 1-2 seconds.[/QUOTE] Thus began a paradox. Using a timer may seem to help at first, but it then becomes impossible to manage if another person also uses a timer. You could of course rewrite it, but then what if someone else creates a timer? How about another person? What if there are 20 timers running after a PlayerSpawn hook, wanting to set the armor? Alternative solution: Ask all addon/gamemode writers to use a standardized timer time, and write your code like this: [lua] ply:SetArmor(ply:GetArmor()+250); [/lua]
[QUOTE=MDave;48648069]I know I am nitpicking but why not use string.byte directly? [code] local c = string.byte(str, (i - 1) * 16) + j) [/code][/QUOTE] cause I still need to use c on line 15 (and I didn't know byte took two args :v:)
[QUOTE=MeepDarknessM;48648125]Thus began a paradox. Using a timer may seem to help at first, but it then becomes impossible to manage if another person also uses a timer. You could of course rewrite it, but then what if someone else creates a timer? How about another person? What if there are 20 timers running after a PlayerSpawn hook, wanting to set the armor? Alternative solution: Ask all addon/gamemode writers to use a standardized timer time, and write your code like this: [lua] ply:SetArmor(ply:GetArmor()+250); [/lua][/QUOTE] implying he has more than one addon that wants to set the armor in the first place? it's probably just the gamemode calling its default spawn junk.
[CODE]function SWEP:Holster() if CLIENT and IsValid(self.Owner) then local vm = self.Owner:GetViewModel() if IsValid(vm) then self:ResetBonePositions(vm) end end return true self:OnRemove() return true if ( IsValid( self.Owner ) && CLIENT && self.Owner:IsPlayer() ) then local vm = self.Owner:GetViewModel() if ( IsValid( vm ) ) then vm:SetMaterial( "" ) end end end[/CODE] With error: [Test] lua/weapons/testswep.lua:108: 'end' expected (to close 'function' at line 97) near 'self' 1. unknown - lua/weapons/suicidebomb.lua:0 Where do I put the end? Im so tired and finished with myself.
[QUOTE=deadpotato363;48650555][CODE]function SWEP:Holster() if CLIENT and IsValid(self.Owner) then local vm = self.Owner:GetViewModel() if IsValid(vm) then self:ResetBonePositions(vm) end end return true end --This is what is missing, but now the rest of your code doesn't make sense self:OnRemove() return true if ( IsValid( self.Owner ) && CLIENT && self.Owner:IsPlayer() ) then local vm = self.Owner:GetViewModel() if ( IsValid( vm ) ) then vm:SetMaterial( "" ) end end end[/CODE] With error: [Test] lua/weapons/testswep.lua:108: 'end' expected (to close 'function' at line 97) near 'self' 1. unknown - lua/weapons/suicidebomb.lua:0 Where do I put the end? Im so tired and finished with myself.[/QUOTE] Added the 'end' it is expecting, but now the rest of your code doesn't make sense (nothing will run after 'return'ing).
[QUOTE=deadpotato363;48650555][CODE]function SWEP:Holster() if CLIENT and IsValid(self.Owner) then local vm = self.Owner:GetViewModel() if IsValid(vm) then self:ResetBonePositions(vm) end end return true self:OnRemove() return true if ( IsValid( self.Owner ) && CLIENT && self.Owner:IsPlayer() ) then local vm = self.Owner:GetViewModel() if ( IsValid( vm ) ) then vm:SetMaterial( "" ) end end end[/CODE] With error: [Test] lua/weapons/testswep.lua:108: 'end' expected (to close 'function' at line 97) near 'self' 1. unknown - lua/weapons/suicidebomb.lua:0 Where do I put the end? Im so tired and finished with myself.[/QUOTE] You have "return true" statements in the middle of a function body. Lua parser doesn't allow a return statement to be anywhere else than a last statement in a function.
@mijyuoon and wh1t3rabbit I'm not entirely familiar with how Lua completely functions yet.Im merging the SWEP Construction Kit base with an existing SWEP. How would I rewrite that function for it to operate normally?
[QUOTE=deadpotato363;48650701]I'm not entirely familiar with how Lua completely functions yet.Im merging the SWEP Construction Kit base with an existing SWEP. How would I rewrite that function for it to operate normally?[/QUOTE] I'm not sure what you're trying to accomplish, but given the code you've provided this should 'operate normally': [CODE] function SWEP:Holster() if CLIENT and IsValid(self.Owner) then local vm = self.Owner:GetViewModel() if IsValid(vm) then self:ResetBonePositions(vm) vm:SetMaterial("") return true end end end function SWEP:OnRemove() -- called before the SWEP is removed end [/CODE]
Alright, I tried all that you people have mentioned and it fixed 1 problem and returned 2. The new problems are that the worldmodels I want to appear aren't appearing at all, and that you can't actually holster the SWEP now. Code: [CODE]AddCSLuaFile() SWEP.PrintName = "Blah Blah Blah" SWEP.Category = "Blah Blah Blah" SWEP.Author = "Blah Blah Blah" SWEP.Purpose = "Blah Blah Blah" SWEP.Spawnable = true SWEP.UseHands = true SWEP.DrawAmmo = false SWEP.Base = "weapon_base" SWEP.ViewModel = "models/weapons/v_slam.mdl" SWEP.WorldModel = "" SWEP.TraceLength = 500 SWEP.ViewModelFOV = 52 SWEP.Slot = 0 SWEP.SlotPos = 5 SWEP.Effect = "c4_explosion" SWEP.EffectAir = "c4_explosion_air" SWEP.WElements = { ["Detonator"] = { type = "Model", model = "models/Items/battery.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(4.675, 3.635, -3.636), angle = Angle(0, 0, 0), size = Vector(0.56, 0.56, 0.56), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }, ["Bomb1"] = { type = "Model", model = "models/dav0r/tnt/tnttimed.mdl", bone = "ValveBiped.Bip01_Spine4", rel = "", pos = Vector(-7.792, -9.87, -1.558), angle = Angle(-94.676, 171.817, 180), size = Vector(0.367, 0.367, 0.367), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }, ["Bomb3"] = { type = "Model", model = "models/dav0r/tnt/tnt.mdl", bone = "ValveBiped.Bip01_Spine4", rel = "", pos = Vector(-7.792, -9.87, -4.676), angle = Angle(-3.507, -101.689, -85.325), size = Vector(0.367, 0.367, 0.367), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }, ["Bomb2"] = { type = "Model", model = "models/dav0r/tnt/tnt.mdl", bone = "ValveBiped.Bip01_Spine4", rel = "", pos = Vector(-7.792, -9.87, 1.557), angle = Angle(-10.52, -104.027, -85.325), size = Vector(0.367, 0.367, 0.367), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} } } util.PrecacheModel( SWEP.ViewModel ) SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "none" SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" local Explosion = { "ambient/explosions/explode_1.wav" , "ambient/explosions/explode_2.wav" , "ambient/explosions/explode_3.wav" , "ambient/explosions/explode_4.wav" } local MuselScream = { "allakbar1.mp3", "allakbar2.mp3" , "allakbar3.mp3" } SWEP.DamageDistance = 1000 function SWEP:Initialize() self:SetHoldType( "slam" ) self.CanPerformAttack = true timer.Simple(0.05,function() self:SendWeaponAnim(ACT_SLAM_DETONATOR_IDLE) end) if CLIENT then // Create a new table for every weapon instance self.VElements = table.FullCopy( self.VElements ) self.WElements = table.FullCopy( self.WElements ) self.ViewModelBoneMods = table.FullCopy( self.ViewModelBoneMods ) self:CreateModels(self.VElements) // create viewmodels self:CreateModels(self.WElements) // create worldmodels // init view model bone build function if IsValid(self.Owner) then local vm = self.Owner:GetViewModel() if IsValid(vm) then self:ResetBonePositions(vm) // Init viewmodel visibility if (self.ShowViewModel == nil or self.ShowViewModel) then vm:SetColor(Color(255,255,255,255)) else // we set the alpha to 1 instead of 0 because else ViewModelDrawn stops being called vm:SetColor(Color(255,255,255,1)) // ^ stopped working in GMod 13 because you have to do Entity:SetRenderMode(1) for translucency to kick in // however for some reason the view model resets to render mode 0 every frame so we just apply a debug material to prevent it from drawing vm:SetMaterial("Debug/hsv") end end end end end function SWEP:Holster() if CLIENT and IsValid(self.Owner) then local vm = self.Owner:GetViewModel() if IsValid(vm) then self:ResetBonePositions(vm) vm:SetMaterial("") return true end end end function SWEP:OnRemove() end function SWEP:OnRemove() self:Holster() end if CLIENT then SWEP.vRenderOrder = nil function SWEP:ViewModelDrawn() local vm = self.Owner:GetViewModel() if !IsValid(vm) then return end if (!self.VElements) then return end self:UpdateBonePositions(vm) if (!self.vRenderOrder) then // we build a render order because sprites need to be drawn after models self.vRenderOrder = {} for k, v in pairs( self.VElements ) do if (v.type == "Model") then table.insert(self.vRenderOrder, 1, k) elseif (v.type == "Sprite" or v.type == "Quad") then table.insert(self.vRenderOrder, k) end end end for k, name in ipairs( self.vRenderOrder ) do local v = self.VElements[name] if (!v) then self.vRenderOrder = nil break end if (v.hide) then continue end local model = v.modelEnt local sprite = v.spriteMaterial if (!v.bone) then continue end local pos, ang = self:GetBoneOrientation( self.VElements, v, vm ) if (!pos) then continue end if (v.type == "Model" and IsValid(model)) then model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z ) ang:RotateAroundAxis(ang:Up(), v.angle.y) ang:RotateAroundAxis(ang:Right(), v.angle.p) ang:RotateAroundAxis(ang:Forward(), v.angle.r) model:SetAngles(ang) //model:SetModelScale(v.size) local matrix = Matrix() matrix:Scale(v.size) model:EnableMatrix( "RenderMultiply", matrix ) if (v.material == "") then model:SetMaterial("") elseif (model:GetMaterial() != v.material) then model:SetMaterial( v.material ) end if (v.skin and v.skin != model:GetSkin()) then model:SetSkin(v.skin) end if (v.bodygroup) then for k, v in pairs( v.bodygroup ) do if (model:GetBodygroup(k) != v) then model:SetBodygroup(k, v) end end end if (v.surpresslightning) then render.SuppressEngineLighting(true) end render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255) render.SetBlend(v.color.a/255) model:DrawModel() render.SetBlend(1) render.SetColorModulation(1, 1, 1) if (v.surpresslightning) then render.SuppressEngineLighting(false) end elseif (v.type == "Sprite" and sprite) then local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z render.SetMaterial(sprite) render.DrawSprite(drawpos, v.size.x, v.size.y, v.color) elseif (v.type == "Quad" and v.draw_func) then local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z ang:RotateAroundAxis(ang:Up(), v.angle.y) ang:RotateAroundAxis(ang:Right(), v.angle.p) ang:RotateAroundAxis(ang:Forward(), v.angle.r) cam.Start3D2D(drawpos, ang, v.size) v.draw_func( self ) cam.End3D2D() end end end SWEP.wRenderOrder = nil function SWEP:DrawWorldModel() if (self.ShowWorldModel == nil or self.ShowWorldModel) then self:DrawModel() end if (!self.WElements) then return end if (!self.wRenderOrder) then self.wRenderOrder = {} for k, v in pairs( self.WElements ) do if (v.type == "Model") then table.insert(self.wRenderOrder, 1, k) elseif (v.type == "Sprite" or v.type == "Quad") then table.insert(self.wRenderOrder, k) end end end if (IsValid(self.Owner)) then bone_ent = self.Owner else // when the weapon is dropped bone_ent = self end for k, name in pairs( self.wRenderOrder ) do local v = self.WElements[name] if (!v) then self.wRenderOrder = nil break end if (v.hide) then continue end local pos, ang
[QUOTE=deadpotato363;48650943]Alright, I tried all that you people have mentioned and it fixed 1 problem and returned 2. The new problems are that the worldmodels I want to appear aren't appearing at all, and that you can't actually holster the SWEP now.[/QUOTE] That looks like quite a mess, but to your points you never actually define a world model so change: [CODE]SWEP.WorldModel = ""[/CODE] To: [CODE]SWEP.WorldModel = "w_slam.mdl"[/CODE] Also, I made a slight error so replace the SWEP:Holster function I gave you before with this: [CODE] function SWEP:Holster() if CLIENT and IsValid(self.Owner) then local vm = self.Owner:GetViewModel() if IsValid(vm) then self:ResetBonePositions(vm) vm:SetMaterial("") end end return true end[/CODE]
Not 100% Garry's Mod related per se, but whatever. Is there any way to execute console commands in textmode? and is there any way to queue console commands once in-game? (i.e. not in the menu state and connected to a server)
Could anyone explain to me how would you be able to use these kind of table format. [code] Table = {} Table[0] = { Name = "Cool", Color = color_black, Func = function(ply) return ply:Name() end } Here a way to print each value ( Name, Color, Functions result ) [/code] And [code] Table = {} Table["Cool"] = { Color = color_black, Func = function(ply) return ply:Name() end } Here a way to print ( Cool, Color, Functions result ) [/code]
1: First, start your table with 1 instead of 0. [lua] for i, data in ipairs(Table) do for k, v in pairs(data) do if type(v) == "function" then print(v()) else print(v) end end end [/lua] 2: [lua] for name, data in pairs(Table) do for k, v in pairs(data) do if type(v) == "function" then print(v()) else print(v) end end end [/lua]
The math on one of my values keeps resetting? In one file I have: [code] classpect_base = {} classpect_base["health"] = 100 --CLASSES-- Lord = {} Lord["health"] = classpect_base["health"] + 100 print(" Lord health is "..Lord["health"] ) [/code] The print returns that it is indeed now at 200. However I use the table in another file, where I've use a print to check it [code] print(" Lord health is now "..Lord["health"].." ?!?!?!? " ) [/code] And this returns only 100 !
snip *RESTARTED MY GAME AND WORKED*
Anyone knows why my addons wont start? I just unzipped on of addons that worked not long ago and now it just won't start, I have the addons.txt file, I did the include and AddCSLuaFile thing but still doesn't show up and there are no errors.
Sorry, you need to Log In to post a reply to this thread.