• Problems That Don't Need Their Own Thread v3.0
    5,003 replies, posted
[QUOTE=MPan1;49573071]If I use 0 and ScrW() and math.Approach works how I think it does, won't it just do nothing unless it reaches 0 or ScrW()? What's the point of it? I want the movement to be smooth, not just do some odd thing once it reaches 0 or ScrW()...[/QUOTE] math.Approach, according to the wiki page, "Increments a value from a start point by the given amount, up to a given upper limit." Using Zombine's example, it would increment by RealFrameTime()*8 each time it was called. I think math.Approach is a bit useless because it's really just an if statement. I gave you a code snippet a while ago while you were trying to have a bar's width increase at a set rate regardless of framerate. That code can be used again here. [CODE] local value = 0 local width = ScrW() value = math.min( width, value + ( width * RealFrameTime() / seconds ) ) if value == width then --do stuff end [/CODE] Just set seconds to the number of seconds you want it to take to traverse the screen and use value for the draw call. In the if statement you can remove the object or whatever to stop it drawing when it's no longer on the screen.
I have a vgui question now: How would I get a child of a DFrame to firstly un-dock from it's parent (if necessary), then go fullscreen? Or, should I try to get the parent of the child element to go fullscreen? I don't really know what to do. All I want to do is get a DFrame to appear like it's going fullscreen with a DButton docked into it [editline]21st January 2016[/editline] EDIT: I think I figured it out. I needed to set the DFrame's docking to 0, 0, 0 and invalidate some stuff
Not too much of a problem, but I'm trying to allow players to see all around them when in thirdperson (freelook) but I can't seem to figure out how to allow all of the angles. I've attempted editing the view.angles to pretty much everything I could think of. (Angles, Player's Angles, Math applied to players angles, etc) [code] local View = { } View.origin = Trace.HitPos + Player:GetForward() * 8 View.angles = Player:GetAngles() View.fov = Fov return View [/code] Really small and simple I know, maybe I'm just too stupid.
So...roastchicken, with the code snippet you gave me: [QUOTE=roastchicken;49573236][CODE]value = math.min( width, value + ( width * RealFrameTime() / seconds ) )[/CODE][/QUOTE] What am I supposed to do if the speed is 0? Everything just flies off screen if I try to use your example. Also, since I want the number to get smaller rather than bigger (the stuff is all being created at ScrW()), I did this instead: [CODE] value = math.min( width, value - ( width * RealFrameTime() / seconds ) ) [/CODE] So that's probably why it's screwing up. Could you help me?
Okay, I have another question- is there a way in Lua to change a variable in a literal way with a function like so: [CODE] local var local function changevar( variable ) variable = 'test' end changevar( var ) print( var ) --> nil -- how could I get it to print 'test' ? [/CODE] Except get the code above to somehow make the variable actually get changed? No idea how this could be done, probably with some dodgy table indexing or something
[QUOTE=MPan1;49576108]Except get the code above to somehow make the variable actually get changed? No idea how this could be done, probably with some dodgy table indexing or something[/QUOTE] [CODE] local var local function changevar( variable ) var = variable end changevar( var ) print( var ) --> nil -- how could I get it to print 'test' ? [/CODE] ?? [B]edit[/B] oh i guess you mean change the variable in the arg.. i'd use tables instead
[QUOTE=MPan1;49576108]Okay, I have another question- is there a way in Lua to change a variable in a literal way with a function like so: [CODE] local var local function changevar( variable ) variable = 'test' end changevar( var ) print( var ) --> nil -- how could I get it to print 'test' ? [/CODE] Except get the code above to somehow make the variable actually get changed? No idea how this could be done, probably with some dodgy table indexing or something[/QUOTE] You should really not have code that works like this in Lua. If you really need to, you could fight with debug.setupvalue.
As said before, just use tables. There's nothing dodgy about them. I guarantee that whatever you're doing doesn't need to do what you're trying to do now.
I meant table indexing as in table indexing the _G table (containing all global variables as far as I know) or whatever the equivalent is for local variables I should be using tables but I was just trying to condense a bit of code that sets a variable based on whether or not a DCheckBox is ticked. It was only a little bit of code anyway so it doesn't really matter
Is there a way to make sure, if you're using AnimRestartGesture, that the ACT you use will always be the same for the client and the server? Because right now they're desynced, as the ACT has I think 7 different variations (ACT_GMOD_GESTURE_RANGE_ZOMBIE). I want it to use the same variation for both client and server, per call. I have a pretty limited knowledge of the animation functions so I might be missing something obvious here.
[QUOTE=Unib5;49576873]Is there a way to make sure, if you're using AnimRestartGesture, that the ACT you use will always be the same for the client and the server? Because right now they're desynced, as the ACT has I think 7 different variations (ACT_GMOD_GESTURE_RANGE_ZOMBIE). I want it to use the same variation for both client and server, per call. I have a pretty limited knowledge of the animation functions so I might be missing something obvious here.[/QUOTE] That's how ACTs work, one ACT may have multiple sequences assigned to it: [url]https://github.com/robotboy655/gmod-animations/blob/master/gm_sequences_zombie.qci#L133-L139[/url] If you wish for them to be synched, you gotta play sequences.
[QUOTE=MPan1;49575712]So...roastchicken, with the code snippet you gave me: What am I supposed to do if the speed is 0? Everything just flies off screen if I try to use your example. Also, since I want the number to get smaller rather than bigger (the stuff is all being created at ScrW()), I did this instead: [CODE] value = math.min( width, value - ( width * RealFrameTime() / seconds ) ) [/CODE] So that's probably why it's screwing up. Could you help me?[/QUOTE] What do you mean "speed"? I had also made one where the value decreased, but I didn't post it. I'll see if I can figure it out again.
How do I put a particle in front of a player?
I'm feeling stupid. Script is in GM:PlayerInitialSpawn and should remove all the shitty props around the map. No error just not working. [CODE] if !FIRSTJOINED then FIRSTJOINED = true timer.Simple(5,function() for k, v in pairs( ents.FindByClass("prop_physics")) do v:Remove() end end) end [/CODE] Thanks in advance.
how would I make a map show a users current STEAMname on item use with lua_run like they consume an item, I kill the item with hammers i/o system they get hp or something but it also messages the entire server like "STEAMNAME used the health item" possible?
[QUOTE=Strideynet;49579174]I'm feeling stupid. Script is in GM:PlayerInitialSpawn and should remove all the shitty props around the map. No error just not working. [CODE] if !FIRSTJOINED then FIRSTJOINED = true timer.Simple(5,function() for k, v in pairs( ents.FindByClass("prop_physics")) do v:Remove() end end) end [/CODE] Thanks in advance.[/QUOTE] You should put this in InitPostEntity and use ent:CreatedByMap() in your loop. Also make sure you are using hook.Add to make your hook.
[QUOTE=roastchicken;49577752]What do you mean "speed"?[/QUOTE] Oh, sorry, by speed I just meant the amount of seconds it takes for the stuff to reach the edge of the screen. Thanks for trying to help me, by the way! [editline]21st January 2016[/editline] [QUOTE=Rocketsurgery;49579643]how would I make a map show a users current STEAMname on item use with lua_run like they consume an item, I kill the item with hammers i/o system they get hp or something but it also messages the entire server like "STEAMNAME used the health item" possible?[/QUOTE] Well, probably don't use lua_run for it, just put the code in a .lua file in the garrysmod/lua/autorun folder (if the server you're on had lua_run enabled just so you could manually run one thing then anyone could type any command and screw up the whole server). Anyway, this would probably work: [CODE] --SERVERSIDE STUFF AddCSLuaFile( 'lua/whatever_folder/whatever_the_name_of_your_clientside_code_file_would_be.lua' ) -- the clientside file of this needs to be sent to the client, that's what AddCSLuaFile does util.AddNetworkString( 'SendChatToPlayers' ) -- since gmod doesn't allow server-wide chat we have to use the net library :( hook.Add( 'PlayerUse', 'UNIQUE_NAME', function( ply, ent ) -- make sure to change UNIQUE_NAME to a unique name so this hook doesn't get overwritten by some other addon if ent:GetModel() == 'whatever model it is' then -- you could do something different to this but this is just an example ply:SetHealth( ply:Health() + 10 ) -- add 10 hp for example ent:Remove() -- you don't need to use hammer for this :P net.Start( 'SendChatToPlayers' ) -- start the thing that makes the chat say whatever player ate it net.WriteEntity( ply ) -- send the player who ate it net.Broadcast() -- send it to all players on the server so it shows all of them who ate it end end ) -- CLIENTSIDE STUFF (note you need to do AddCSLuaFile on whatever .lua file this code will be in, as I did an example of in the serverside code above) net.Receive( 'SendChatToPlayers', function() local ply = net.ReadEntity() -- read the player entity we sent chat.AddText( Color( 100, 100, 255 ), ply, " used the health item!" ) -- that prints the text you wanted end ) [/CODE] [editline]22nd January 2016[/editline] Also, I have a question- I'm working on a really simple swear remover just for fun, and I have a long list of swear words to remove, which my code just finds in the chat string a player says and string-subs them out. But, my question is this: Say a player says something like [CODE] sh-it [/CODE] Or uses some kind of other character to make a gap between what would be a swear word so it gets undetected. How would I somehow remove the - character, and then check if it's a swear word, and if so, replace it with some other letter like *? I really have no idea how that could be done... Here's my code for replacing the letters (it's pretty messy though): [CODE] hook.Add( 'PlayerSay', 'RemoveSwears', function( sender, text, bTeamChat ) local Violators = {} text = string.Replace( text, '-', '' ) -- current i'm just subbing out the character, but then if a player says something like hot-dog it would turn into hotdog, which I don't want to happen for word in pairs( Swears ) do -- Swears is the name of the table with all the swears in it local s, e = string.find( string.lower( text ), word ) if s ~= nil then Violators[ #Violators+1 ] = { start = s, finish = e } end end for _, PosTab in ipairs( Violators ) do text = string.sub( text, 0, PosTab.start - 1 ) .. string.rep( '*', PosTab.finish + 1 - PosTab.start ) .. string.sub( text, PosTab.finish + 1, #text ) end return text end ) [/CODE]
[QUOTE=MPan1;49580042]Oh, sorry, by speed I just meant the amount of seconds it takes for the stuff to reach the edge of the screen. Thanks for trying to help me, by the way![/QUOTE] I want to kick myself right now for not posting/saving the code for the constant rate of decreasing. I swear I had an equally elegant solution that just required swapping out an operator and maybe switching min to max, but now I can't seem to think of it. This is the best I could do: [CODE]local value = ScrW() local width = 0 local difference = math.abs( value - width ) value = math.max( width, value + ( difference * RealFrameTime() / seconds ) ) if value == width then --do stuff end[/CODE] [editline]22nd January 2016[/editline] I'm stupid [CODE] local value = ScrW() local width = ScrW() value = math.max( 0, value - (width * RealFrameTime() / seconds ) ) if value == width then --do stuff end [/CODE]
[QUOTE=MPan1;49580042] Well, probably don't use lua_run for it, just put the code in a .lua file in the garrysmod/lua/autorun folder (if the server you're on had lua_run enabled just so you could manually run one thing then anyone could type any command and screw up the whole server). Anyway, this would probably work: [CODE] --SERVERSIDE STUFF AddCSLuaFile( 'lua/whatever_folder/whatever_the_name_of_your_clientside_code_file_would_be.lua' ) -- the clientside file of this needs to be sent to the client, that's what AddCSLuaFile does util.AddNetworkString( 'SendChatToPlayers' ) -- since gmod doesn't allow server-wide chat we have to use the net library :( hook.Add( 'PlayerUse', 'UNIQUE_NAME', function( ply, ent ) -- make sure to change UNIQUE_NAME to a unique name so this hook doesn't get overwritten by some other addon if ent:GetModel() == 'whatever model it is' then -- you could do something different to this but this is just an example ply:SetHealth( ply:Health() + 10 ) -- add 10 hp for example ent:Remove() -- you don't need to use hammer for this :P net.Start( 'SendChatToPlayers' ) -- start the thing that makes the chat say whatever player ate it net.WriteEntity( ply ) -- send the player who ate it net.Broadcast() -- send it to all players on the server so it shows all of them who ate it end end ) -- CLIENTSIDE STUFF (note you need to do AddCSLuaFile on whatever .lua file this code will be in, as I did an example of in the serverside code above) net.Receive( 'SendChatToPlayers', function() local ply = net.ReadEntity() -- read the player entity we sent chat.AddText( Color( 100, 100, 255 ), ply, " used the health item!" ) -- that prints the text you wanted end ) [/CODE] [/QUOTE] I appreciate the code id rather have in included in the map with lua_run so no extra files are needed I just need the chat stuff really, I can do the damage stuff in hammer easily with trigger_hurt
I'm sure it was more elegant than that but I'm going to stop beating myself up for it. Hope it solved your problem. [editline]22nd January 2016[/editline] rip merge
[QUOTE=Rocketsurgery;49580567]I appreciate the code id rather have in included in the map with lua_run so no extra files are needed I just need the chat stuff really, I can do the damage stuff in hammer easily with trigger_hurt[/QUOTE] Can you do lua_run_cl in hammer? If so, just run the clientside bit with that and the serverside bit with lua_run and it would probably work. Take away that health adding thing though and the entity:Remove bit if you don't want to use them, then just remove all the paragraphs by replacing them with spaces and try running the code and see what happens
I guess my original code wasn't as modular as I thought [CODE] local start = 0 --starting value local stop = 100 --ending value local seconds = 1 --number of seconds you want it to take local diff = stop - start local value = start if value ~= stop then value = value + ( diff * RealFrameTime() / seconds ) else --do stuff end [/CODE] I can now sleep easy
[QUOTE=MPan1;49580597]Can you do lua_run_cl in hammer? If so, just run the clientside bit with that and the serverside bit with lua_run and it would probably work. Take away that health adding thing though and the entity:Remove bit if you don't want to use them, then just remove all the paragraphs by replacing them with spaces and try running the code and see what happens[/QUOTE] dont think so i googled and I will try grabbing the lua file remotely method [url]https://facepunch.com/showthread.php?t=1389222[/url]
[QUOTE=Rocketsurgery;49580846]dont think so i googled and I will try grabbing the lua file remotely method [url]https://facepunch.com/showthread.php?t=1389222[/url][/QUOTE] Well, good luck. The reason you need a clientside file by the way is because you can only print text in chat on the client's side, so unless Hammer has some way to print text to all players without using any clientside files, I guess you'll have to try whatever you're trying now. It would be a hell of a lot easier if you just let the clientside .lua file be a separate thing from the map, though :P [editline]22nd January 2016[/editline] How can I add 'dummy' DPanels to a DListLayout? I'm trying to make a leaderboard (which I've never done before, by the way) and since I'm testing it only with a couple of players, so there's lots of empty space on it and it looks bad. I want to fill the empty space with some DPanels or something so it looks like they're spots to be taken, like how the DListView adds all those blue and white stripes even when there's nothing in them. How could I do this in a way that will make sure all the possible space will be filled?
[QUOTE=Rocketsurgery;49579643]how would I make a map show a users current STEAMname on item use with lua_run like they consume an item, I kill the item with hammers i/o system they get hp or something but it also messages the entire server like "STEAMNAME used the health item" possible?[/QUOTE] [code]PrintMessage( HUD_PRINTTALK, string.format( "%s used the %s item.", ACTIVATOR:Nick( ), "health" ) )[/code] lua_run creates two variables - ACTIVATOR and CALLER. Experiment with it, but something like that should work.
Could someone give me some pointers on how I can check if the server has crashed server side only? Thanks in advance.
[QUOTE=Leyserr;49585459]Could someone give me some pointers on how I can check if the server has crashed server side only? Thanks in advance.[/QUOTE] If your code doesn't run.
[QUOTE=Kogitsune;49584505][code]PrintMessage( HUD_PRINTTALK, string.format( "%s used the %s item.", ACTIVATOR:Nick( ), "health" ) )[/code] lua_run creates two variables - ACTIVATOR and CALLER. Experiment with it, but something like that should work.[/QUOTE] thank you I had to change quotes to apostrophes but I tested it in multiplayer and it worked.
can I paint the lines in DNumSlider somehow`??
:snip: Figured it out [B]EDIT:[/B] Nope, I didn't This is probably a really simple maths question, but: If I had a screen width of [B]1920[/B], then I want a variable to be set as [B]100[/B]. If I had a screen width of [B]1176[/B], then I want a variable to be set as [B]84[/B]. Or as close to the second number as possible. What equation am I meant to do to the first number to get it as close as possible to the second one? Also, I want the equation to be the same for both numbers so it works for all screen resolutions. How could I do this? [B]EDIT:[/B] Nevermind, I'll just use different numbers
Sorry, you need to Log In to post a reply to this thread.