• Problems That Don't Need Their Own Thread v2.0
    5,020 replies, posted
This seems like it should be really simple but I don't know how to make this work... I'm trying to get [code]local precRand = xFloor( math.Rand( .75, 1 ), 2 )[/code] to be the exact same number on both the server and client. I don't really want to resort to net messages. [editline]4th February 2015[/editline] Figured it out thanks to PortalGod telling me about randomseed: [code]math.randomseed( xFloor( CurTime( ), 1 ) )[/code] And xFloor is my own function: [code]function xFloor( num, decimal ) local mult = 10 ^ ( decimal or 0 ) return math.floor( num * mult ) / mult [/code] Maybe someone will find it useful - it changes the amount of decimals you want it to floor to.
Hello. I have a small problem, that I can't fix. I tried to reskin weapons, all works good, but scope painting too(like that:[URL="http://puu.sh/fvyNP/d80b5dbcaf.jpg"]PUU.SH[/URL]). I try to create another material by game, but it not helped. I see in css directory, see vmt files, tried to create with another parameters, but it not helped me:(. Maybe you can help me?
Hey guys. I'm using ENT:SetPoseParameters on my SENT to animate it. Right now it receives a value from math.Approach ran clientside, and while this works relatively well, the speed of the animation is framerate dependant. What's a more conventional way of animating props? I'm sure there's an alternative. Thanks.
[QUOTE=VIoxtar;47080527]Hey guys. I'm using ENT:SetPoseParameters on my SENT to animate it. Right now it receives a value from math.Approach ran clientside, and while this works relatively well, the speed of the animation is framerate dependant. What's a more conventional way of animating props? I'm sure there's an alternative. Thanks.[/QUOTE] You can use FrameTime() to get the time it took to draw the last frame, and divide the math.Approach's increment by that number. So if you were doing 1 animation frame per 1 game frame, right? If you multiply the amount of animation frames you want to be ran each second by the FrameTime() of each frame, it will make your animation run in real time rather than frame speed.
How would I make it so when a player kills another player, They get 10 added to a variable "points"? I've been trying multiple things and nothing works (although me trying mutiple things doesn't consist of alot, mostly wiki browsing and experimenting) And just a small question, If I have a variable called "points". What is the syntax I use to minus it from a player on the client lua file?
[QUOTE=Acecool;47078044]If you draw a model twice in different positions in the same frame, call self:SetupBones( ) on it. [editline]5th February 2015[/editline] You should have no trouble editing entities in your game-mode directory ( you have to spawn a new entity each time you change the code for the changes to appear though unless you redirect all functions to global functions for dev-work and then merge them back into the ent file when you're ready to release ). You can also update the Entities list with the new data ( look into adding entities without the entities folder ).[/QUOTE] The file still doesn't reload properly in a gamemode [img]http://puu.sh/fwpOX/a994d50040.png[/img] Also could you point me in the direction of adding entities to the Entities list?
any way to ignore // on strings?
[QUOTE=Scarface3353;47082899]any way to ignore // on strings?[/QUOTE] What are you trying to do?
[QUOTE=Revenge282;47083438]What are you trying to do?[/QUOTE] use sound.PlayURL
[QUOTE=Scarface3353;47083606]use sound.PlayURL[/QUOTE] wut? ([img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/sound/PlayURL]sound.PlayURL[/url]?)
local str = string.Replace("// // asfasdf//as", "//", "/") Is that what you're trying to do? Be more specific.
Are you worried that it'll turn into comments or something?
I'm a bit confused and always have been in this area. What should I use? Draw, Surface, or Derma? Should I use Surface for the HUD and Derma for all menus and VGUI related elements? I've tried using Derma for everything and it seems to work out fine, is this okay?
So this jittery animation has been happening on my new SENT I'm working on... [URL]http://a.pomf.se/zgeyno.mp4[/URL] The model is posed via a pose parameter called 'blendstates', which receives a number value (ranges from 0-65). I'm animating it in ENT:Think() ... on client (if CLIENT then) ..., by receiving a networked variable that includes its new pose, and the speed it takes to get to that pose. Then define a value by math.Approach to create a gradual animation, which SetPoseParameter then receives. (I'm also using CurTime() to make the animation;s speed independent of framerates. [B]This doesn't happen X minutes after server restart. It works fine first, and only then fucks up. Not sure how to replicate it myself or what's causing it.[/B] The code looks like this: [CODE] ENT:Think() if CLIENT then local fx = string.Explode("/", self:GetFX()) -- Creates a table (fx) with all the effects I want as number strings self.oldtime = self.newtime or 0 -- Not really relevant to my request self.newtime = CurTime() -- Same here self.oldanim = self.anim or 65 -- The last pose of the model. If nonexistent then it's 65 (claws are open) self.toanim = tonumber(fx[9]) -- fx[9] is a string which ranges from 0-65, basically the new pose. defines target pose (self.toanim) self.spdanim = tonumber(fx[10]) -- fx[10] is the speed of the animation, ranges are 150-600 ish self.anim = math.Approach(self.oldanim, self.toanim, (self.newtime-self.oldtime)*self.spdanim) -- defines the new pose SetPoseParameter will be receiving self:SetPoseParameter("blendstates", self.anim) -- self.anim is the new pose it receives end [/CODE] Can anyone pinpoint what exactly I'm doing wrong? Let me know if I wasn't clear on anything :S
[QUOTE=Kamber56;47082298]How would I make it so when a player kills another player, They get 10 added to a variable "points"? I've been trying multiple things and nothing works (although me trying mutiple things doesn't consist of alot, mostly wiki browsing and experimenting) And just a small question, If I have a variable called "points". What is the syntax I use to minus it from a player on the client lua file?[/QUOTE] Here's how I do it: [code]hook.Add("PlayerDeath", "WB_TB_PlayerDeath_unstackpoints", function(victim, _, attacker) if IsValid( attacker ) && attacker:IsPlayer() && attacker != victim then givePlayerPoints(attacker) end -- End the streak of the dying player unstackPlayer(victim) end)[/code] givePlayerPoints(player) is a helper function I defined somewhere else, replace it with what you actually want to do. Same for unstackPlayer, but that's less relevant to you. Adapt to your own code :)
Hey is GetWidth/GetHeight supposed to work on derma panels? I was trying to move an image to another position and while I remembered that MoveTo is a thing I can use instead, it felt odd this gave me nil
[QUOTE=Neat-Nit;47086293]Here's how I do it: [code]hook.Add("PlayerDeath", "WB_TB_PlayerDeath_unstackpoints", function(victim, _, attacker) if IsValid( attacker ) && attacker:IsPlayer() && attacker != victim then givePlayerPoints(attacker) end -- End the streak of the dying player unstackPlayer(victim) end)[/code] givePlayerPoints(player) is a helper function I defined somewhere else, replace it with what you actually want to do. Same for unstackPlayer, but that's less relevant to you. Adapt to your own code :)[/QUOTE] Thanks! Just a few questions though 1. What does the && do? 2. What does "attacker != victim then" do? (Specifically the !=) Thanks again
Is there a way to get the minimum distance between two entities/physobjects)? Horrible terrible miserable mock-up: [img]http://gyazo.com/2cfb74c4bc47f8870e7611bdc6bbaa16.png[/img] red distance = bad green distance = good In case it matters, one of the entities is actually a player.
[QUOTE=Kamber56;47086363]Thanks! Just a few questions though 1. What does the && do? 2. What does "attacker != victim then" do? (Specifically the !=) Thanks again[/QUOTE] && = and != = not equal to true && false = false true && true = true true != false = true true != true = false Awww yeah, double ninja.
[QUOTE=Kamber56;47086363]Thanks! Just a few questions though 1. What does the && do? 2. What does "attacker != victim then" do? (Specifically the !=) Thanks again[/QUOTE] 1. means 'and' 2. means 'does not equal', so it's useful to make sure players don't get points for suiciding [editline]6th February 2015[/editline] FUCK
[QUOTE=Kamber56;47086363]Thanks! Just a few questions though 1. What does the && do? 2. What does "attacker != victim then" do? (Specifically the !=) Thanks again[/QUOTE] != is the opposite of ==. That means that if two values are NOT the same, it returns true. If they ARE the same, it returns false. In this case, I'm making sure that the that the player didn't kill himself. && is the same as [b]and[/b]. [url]http://www.lua.org/pil/3.3.html[/url] Edit: ninja'd >< Any idea why PIL jumps straight to using [b]and[/b] and [b]or[/b] for choosing between variables rather than actual boolean evaluations? Seems totally newbie-unfriendly.
-automerge, fuck-
[lua]for k, ply in pairs(ents.FindByClass("Player")) do if ply:GetName() == name then[/lua] If I have code like this in the GM:PlayerConnect hook, after it finds all the players and gets the information that one of the players name is relevant to the name, would further association of ply be with that specific player or still every player on the server? If it would still apply to everyone on the server, is there a better way I could do this? Thanks.
[QUOTE=SteelSliver;47086590][lua]for k, ply in pairs(ents.FindByClass("Player")) do if ply:GetName() == name then[/lua] If I have code like this in the GM:PlayerConnect hook, after it finds all the players and gets the information that one of the players name is relevant to the name, would further association of ply be with that specific player or still every player on the server? If it would still apply to everyone on the server, is there a better way I could do this? Thanks.[/QUOTE] I don't understand 100% what you're asking. It would help if you explain what you're trying to do. By the way, you can use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/player/GetAll]player.GetAll[/url] instead of ents.FindByClass("Player"). It's prettier! :)
[QUOTE=Neat-Nit;47086372]Is there a way to get the minimum distance between two entities/physobjects)?[/QUOTE] [url]http://wiki.garrysmod.com/page/Entity/NearestPoint[/url] How do I set the color of an imesh without doing it in the vertex table before building it?
[QUOTE=Neat-Nit;47086605]I don't understand 100% what you're asking. It would help if you explain what you're trying to do. By the way, you can use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/player/GetAll]player.GetAll[/url] instead of ents.FindByClass("Player"). It's prettier! :)[/QUOTE] Maybe if I gave you the rest of the code then it would make sense. [lua]function GM:PlayerConnect(name, ip) for k, ply in pairs(ents.FindByClass("Player")) do if ply:GetName() == name then mathpff = math.random(1,2) if mathpff == 1 then ply:DoSomething() else ply:DoSomethingElse() end end end end[/lua] In the [URL="http://wiki.garrysmod.com/page/GM/PlayerConnect"]PlayerConnect[/URL] parameters, there's no way to refer to the player that just connected other than their IP or steam name. I'm trying to refer to just the player that connected by finding all players and comparing their steam names to the name of the player that just connected.
[QUOTE=SteelSliver;47086666]Maybe if I gave you the rest of the code then it would make sense. [lua]function GM:PlayerConnect(name, ip) for k, ply in pairs(ents.FindByClass("Player")) do if ply:GetName() == name then mathpff = math.random(1,2) if mathpff == 1 then ply:DoSomething() else ply:DoSomethingElse() end end end end[/lua] In the [URL="http://wiki.garrysmod.com/page/GM/PlayerConnect"]PlayerConnect[/URL] parameters, there's no way to refer to the player that just connected other than their IP or steam name. I'm trying to refer to just the player that connected by finding all players and comparing their steam names to the name of the player that just connected.[/QUOTE] You probably want to use [url=http://wiki.garrysmod.com/page/GM/PlayerAuthed]GM:PlayerAuthed[/url] instead. The PlayerConnect hook is called before the player entity is actually created. There's also [url=http://wiki.garrysmod.com/page/GM/PlayerInitialSpawn]GM:PlayerInitialSpawn[/url] which, depending on what your DoSomething() and DoSomethingElse() actually do, might be more appropriate. With that out of the way, I think your original question was more about how lua local variables work in general, and not just specifically here. For that matter, the way you're using ply in this code snippet seems correct. When you use ply inside the for-do-end loop, it only refers to ONE player at a time.
[QUOTE=NiandraLades;47086352]Hey is GetWidth/GetHeight supposed to work on derma panels? I was trying to move an image to another position and while I remembered that MoveTo is a thing I can use instead, it felt odd this gave me nil[/QUOTE] It's weird indeed, it is GetWide and GetTall for panels instead of GetWidth and GetHeight.
[QUOTE=Pandaman09;47082413]The file still doesn't reload properly in a gamemode [img]http://puu.sh/fwpOX/a994d50040.png[/img] Also could you point me in the direction of adding entities to the Entities list?[/QUOTE] Odd, if you're using windows it should detect; if I recall correctly you'd use list.Get( "Entities" ) or something along those lines so you'd need to set up a new table ENT = { }, etc...
[QUOTE=TheLuaNoob;47085418]I'm a bit confused and always have been in this area. What should I use? Draw, Surface, or Derma? Should I use Surface for the HUD and Derma for all menus and VGUI related elements? I've tried using Derma for everything and it seems to work out fine, is this okay?[/QUOTE] Derma is designed for ease of use in making user input UI pieces. You will have a very hard time making a VGUI which accepts user input without using Derma. However, though most developers use the draw/surface functions to paint their HUD, Derma is still a viable option. Just note that at the end of the day, even Derma panels use surface/draw functions to paint themselves. The biggest difference between Derma and surface/draw functions is that Derma assigns all the little elements of your UI to variables which can be retrieved, edited, and persist between frames; while draw/surface hooks just set up the pixels on your screen and move on, no editing, no modification. [editline]6th February 2015[/editline] [QUOTE=Neat-Nit;47086372]Is there a way to get the minimum distance between two entities/physobjects)? Horrible terrible miserable mock-up: [img]http://gyazo.com/2cfb74c4bc47f8870e7611bdc6bbaa16.png[/img] red distance = bad green distance = good In case it matters, one of the entities is actually a player.[/QUOTE] You, my friend, are in luck. I made a function for the portal gun which does this exact thing, and it took me a whole day just to figure it out. Enjoy. [lua] // Returns a point inside an OBB, defined by mins and maxs, which is closest to another point. // If a center is given, it will return a distance within the OBB if the point is within the OBB. // Works in 2 dimensions. Ignores Z of target and center. // Also only works with player OBB's so far. Derp. function util.ClosestPointInOBB(point,mins,maxs,center) -- local yaw = ply:GetRight():Angle().y+90 local Debug = Debug or false local yaw = math.rad(math.YawBetweenPoints(point,center)) local radius local abs_cos_angle= math.abs(math.cos(yaw)); local abs_sin_angle= math.abs(math.sin(yaw)); if (16*abs_sin_angle <= 16*abs_cos_angle) then radius= 16/abs_cos_angle; else radius= 16/abs_sin_angle; end radius = math.min(radius,math.Distance(center.x,center.y,point.x,point.y)) local x,y = math.cos(yaw)*radius, math.sin(yaw)*radius return Vector(x,y,0) + center end //Example: -- local OBBPos = util.ClosestPointInOBB(entPos,ply:OBBMins(),ply:OBBMaxs(),ply:GetPos()) [/lua]
Sorry, you need to Log In to post a reply to this thread.