• What do you need help with? V3
    6,419 replies, posted
Does anyone know how to fix this problem with DModelPanels? At the bottom the model doesn't disappear after going below the menu. -snip- [editline]Edited[/editline] I found a solution to it thanks to [URL="http://www.facepunch.com/showthread.php?t=1160598&p=37089922&viewfull=1#post37089922"]Crap-Head[/URL]. [lua] local PANEL = {} function PANEL:Paint() local x, y = self:LocalToScreen( 0, 0 ) local w, h = self:GetSize() local sl, st, sr, sb = x, y, x + w, y + h local p = self while p:GetParent() do p = p:GetParent() local pl, pt = p:LocalToScreen( 0, 0 ) local pr, pb = pl + p:GetWide(), pt + p:GetTall() sl = sl < pl and pl or sl st = st < pt and pt or st sr = sr > pr and pr or sr sb = sb > pb and pb or sb end render.SetScissorRect( sl, st, sr, sb, true ) self.BaseClass.Paint( self ) render.SetScissorRect( 0, 0, 0, 0, false ) end vgui.Register( "DModelPanel2", PANEL, "DModelPanel" ) [/lua]
[QUOTE=Nalestom;37671963]For whatever reason, this function isn't working. I'm not entirely sure why. Anybody have any ideas? [lua] function MoneyForKill(victim, inflictor, killer) local steamID = killer:SteamID() local currentmoney = sql.QueryValue("SELECT money FROM player_info WHERE steam_id = '"..steamID.."'") local killmoney = currentmoney + 500 if inflictor:IsWeapon() == true and killer:IsPlayer() == true then killer:SetNWInt("money", killmoney) print(killer:GetNWInt("money")) --Debugging print(""..killer:GetName().." has killed "..victim:GetName().." and gained "..killmoney.."!\n") end end hook.Add("PlayerDeath", "PlayerDies", MoneyForKill) [/lua][/QUOTE] See how this goes for you: [lua] function MoneyForKill(victim, inflictor, killer) local steamID = killer:SteamID() local currentmoney = sql.QueryValue("SELECT money FROM player_info WHERE steam_id = '"..steamID.."'") local killmoney = currentmoney + 500 if killer:IsPlayer() and (inflictor:IsValid() or killer:GetActiveWeapon():IsValid()) and (inflictor:IsWeapon() or killer:GetActiveWeapon():IsWeapon()) then killer:SetNWInt("money", killmoney) end end hook.Add("PlayerDeath", "PlayerDies", MoneyForKill) [/lua]
[QUOTE=brandonj4;37672704]See how this goes for you: [lua] function MoneyForKill(victim, inflictor, killer) local steamID = killer:SteamID() local currentmoney = sql.QueryValue("SELECT money FROM player_info WHERE steam_id = '"..steamID.."'") local killmoney = currentmoney + 500 if killer:IsPlayer() and (inflictor:IsValid() or killer:GetActiveWeapon():IsValid()) and (inflictor:IsWeapon() or killer:GetActiveWeapon():IsWeapon()) then killer:SetNWInt("money", killmoney) end end hook.Add("PlayerDeath", "PlayerDies", MoneyForKill) [/lua][/QUOTE] Works perfectly. Thank you. =)
[lua]function AddDir(dir) // recursively adds everything in a directory to be downloaded by client local list = file.FindDir(dir.."/*", "GAME") for _, fdir in pairs(list) do if fdir != ".svn" then // don't spam people with useless .svn folders AddDir(dir.."/"..fdir) end end for k,v in pairs(file.Find("../"..dir.."/*", "GAME")) do resource.AddFile(dir.."/"..v) end end [/lua] This snippet I use for clients to download content from the server. However, it doesn't work anymore in Gmod13. What could be wrong with the script? I got an error which I don't understand: [@lua/autorun/server/resources.lua:9] bad argument #1 to 'pairs' (table expected, got no value)
[QUOTE=jdmmer;37673414][lua]function AddDir(dir) // recursively adds everything in a directory to be downloaded by client local list = file.FindDir(dir.."/*", "GAME") for _, fdir in pairs(list) do if fdir != ".svn" then // don't spam people with useless .svn folders AddDir(dir.."/"..fdir) end end for k,v in pairs(file.Find(dir.."/*", "GAME")) do resource.AddFile(dir.."/"..v) end end [/lua] This snippet I use for clients to download content from the server. However, it doesn't work anymore in Gmod13. What could be wrong with the script? I got an error which I don't understand: [@lua/autorun/server/resources.lua:9] bad argument #1 to 'pairs' (table expected, got no value)[/QUOTE] Remove the ' "../".. ' on line 9 like I did above, the "GAME" part makes it search relative to the game folder, the "../" is making it go back a directory. Thats all I can think of at least. Also still waiting on: [QUOTE=Cushie;37661579]Would using the built-in SQL functions be more or less expensive than file-based storage?[/QUOTE]
File storage is fastest for small amounts of data, when the files get big SQL is considerably faster.
I need help drawing a sprite with alpha (so it is partially invisible) [lua]local mat = Material( "Ash47_CC/Tiles/4b" ) function ENT:Draw() render.SetMaterial( mat ) render.DrawSprite( self:GetPos() + Vector(0, 0, 32), 64, 64) end[/lua] The material has an alpha channel in it, and I am able to draw it with alpha if I use the surface.draw commands, however, It then ignores the z (depth), and looks terrible. I've tried tons of different settings in the VMT, this is what it currently looks like: [code]"Sprite" { "$basetexture" "Ash47_CC/Tiles/4b" "$spriteorientation" "parallel_upright" "$spriteorigin" "[ 0.50 1 ]" "$vertexalpha" "1" } [/code] Edit: [b]Solved it myself once again[/b]: 4B.VMT should be: [code]"UnlitGeneric" { "$basetexture" "Ash47_CC/Tiles/4b" "$vertexcolor" 1 "$vertexalpha" 1 } [/code] and I needed to add the line: [lua]local mat = Material("Ash47_CC/Tiles/4b") ENT.RenderGroup = RENDERGROUP_TRANSLUCENT[/lua] and to draw it: [lua] function ENT:Draw() render.SetMaterial( self.mat ) render.DrawSprite( self:GetPos() + Vector(0, 0, 32), 32, 32) end[/lua]
[QUOTE=jdmmer;37673414][lua]function AddDir(dir) // recursively adds everything in a directory to be downloaded by client local list = file.FindDir(dir.."/*", "GAME") for _, fdir in pairs(list) do if fdir != ".svn" then // don't spam people with useless .svn folders AddDir(dir.."/"..fdir) end end for k,v in pairs(file.Find("../"..dir.."/*", "GAME")) do resource.AddFile(dir.."/"..v) end end [/lua] This snippet I use for clients to download content from the server. However, it doesn't work anymore in Gmod13. What could be wrong with the script? I got an error which I don't understand: [@lua/autorun/server/resources.lua:9] bad argument #1 to 'pairs' (table expected, got no value)[/QUOTE] [lua] function AddDir(dir) // recursively adds everything in a directory to be downloaded by client local list = file.FindDir(dir.."/*", "DATA") for _, fdir in pairs(list) do if fdir != ".svn" then // don't spam people with useless .svn folders AddDir(dir.."/"..fdir) end end for k,v in pairs(file.Find(dir.."/*", "GAME")) do resource.AddFile(dir.."/"..v) end end [/lua] I had the same problem. The code above works perfectly fine.
[QUOTE=Drakehawke;37674056]File storage is fastest for small amounts of data, when the files get big SQL is considerably faster.[/QUOTE] Thanks, but at what point would you define big? We get about 4000 unique players a month and each one has their own data file, ranging from 35b - 10kb depending on how long they have played.
[QUOTE=Cushie;37674469]Thanks, but at what point would you define big? We get about 4000 unique players a month and each one has their own data file, ranging from 35b - 10kb depending on how long they have played.[/QUOTE] For that kinda data I'd definitely go with SQL.
[QUOTE=Stillnex;37672168]There's no line resetting the self.Delay, so right now, it checks if self.Delay exists, if it doesn't, set the current time + 5, then it checks if self.Delay is less than the current time, it will work perfectly at the first time because the delay is set properly there, as the delay will maintain forever and ever the same, it will always be smaller, as the time didn't stop. Use this code: (Didn't test it, but should work.) [lua] ENT.Type = "anim" ENT.PrintName = "Zombie - Spawner" ENT.Author = "Ninjadude" ENT.Spawnable = false ENT.AdminSpawnable = true ENT.Category = "NPC Spawners" ENT.SpawnEntity = "aura_zombie" ENT.MaxSpawnable = 2 ENT.Interval = 200 ENT.Radius = 400 ENT.Count = 0 ENT.SpawnedNPCs = {} if SERVER then AddCSLuaFile("shared.lua") function ENT:SpawnFunction( ply, tr ) if ( !tr.Hit ) then return end local SpawnPos = tr.HitPos + tr.HitNormal * 16 local ent = ents.Create( "npcspawner_aurazombie" ) ent:SetPos( SpawnPos ) ent:Spawn() ent:Activate() return ent end function ENT:Initialize() self:SetModel("models/dav0r/hoverball.mdl") self:PhysicsInit(SOLID_NONE) self:SetMoveType(MOVETYPE_NOCLIP) self:DrawShadow(false) self:DropToFloor() end function ENT:Think() self:NextThink( CurTime() + self.Interval ) for I,N in pairs( self.SpawnedNPCs ) do if not N:IsValid() then table.remove( self.SpawnedNPCs, I ) self.Count = self.Count - 1 end end if self.Count < self.MaxSpawnable then if !self.Delay then self.Delay = ( os.time() + 5 ) end if self.Delay < os.time() then local ent = ents.Create(self.SpawnEntity) if ent and ent:IsValid() then ent:SetPos(self:GetPos()) ent:SetModel("models/zed/malezed_0"..table.Random( {4, 6, 8} )..".mdl") ent:Spawn() end if not ent:IsInWorld() then ent:Remove() end self.Count = self.Count + 1 table.insert(self.SpawnedNPCs,ent) self.Delay = nil else --Please wait one minute before another zombie spawns. end end end end if CLIENT then function ENT:Draw() self.Entity:DrawModel() end end [/lua][/QUOTE] Yeah, this works, thanks alot <3
I have 2 questions: 1) When I click the default close button on my derma panel at Gmod13, the cursor is not active. I have to press F1 to make the cursor active again. How can I fix this, so that the cursor goes automatically active again? Also when a derma panel pops up, in the background the cursor is active. 2) [lua] function ENT:DrawEntityOutline( size ) size = size or 1.0 render.SuppressEngineLighting( true ) render.SetAmbientLight( 1, 1, 1 ) render.SetColorModulation( 1, 1, 1 ) // First Outline self:SetModelScale( ScaleOutline2 * size ) render.MaterialOverride( matOutlineBlack ) self:DrawModel() // Second Outline self:SetModelScale( ScaleOutline1 * size ) render.MaterialOverride( matOutlineWhite ) self:DrawModel() // Revert everything back to how it should be render.MaterialOverride( nil ) self:SetModelScale( ScaleNormal ) render.SuppressEngineLighting( false ) -- Gmod's 13 new way of doing this. local c = self:GetColor() local r,g,b,a = c.r, c.g, c.b, c.a render.SetColorModulation( r/255, g/255, b/255 ) end [/lua] I use this code to make a white border around my dropped items. However, the model just disappears now when looking at it. What could be the issue? Thanks in advance!
[QUOTE=Stillnex;37672168]There's no line resetting the self.Delay, so right now, it checks if self.Delay exists, if it doesn't, set the current time + 5, then it checks if self.Delay is less than the current time, it will work perfectly at the first time because the delay is set properly there, as the delay will maintain forever and ever the same, it will always be smaller, as the time didn't stop. Use this code: (Didn't test it, but should work.) [code]CODE[/code] [/QUOTE] Opps haha, thanks. You should just set the variable instead of making it nil every time though. I updated my original post with the corrections.
Alright, this is killing me. How do I do something like this (code below obviously doesn't work, I'm ignorant) [CODE] local table = {} table[1] = "this" table[2] = "is" table[3] = "a" table[4] = "table" for i = 1, #table do local table[i] = value --more code here end [/CODE] Or, in other words, how do I define a variable with a name drawn from a table?
[lua]local mytable = { "this", "is", "a", "table" } for k,v in pairs(mytable) do -- k is the key in the table, v is the value end[/lua]
[QUOTE=randomscript;37681507]Alright, this is killing me. How do I do something like this (code below obviously doesn't work, I'm ignorant) [CODE] local table = {} table[1] = "this" table[2] = "is" table[3] = "a" table[4] = "table" for i = 1, #table do local table[i] = value --more code here end [/CODE] Or, in other words, how do I define a variable with a name drawn from a table?[/QUOTE] if you want to randomize it i think you could just have a function that uses pairs and returns after it picks the first variable
[QUOTE=skar;37682418]if you want to randomize it i think you could just have a function that uses pairs and returns after it picks the first variable[/QUOTE] Not random. Need to define a unique variable for each loop using it's name from the table in sequence, meaning Banana Lord's solution doesn't really do much for me (unless it does, in which case forgive my ignorance). Is there even a way to do this?
[lua] local table = {} table[1] = "John" table[2] = "Jill" table[3] = "Alexander" table[4] = "Victoria" for i = 1, #table do local name = table[i]; if( name != "Victoria" ) then table[i] = string.reverse( name ); end end [/lua] All the values in the table besides "Victoria" will be replaced with the reversed string.
[QUOTE=JustSoFaded;37683507][lua] local table = {} table[1] = "John" table[2] = "Jill" table[3] = "Alexander" table[4] = "Victoria" for i = 1, #table do local name = table[i]; if( name != "Victoria" ) then table[i] = string.reverse( name ); end end [/lua] All the values in the table besides "Victoria" will be replaced with the reversed string.[/QUOTE] A little closer to what I need, but not quite. Imagine that, instead of defining [CODE] local name = table[i];[/CODE] I need to make a variable named "John" on the first loop, then "Jill", and so on. Is there a way to do this? Sorry for not explaining it very well.
Basically, what I've been trying to do is make it so when a player enter's noclip, the script: 1. Saves the starting point where they went into noclip 2. Save their eyeangle point when they went into clip 3. Send them back to the location they first started out at when they exit noclip. Problems: It won't send them back to the location they started off at and it doesnt set the eyeangles correctly. I can't seem to figure out why this is happening -_- [CODE]function AdminNoClip ( ply ) if (ply:GetMoveType() == MOVETYPE_NOCLIP) then print("noclip off") ply:SetPos( Vector(GetStartPos) ) ply:SetEyeAngles( Angle(GetEyeAngles) ) GetStartPos = nil GetEyeAngles = nil else print("noclip on") GetStartPos = ply:GetPos() GetEyeAngles = ply:EyeAngles() end end hook.Add("PlayerNoClip", "AdminNoClip", AdminNoClip)[/CODE]
Hello, Can someone help me i have thread of it already but ppl just put me as "dumb" idk why cause idk anything about pointshops angles,position i edited and copied the angle,position but now i want put it in my pointshop idk anything about where i put what :/ please help me: angles -1.057 -62.992 89.44 position 0.706 -3.141 0.265 and they need to be ModifyHat = function(ent, pos, ang) after that but idk where i put what ._. please help me Thanks
[QUOTE=randomscript;37684363]A little closer to what I need, but not quite. Imagine that, instead of defining [CODE] local name = table[i];[/CODE] I need to make a variable named "John" on the first loop, then "Jill", and so on. Is there a way to do this? Sorry for not explaining it very well.[/QUOTE] On the first loop, name will be John. On the second loop, name will be Jill. That does exactly what you're asking for. [editline]16th September 2012[/editline] [img]http://puu.sh/15Aox[/img] That might help you understand the loop better.
[QUOTE=JustSoFaded;37685018]On the first loop, name will be John. On the second loop, name will be Jill. That does exactly what you're asking for.[/QUOTE] I'm trying to define the name I get from the table as something else entirely, like [CODE] local table[i] = (thing goes here) MEANING on the first iteration, local John = (thing) on the second iteration, local Jill = (thing) [/CODE] The idea is to have a new variable defined on each iteration. I understand what you're saying, but it's not what I'm trying to do.
I literally can't think of a reason to have local John = "John", local Jill = "Jill". That's inefficient and pointless. What exactly are you trying to do?
I'm... I'm not trying to set the variable to its own name. The important part here is the name of the variable, not what it's defined as. Ignore the (thing) part of the above psuedocode.
So you're saying you want a table full of variable names, then you want to traverse the table and on each iteration set a local variable (named appropriately) to some other value? Why don't you explain what you're trying to do so I can help you further. If you want to talk about it privately feel free to PM me . [editline]16th September 2012[/editline] I really don't understand the point of doing that anyways.
[QUOTE=randomscript;37685086]I'm... I'm not trying to set the variable to its own name. The important part here is the name of the variable, not what it's defined as. Ignore the (thing) part of the above psuedocode.[/QUOTE] Just... Just why?
How can I make a PNG material additive, if possible.
[QUOTE=randomscript;37685086]I'm... I'm not trying to set the variable to its own name. The important part here is the name of the variable, not what it's defined as. Ignore the (thing) part of the above psuedocode.[/QUOTE] If you give us some context, we can give you a proper solution. Closest thing ot what you actually asked, however, is a table with non-numeric indexes. [lua] local table = {} table[1] = "John" table[2] = "Jill" table[3] = "Alexander" table[4] = "Victoria" local newtable = {} for i = 1, #table do local name = table[i]; newtable[name] = "some data" end print(newtable["John"]) [/lua] So, now we have a table you can think of as having different variable names (the variable names are actually called keys, and they are John, Victoria etc.) Untested, written in a rush, will explain more later if needed
[QUOTE=Trumple;37690051]If you give us some context, we can give you a proper solution. Closest thing ot what you actually asked, however, is a table with non-numeric indexes. [lua] local table = {} table[1] = "John" table[2] = "Jill" table[3] = "Alexander" table[4] = "Victoria" local newtable = {} for i = 1, #table do local name = table[i]; newtable[name] = "some data" end print(newtable["John"]) [/lua] So, now we have a table you can think of as having different variable names (the variable names are actually called keys, and they are John, Victoria etc.) Untested, written in a rush, will explain more later if needed[/QUOTE] This is the way you should be doing it
Sorry, you need to Log In to post a reply to this thread.