Is there a good way to do some last minute lua before the map changes? I use the ShutDown hook but either the hook isn't working or there just isn't enough time because I'm trying to write to a file and nothing happens.
Hey, I've been trying to create a clientside DarkRP module that allows for a player to identify whether or not a drug they are growing is finished by adding a halo to the potted drug when it is done growing.
But I haven't been able to understand why the halo hasn't shown up without giving me a lua error. Here is my code.
[CODE]function GM:PreDrawHalos()
local client = LocalPlayer()
local tr = client:GetEyeTrace().Entity:GetPos():Distance(client:GetPos()) < 101
if LocalPlayer():GetEyeTrace().Entity:GetClass() == "ent_pot" then
local ent = LocalPlayer():GetEyeTrace().Entity
local tab = {}
table.insert( tab, ent )
if tr and ent:GetIsDone() == true then
halo.Add(tab, Color(0, 0, 255), 5, 5, 2, true, false)
end
end
end[/CODE]
If anybody is able to tell me whether or not the error is in the syntax, I would be pretty grateful.
[QUOTE=Crossu88;48905104]Hey, I've been trying to create a clientside DarkRP module that allows for a player to identify whether or not a drug they are growing is finished by adding a halo to the potted drug when it is done growing.
But I haven't been able to understand why the halo hasn't shown up without giving me a lua error. Here is my code.
[CODE]function GM:PreDrawHalos()
local client = LocalPlayer()
local tr = client:GetEyeTrace().Entity:GetPos():Distance(client:GetPos()) < 101
if LocalPlayer():GetEyeTrace().Entity:GetClass() == "ent_pot" then
local ent = LocalPlayer():GetEyeTrace().Entity
local tab = {}
table.insert( tab, ent )
if tr and ent:GetIsDone() == true then
halo.Add(tab, Color(0, 0, 255), 5, 5, 2, true, false)
end
end
end[/CODE]
If anybody is able to tell me whether or not the error is in the syntax, I would be pretty grateful.[/QUOTE]
I think your issue is coming from you trying to override the PreDrawHalos function instead of hooking into it.
Give this a try.
[CODE]
hook.Add("PreDrawHalos", "Drugz_finished", function()
local cl = LocalPlayer()
local ent = cl:GetEyeTrace().Entity
if ent and ent:GetClass() == "ent_pot" and ent:GetPos():Distance(cl:GetPos()) < 101 and ent:GetIsDone() then
halo.Add({ent}, Color(0, 0, 255), 5, 5, 2)
end
end)
[/CODE]
[QUOTE=DeathWard;48905442]I think your issue is coming from you trying to override the PreDrawHalos function instead of hooking into it.
Give this a try.
[CODE]
hook.Add("PreDrawHalos", "Drugz_finished", function()
local cl = LocalPlayer()
local ent = cl:GetEyeTrace().Entity
if ent and ent:GetClass() == "ent_pot" and ent:GetPos():Distance(cl:GetPos()) < 101 and ent:GetIsDone() then
halo.Add({ent}, Color(0, 0, 255), 5, 5, 2)
end
end)
[/CODE][/QUOTE]
While this did immensely shorten the code and taught me how hooks worked, it doesn't seem to work. I've reflected on my previous post and forgot to say that the script works fine until I add this:
[CODE]and ent:GetIsDone() [/CODE]
I don't know why this is though, is it possible that the client isn't able to access the information of an entity?
[editline]14th October 2015[/editline]
Nevermind the code was spot on, I was the one who messed up simply. I forgot to remove some comments and ended up not giving a value for the script
If anyone cares, the answer to my previous question- [QUOTE=MPan1;48899278]I can't figure out how to hide a DScrollPanel (or make it smaller) once it's children get removed[/QUOTE]
Was doing scroll:InvalidateChildren()
HudPaint stuff keeps crashing my game, is this not the right way to use it?
[code]
//HUDon is changed to true when the entity is clicked on, then switched back to false when after 5 seconds
//I know the box and text aren't lined up, right now I just don't want my game to freeze
hook.Add( "HUDPaint", "ShowPhrase", function()
while HUDon == true do
print("Showing Words!")
draw.RoundedBox( 4, 100, 120, 100, 100, Color( 50, 50, 50, 255 ) )
draw.SimpleText( phrase, "DermaLarge", ScrW() * 0.25, ScrH() * 0.55, Color( 0, 0, 0 , 255 ), 0, 4 )
end
end)
[/code]
[QUOTE=Becomeimp;48906066]HudPaint stuff keeps crashing my game, is this not the right way to use it?
[code]
//HUDon is changed to true when the entity is clicked on, then switched back to false when after 5 seconds
//I know the box and text aren't lined up, right now I just don't want my game to freeze
hook.Add( "HUDPaint", "ShowPhrase", function()
while HUDon == true do
print("Showing Words!")
draw.RoundedBox( 4, 100, 120, 100, 100, Color( 50, 50, 50, 255 ) )
draw.SimpleText( phrase, "DermaLarge", ScrW() * 0.25, ScrH() * 0.55, Color( 0, 0, 0 , 255 ), 0, 4 )
end
end)
[/code][/QUOTE]
nooooooooooo don't do that.
HUDPaint is called every frame. Creating a while loop every frame (or really anywhere) will cause manymanymany problems.
Use an if statement instead.
[QUOTE=Z0mb1n3;48906101]nooooooooooo don't do that.
HUDPaint is called every frame. Creating a while loop every frame (or really anywhere) will cause manymanymany problems.
Use an if statement instead.[/QUOTE]
oooo I knew I had to call the draws every frame to work, but I didn't realize the hook accomplished that for me. so I was now doing it twice. Thanks for the help!
i think PlayerHurt doesn't getting called clientside, but wiki says it does. the code below doesn't work.
[CODE]
hook.Add("PlayerHurt", "HitDetect", function(victim, attacker)
addMessage("Received stats!")
addMessage("Stats:")
addMessage("Attacker: " .. attacker:Nick())
addMessage("Victim: " .. victim:Nick())
end)
[/code]
Why would my scoreboard image being blurry? One of my PNG'sI made it worked fine, very high detail. Here is what I have tried:
-Changed Resolution to high amount as a native image.
-Change Size to Image in script - Image's size changes but resolution is super crappy and blurry
-I've tried to match the other images details as much as possible...I'm considering just copying my new image over into that one and making a copy...but I'd like to understand why this is happening.
Ideas?
EDIT : sorry, changed to PNG...
[QUOTE=Blakestr;48907804]Why would my scoreboard image being blurry? One of my PNF's I made it worked fine, very high detail. Here is what I have tried:
-Changed Resolution to high amount as a native image.
-Change Size to Image in script - Image's size changes but resolution is super crappy and blurry
-I've tried to match the other images details as much as possible...I'm considering just copying my new image over into that one and making a copy...but I'd like to understand why this is happening.
Ideas?[/QUOTE]
Never heard of a PNF lol...
Post the original image and a screenshot of how it looks in-game and the code your using to create the image.
[QUOTE=Blakestr;48907804]Why would my scoreboard image being blurry? One of my PNF's I made it worked fine, very high detail. Here is what I have tried:
-Changed Resolution to high amount as a native image.
-Change Size to Image in script - Image's size changes but resolution is super crappy and blurry
-I've tried to match the other images details as much as possible...I'm considering just copying my new image over into that one and making a copy...but I'd like to understand why this is happening.
Ideas?[/QUOTE]
Texture dimensions MUST be power of two ( 1,2,4,8,16,32,64,128,256,512,1024,2048 ), non square textures are allowed ( 64x128, etc )
[QUOTE=jaooe;48907863]Never heard of a PNF lol...
Post the original image and a screenshot of how it looks in-game and the code your using to create the image.[/QUOTE]
[IMG]http://imgur.com/gxgEoZW[/IMG] original [url]http://imgur.com/gxgEoZW[/url]
[IMG]http://imgur.com/r3sG6pZ[/IMG] screenshot of game .... [url]http://imgur.com/r3sG6pZ[/url]
[CODE]GAMEMODE.scoreimage.myimage:SetImage(CBImage) //CBImage created upon VGUI panel creation, updated via buttons
GAMEMODE.scoreimage.myimage:Center()
GAMEMODE.scoreimage.myimage:SetSize( 1024, 512 ) [/CODE]
The panel for the scoreboard is created somewhere else but that just creates the panel versus changing the image...
[QUOTE=Blakestr;48908173]
The panel for the scoreboard is created somewhere else but that just creates the panel versus changing the image...[/QUOTE]
Try using "noclamp smooth" as your png parameters when you define the material.
[CODE]
local CBImage = Material("path/to/file.png", "noclamp smooth")
[/CODE]
I forgot which one it was, but IIRC one of them bypasses the downscaling forced by the games texture setting.
Sorry to butt in, but I have a pretty easy question to do with strings.
I need a function that can split a string every certain amount of characters, like this:
[CODE]
PrintTable( SplitString( "Test string m8", 3 ) ) -- Would split the string every 3 characters
Output:
{ [1] = 'Tes',
[2] = 't s',
[3] = 'tri',
[4] = 'ng ',
[5] = 'm8' }
[/CODE]
But I'm not quite sure how to go about coding it. I tried doing a rather confusing thing involving 3 variables - one being the number that gets reset to 0 before the loop continues - but that didn't work.
Anyone know how to do this?
[code]local tab = {}
for x in string.gmatch( "Test string m8" , "..?.?" ) do
table.insert( tab, x )
end[/code]
[url]http://www.lua.org/pil/20.2.html[/url]
[url]http://www.lua.org/manual/5.1/manual.html#pdf-string.gmatch[/url]
[QUOTE=Willox;48913717]Nice small code[/QUOTE]
Thanks for that really simple example, but I still find it rather confusing (especially with the .? at the end)- how could I get this to work for any number, not just 3?
[highlight]Edit:[/highlight]
This seems to work:
[CODE]
local function SplitString( str, num )
local dots = ''
local tab = {}
for i = 1, num do
dots = dots .. '.'
end
for x in string.gmatch( str, dots .. "?" ) do
table.insert( tab, x )
end
return tab
end
[/CODE]
But is there a shorter way?
[QUOTE=MPan1;48913875]Thanks for that really simple example, but I still find it rather confusing (especially with the .? at the end)- how could I get this to work for any number, not just 3?
[highlight]Edit:[/highlight]
This seems to work:
[CODE]
local function SplitString( str, num )
local dots = ''
local tab = {}
for i = 1, num do
dots = dots .. '.'
end
for x in string.gmatch( str, dots .. "?" ) do
table.insert( tab, x )
end
return tab
end
[/CODE]
But is there a shorter way?[/QUOTE]
[code]local str = "Every three characters, split!"
local sets = {}
for i = 1, string.len(str) do
if i % 3 == 0 then
local newstr = string.sub(str, i-2, i-2)..string.sub(str, i-1, i-1)..string.sub(str, i, i)
table.insert(sets, newstr)
end
end
PrintTable(sets)[/code]
[code]1 = Eve
2 = ry
3 = thr
4 = ee
5 = cha
6 = rac
7 = ter
8 = s,
9 = spl
10 = it!
[/code]
EDIT:
wow i got lucky and that one divided evenly, i did not account for if it has extra characters. let me fix that
EDIT Again:
Just use Willox's way, it's much better, and is much smaller than any "simpler" alternative.
Z0mb1ne, would that example work if you changed the 3 to any other number, or would you have to change the sub amounts as well? Sorry, can't test on iPad
[QUOTE=MPan1;48914087]Z0mb1ne, would that example work if you changed the 3 to any other number, or would you have to change the sub amounts as well? Sorry, can't test on iPad[/QUOTE]
Well yeah but the problem is that it would take more code than I'm really interested in writing for something that string.gmatch already accomplishes to make sure that it does not truncate any leftover characters.
Example, length of your string is 5, you only want every 4 characters, last character is left off.
[editline]16th October 2015[/editline]
If you'd like, here is a smaller function for you using Willox's example.
[code]function string.SplitEvery(str, count)
local tab = {}
for x in string.gmatch(str, string.rep(".", count-1).."?.?" ) do
table.insert( tab, x )
end
return tab
end[/code]
Thanks, that's what I was looking for.
[QUOTE=DeathWard;48908969]Try using "noclamp smooth" as your png parameters when you define the material.
[CODE]
local CBImage = Material("path/to/file.png", "noclamp smooth")
[/CODE]
I forgot which one it was, but IIRC one of them bypasses the downscaling forced by the games texture setting.[/QUOTE]
How would I incorporate this into SetImage function? I keep getting "string expect, got userdata" error..I know it's because I'm trying to set the material to a setimage function but I am not sure how to combine them...
Does anyone know how tall the DFrame's top title box is, or a function to call it?
[IMG]https://i.gyazo.com/2b2cfdc5ad0501a885f3590da5180313.png[/IMG]
[QUOTE=PigeonTroll;48917325]Does anyone know how tall the DFrame's top title box is, or a function to call it?
[IMG]https://i.gyazo.com/2b2cfdc5ad0501a885f3590da5180313.png[/IMG][/QUOTE]
23 ish pixels,
[QUOTE=AIX-Who;48917399]23 ish pixels,[/QUOTE]
What is the simplest way too make a function that detonates all the dynamite at once? Make a function that sends the same key press that the detonate button is set to? I have the general idea but could use some help with the implementation.
[QUOTE=Blakestr;48917417]What is the simplest way too make a function that detonates all the dynamite at once? Make a function that sends the same key press that the detonate button is set to? I have the general idea but could use some help with the implementation.[/QUOTE]
[CODE]
for k,v in pairs( ents.FindByClass("gmod_dynamite") ) do
v:Explode( delay, player )
end
Player does not have to be defined aswell, delay does though.
[/CODE]
[QUOTE=PigeonTroll;48917325]Does anyone know how tall the DFrame's top title box is, or a function to call it?
[IMG]https://i.gyazo.com/2b2cfdc5ad0501a885f3590da5180313.png[/IMG][/QUOTE]
Depends on what you count.
[img]http://i.imgur.com/AUkJXIH.png[/img]
[QUOTE=Robotboy655;48917803]Depends on what you count.
[img]http://i.imgur.com/AUkJXIH.png[/img][/QUOTE]
Thank you, I got what I needed!
Also, is there a way you can remove DButtons, or at least make it so the cursor won't be a hand when hovered? Remove() didn't work for me.
EDIT: use SetCursor()
EDIT EDIT: nvm I'm dumb
[QUOTE=PigeonTroll;48918510]Thank you, I got what I needed!
Also, is there a way you can remove DButtons, or at least make it so the cursor won't be a hand when hovered? Remove() didn't work for me.[/QUOTE]
Panel:Remove() is exactly how you do it, where Panel is the button you want to remove.
For cursor, see [url]http://wiki.garrysmod.com/page/Panel/SetCursor[/url]
[code]
if IsValid(self.btnMaxim) then self.btnMaxim:Remove() end
if IsValid(self.btnMinim) then self.btnMinim:Remove() end
[/code]
gives me this
[code]
[ERROR] lua/vgui/dframe.lua:259: Tried to use invalid object (type Panel) (Object was NULL or not of the right type)
1. SetPos - [C]:-1
2. unknown - lua/vgui/dframe.lua:259
[ERROR] lua/vgui/dframe.lua:259: Tried to use invalid object (type Panel) (Object was NULL or not of the right type)
1. SetPos - [C]:-1
2. unknown - lua/vgui/dframe.lua:259
[/code]
Sorry, you need to Log In to post a reply to this thread.