[QUOTE=Brassx;51839807]
It wouldn't be too hard to adapt it to include sub directories. Feel free to use it or modify it if you want![/QUOTE]
Thank you! I will give it a shot. Hopefully this solves my headache.
[QUOTE=Sweepyoface;51840618]
-Sweepy's post
[/QUOTE]
Are you calling it on the client or server? The way you wrote it is being called on the client, but you're trying to interact with server variables. If I'm not mistaken, you're trying to manipulate a light (server?) and music but you're doing it from the client's perspective (LocalPlayer())
I'm still semi-new to Lua so I may not be helping what-so-ever but that's what I get from it.
[QUOTE=Sweepyoface;51840618]I'm kinda confused as to how variables work, I have a think hook to set the pos of a DynamicLight that I've attached to a vehicle but I obviously don't want to be getting the vehicle entity every tick in case the player gets out, so I have:
[CODE]
partybus_vehicle = LocalPlayer():GetVehicle()
hook.Add("Think", "partybus_think", function()
if partybus_on then
partybus_dlight = DynamicLight(partybus_vehicle:EntIndex())
partybus_pos = partybus_vehicle:GetPos()
partybus_dlight.pos = Vector(partybus_pos.x, partybus_pos.y, partybus_pos.z)
print("set pos!")
partybus_dlight.brightness = 200
partybus_dlight.decay = 100
partybus_dlight.size = 512
partybus_dlight.DieTime = CurTime() + 1
end
if IsValid(partybus_audiochannel) then
partybus_audiochannel:SetPos(partybus_vehicle:GetPos())
partybus_audiochannel:Set3DFadeDistance(1000, 5000)
end
end)
[/CODE]
but this results in an error saying partybus_vehicle is null, I thought it should be accessible within other functions because it's not local? Can anyone think of a better way to do this?
All of this is in a net.Receive() called when the player gets in the party bus.[/QUOTE]
NULL ~= nil
If the error says it's NULL, it's because GetVehicle returned a NULL entity. Depending on when you're sending the net message, it's possible the client doesn't know about it being inside the vehicle yet. I'd suggest just defining the variable inside the think function, and checking if it's valid.
Also, please use local variables where they're applicable.
It's been a while.. I'm reviving an old project and trying to update some old code to work again, but the way timers work seems to have changed. For example in a projectile I have a timer which calls self.Explode, but self is now out of scope when the timer runs. Passing self along as another argument appears to have worked before, how can I pass self along now?
[QUOTE=Catdaemon;51841181]It's been a while.. I'm reviving an old project and trying to update some old code to work again, but the way timers work seems to have changed. For example in a projectile I have a timer which calls self.Explode, but self is now out of scope when the timer runs. Passing self along as another argument appears to have worked before, how can I pass self along now?[/QUOTE]
Timers no longer pass extra arguments to the function. Also, the reason it doesn't work isn't because self is out of scope, it's because it's attempting to call the function without the self argument.
[code]
self:Explode()
-- translates to
self.Explode(self)
[/code]
The timer just calls the function you pass with no arguments, so it'd be like calling the below.
[code]
self.Explode()
[/code]
To fix this use just pass an anonymous function, e.g.
[code]
timer.Simple(delay, function()
if not IsValid(self) then return end
self:Explode()
end)
[/code]
self is still in the scope of that function, so all you want to do is check to make sure the entity is still valid.
[QUOTE=bigdogmat;51841203]Timers no longer pass extra arguments to the function. Also, the reason it doesn't work isn't because self is out of scope, it's because it's attempting to call the function without the self argument.
[code]
self:Explode()
-- translates to
self.Explode(self)
[/code]
The timer just calls the function you pass with no arguments, so it'd be like calling the below.
[code]
self.Explode()
[/code]
To fix this use just pass an anonymous function, e.g.
[code]
timer.Simple(delay, function()
if not IsValid(self) then return end
self:Explode()
end)
[/code]
self is still in the scope of that function, so all you want to do is check to make sure the entity is still valid.[/QUOTE]
Cheers! Doing it in an anonymous function makes sense, I'll do that.
[QUOTE=bigdogmat;51841074]NULL ~= nil
If the error says it's NULL, it's because GetVehicle returned a NULL entity. Depending on when you're sending the net message, it's possible the client doesn't know about it being inside the vehicle yet. I'd suggest just defining the variable inside the think function, and checking if it's valid.
Also, please use local variables where they're applicable.[/QUOTE]
Well, it's weird because I defined the variable at the beginning of the net receive and then print it's vehicle class name - works fine. Later on in the function however it's not valid. I can't really define it in think because I need the vehicle weather the player is in it or not so move the lights and audio positions.
[QUOTE=Sweepyoface;51841311]Well, it's weird because I defined the variable at the beginning of the net receive and then print it's vehicle class name - works fine. Later on in the function however it's not valid. I can't really define it in think because I need the vehicle weather the player is in it or not so move the lights and audio positions.[/QUOTE]
That's because you're doing it outside of the hook -- the vehicle can change or go invalid. Do it inside of the hook and check its validity every time
I made a script to get a list of all [url=https://developer.valvesoftware.com/wiki/Env_projectedtexture]env_projectedtexture[/url] entities (spotlights) and get the "lightfov" and "farz" key-variables send to clients (Since [url=http://wiki.garrysmod.com/page/Entity/GetKeyValues]ENTITY:GetKeyValues()[/url] is serverside only).
However; I need to update the variables when the keys change and the hook [url=http://wiki.garrysmod.com/page/GM/EntityKeyValue]GM:EntityKeyValue(ent,key,var)[/url] seems not to work on non-scripted entities.
My only solution seems to override [url=http://wiki.garrysmod.com/page/Entity/Fire]ent.Fire[/url], [url=http://wiki.garrysmod.com/page/Entity/Input]ent.Input[/url] and [url=http://wiki.garrysmod.com/page/Entity/SetKeyValue]ent.SetKeyValue[/url] and call the [url=http://wiki.garrysmod.com/page/GM/EntityKeyValue]GM:EntityKeyValue(ent,key,var)[/url] hook.
[code]local meta = FindMetaTable("Entity")
if SERVER then
_sf_fix_fire = _sf_fix_fire or meta.Fire
_sf_fix_input = _sf_fix_input or meta.Input
end
_sf_fix_SetKeyValue = _sf_fix_SetKeyValue or meta.SetKeyValue
if SERVER then
function meta:Fire(...)
local a = {...}
local al = hook.Call("EntityKeyValue",nil,self,a[1],a[2])
if al then
a[2] = al or a[2]
end
_sf_fix_fire(self,a[1],a[2],a[3])
end
function meta:Input(...)
local a = {...} -- str, activator, inflictor, parms
local al = hook.Call("EntityKeyValue",nil,self,a[1],a[4])
if al then
a[4] = al or a[4]
end
_sf_fix_input(self,a[1],a[2],a[3],a[4])
end
end
function meta:SetKeyValue(...)
local a = {...}
local al = hook.Call("EntityKeyValue",nil,self,a[1],a[2])
if al then
a[2] = al or a[2]
end
_sf_fix_SetKeyValue(self,a[1],a[2])
end[/code]
I hate overriding stuff, so do anyone know another solution?
Is there a way to have a variable go from 1 to X amount and back?
I want to make an entity go from red to blue and blue to red but not
jumping from each colors to another, but rather fade from red to blue, etc.
[QUOTE=MGFear;51841866]Is there a way to have a variable go from 1 to X amount and back?
I want to make an entity go from red to blue and blue to red but not
jumping from each colors to another, but rather fade from red to blue, etc.[/QUOTE]
[CODE]
local amount = 1 -- change this to any number
local col = Color( 255, 0, 0 )
-- repeat this every time you want the color to change:
col.b = col.b + amount
col.r = col.r - amount
-- reverse it to go from blue to red
[/CODE]
?
How can I fix sprites rendering incorrectly through a RT? Specifically, when looking through a RT Scope, sprites/overlays and even the spawn effect will show through the viewmodel in the wrong place.
nvm solved
-snip-
sv_allowdownloads 1
I'm an idiot.
Is there a way to stop further executing of Lua code? (or stop the game mode). For example when database connection fails?
[QUOTE=Sapd;51844835]Is there a way to stop further executing of Lua code? (or stop the game mode). For example when database connection fails?[/QUOTE]
No, and it sounds like the wrong approach. Instead ask yourself: what SHOULD happen when you're disconnected from the database?
If you decide that the game cannot continue, then just [url=http://wiki.garrysmod.com/page/Player/Kick]kick[/url] all players and [url=http://wiki.garrysmod.com/page/GM/CheckPassword]don't allow[/url] new players to connect until the database connection is regained.
[QUOTE=Sapd;51844835]Is there a way to stop further executing of Lua code? (or stop the game mode). For example when database connection fails?[/QUOTE]
[url]http://xyproblem.info/[/url]
[QUOTE=LegoGuy;51845064][url]http://xyproblem.info/[/url][/QUOTE]
To be fair, I don't consider it to be that because he did actually provide the background info and actual problem, and even says "or [other ways to] stop the gamemode". I definitely prefer it when they ask for help with an attempted bad solution too, because then we can tell them why that approach is wrong/not optimal.
Also I didn't meant the case were the database connection is lost, but when it doesn't even connect when the server trys to start. Normally applications handle it in the way that they don't allow to start in this case.
That's definitely not an xyproblem.
[QUOTE=NeatNit;51845112]To be fair, I don't consider it to be that because he did actually provide the background info and actual problem, and even says "or [other ways to] stop the gamemode". I definitely prefer it when they ask for help with an attempted bad solution too, because then we can tell them why that approach is wrong/not optimal.[/QUOTE]
Fair enough. At least he did give the actual problem as well.
I personally think that preventing people from connecting is a bad idea. Instead have a notification saying "failure to load" and periodically retry or have a console command to attempt reconnecting. Then do what has to be done on all the players on the server.
[QUOTE=LegoGuy;51845148]Fair enough. At least he did give the actual problem as well.
I personally think that preventing people from connecting is a bad idea. Instead have a notification saying "failure to load" and periodically retry or have a console command to attempt reconnecting. Then do what has to be done on all the players on the server.[/QUOTE]
There's probably a lot of hooks doing all sorts of stuff that he just doesn't want them to do while the game is, presumably, unplayable because the database is lost. I'm not saying that "kick all, accept no one" is a good solution, but it's a quick and easy one that at least keeps stuff from breaking horrendously.
Admittedly, a better approach would be to allow the game to continue when when the database is unavailable, but depending on the gamemode this may not be possible.
[editline]19th February 2017[/editline]
[QUOTE=Sapd;51845132]Also I didn't meant the case were the database connection is lost, but when it doesn't even connect when the server trys to start. Normally applications handle it in the way that they don't allow to start in this case.[/QUOTE]
Do you mean something like: "if the server just started and it can't connect to the database then close server"?
[QUOTE=NeatNit;51845176]
Do you mean something like: "if the server just started and it can't connect to the database then close server"?[/QUOTE]
Yes. I thought that would be a good way, because when it can't connect at this point, then it's likely the user misconfigured something. Also the message "Can't connect to database" can't be seen so easily, because other boot messages will get posted afterwards.
It is not a big problem, but I thought there might be an easy solution. Also I want to emphasise that I am not a newbie in gmod lua or programming overall, as you all seem to think that about people who post in this thread. Also I don't understand why people try to rate my method and why I shouldn't do it that way. I already made my thoughts, so I simply asked the question wether stopping a gamemode/server/lua execution is possible. Stopping to rate people's approach would also made the link to xyproblem.info redundant (Except if I would have asked: "Is my approach advisable").
I guess there is no way without a module which handles this case.
[QUOTE=Sapd;51845438]:snip:[/QUOTE]
FWIW my suggested solution still holds. Display your error message of choice in CheckPassword.
You can't directly say "don't run any more code", but you can prevent it from running by having no players on your server ;)
(with 0 players, Tick/Think never runs and with it go most hooks)
[QUOTE=NeatNit;51845611]You can't directly say "don't run any more code"[/QUOTE]
[lua]while true do end[/lua]
I'm trying to write a simple script to play an mp3 file during the warmup phase of TTT. This is the code I came up with but it doesn't work. It also isn't spitting out any console errors. Any help would be appreciated.
[CODE]--TTT Pre-Round Music
resource.AddFile("sound/ode.mp3")
hook.Add("TTTPrepareRound", "Prep", Prepmusic)
local Prepmusic = function()
if TTTPrepareRound then
BroadcastLua('surface.PlaySound("ode.mp3")')
else
print ("The Round Proper Has Begun")
end
Prepmusic()
end
[/CODE]
You shouldn't be broadcasting Lua like that. What you should be doing is using the Net library to send a message to people's clients to play sounds.
[url]https://wiki.garrysmod.com/page/Net_Library_Usage[/url]
Is anyone able to get Webdings to work as a font? I've been trying forever and cannot get it to work. I've even tried resource.AddFile'ing it. It just keeps defaulting to Wingdings...
What's the cleanest was to write a bunch of the to the screen? I have a [URL="https://wiki.garrysmod.com/page/Category:RichText"]RichText[/URL] vgui element and I'm trying to write about a paragraph of stuff to it. This is for an about me screen for a game mode.
[QUOTE=RenTec;51847752]What's the cleanest was to write a bunch of the to the screen? I have a [URL="https://wiki.garrysmod.com/page/Category:RichText"]RichText[/URL] vgui element and I'm trying to write about a paragraph of stuff to it. This is for an about me screen for a game mode.[/QUOTE]
[url]https://wiki.garrysmod.com/page/Category:DLabel[/url] is more commonly used. You can also use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/surface/DrawText]surface.DrawText[/url] if you're not looking for vgui elements - that is the basis for most text drawing, including all text drawing in the draw library
[QUOTE=MPan1;51847761][url]https://wiki.garrysmod.com/page/Category:DLabel[/url] is more commonly used.[/QUOTE]
I'm trying to make the 'code' look nicer, everything is fine in game but I don't want just one line of code to stretch a page and a half to the right of my screen.
[QUOTE=RenTec;51847752]What's the cleanest was to write a bunch of the to the screen? I have a [URL="https://wiki.garrysmod.com/page/Category:RichText"]RichText[/URL] vgui element and I'm trying to write about a paragraph of stuff to it. This is for an about me screen for a game mode.[/QUOTE]
RichText should work fine.
Like others said you can also use a simple DLabel with SetWrap enabled like so:
[img]https://i.gyazo.com/b2ac479b0b0578a23f17009a70e410a5.png[/img]
[code]
local Panel = vgui.Create( "DFrame" )
Panel:SetSize( 800, 600 )
local dLabel = vgui.Create( "DLabel", Panel )
dLabel:SetPos( 40, 40 )
dLabel:DockMargin(10, 10, 10, 10);
dLabel:Dock(FILL);
dLabel:SetFont("Trebuchet18");
dLabel:SetWrap(true);
dLabel:SetAutoStretchVertical(true);
dLabel:SetText( [[long random paragraph from google here]] )
[/code]
You can also use a DHTML panel to help format your about page better, you could even just input a webpage into it. But you can just enter your own HTML code for nice and easy text formatting, and this allows for nice text selection for copy+pasting. However, I'm not sure on how to get rid of the ugly 'black anti-aliasing' issue I've ran into before.
Example:
[img]https://i.gyazo.com/f5c93100d3eab619b8df46b4a7a9c932.png[/img]
[code]
local Panel = vgui.Create( "DFrame" )
Panel:SetSize( 800, 600 )
local html = vgui.Create( "DHTML" , Panel )
html:Dock( FILL )
function html:Paint(w, h)
surface.SetDrawColor(Color(0, 0, 0, 128));
surface.DrawRect(0, 0, w, h);
end
html:SetHTML( [[
<style>
p {
color: rgb(255,255,255)
}
li {
color: rgb(255,255,255)
}
</style>
<p style="text-shadow: 0 0 8px #00ffff;">Hello there world!</p>
<OL>
<LI>This is a nicely ordered list.
<LI>Yea
<LI>Cool beans
</UL>
]] )
Panel:Center();
Panel:MakePopup();
[/code]
[url]http://wiki.garrysmod.com/page/Category:DHTML[/url]
EDIT: Coming back to it, I figured out the issue with the ugly font. Just set a background color for body and it r
[code]
body {
background-color: rgb(12,12,12)
}
[/code]
Sorry, you need to Log In to post a reply to this thread.