Like on the wiki:
[lua]int2 = math.random(10,100) // will generate an integer between 10 and 100[/lua]
It will work.
- snip (Forgot it isn't math.Rand.) -
[QUOTE=Nak;39492273]Like on the wiki:
[lua]int2 = math.random(10,100) // will generate an integer between 10 and 100[/lua]
It will work.
- snip (Forgot it isn't math.Rand.) -[/QUOTE]
I looked and understand pretty much but this then, explain this..
[code]if math.random(1, 30) == 3 then self:BurstIntoFlames() end[/code]
I want it to go to "BurstIntoFlames" after 30 minutes, but I don't know what that 3 means..?
Human translation begin:
[lua]if math.random(1, 30) == 3 then self:BurstIntoFlames() end
//if a dice with the numbers from 1 to 30 lands on the number 3, then set self on fire, end
[/lua]
:P
If you want it to burst into flames after 30mins .. its not a random function you're looking for .. but a timer.
[lua]
timer.Simple(30*60,function()
self:BurstIntoFlames()
end )
[/lua]
[QUOTE=Nak;39492336]Human translation begin:
[lua]if math.random(1, 30) == 3 then self:BurstIntoFlames() end
//if a dice with the numbers from 1 to 30 lands on the number 3, then set self on fire, end
[/lua]
:P
If you want it to burst into flames after 30mins .. its not a random function you're looking for .. but a timer.
[lua]
timer.Simple(30*60,function()
self:BurstIntoFlames()
end )
[/lua][/QUOTE]
Oh, that was a nice explaination :D
Thank you, and I didn't ever think of setting a simple timer there :3
[editline]6th February 2013[/editline]
Now I have another question, why do I get GetTextSize is nil error in multiplayer but not singleplayer?
The code is:
[code]
local job = LocalPlayer().DarkRPVars.job
Width, Height = surface.GetTextSize(job)
[/code]
Seems like the job field doesn't exist.
[QUOTE=Chessnut;39494021]Seems like the job field doesn't exist.[/QUOTE]
Could you explain that a little bit better, like how to fix and what made it not make it read..?
[QUOTE=addemod;39494708]Could you explain that a little bit better, like how to fix and what made it not make it read..?[/QUOTE]
[code]
if IsValid(LocalPlayer().DarkRPVars.job) then
local job = LocalPlayer().DarkRPVars.job
else
local job = ""
end
Width, Height = surface.GetTextSize(job)
[/code]
You might also be able to
[code]
local job = LocalPlayer().DarkRPVars.job
Width, Height = surface.GetTextSize(job or "")
[/code]
But I don't know if that works.
That way if job is not valid, then use an "nil" string.
[QUOTE=Pandaman09;39495327][code]
if IsValid(LocalPlayer().DarkRPVars.job) then
local job = LocalPlayer().DarkRPVars.job
else
local job = ""
end
Width, Height = surface.GetTextSize(job)
[/code]
You might also be able to
[code]
local job = LocalPlayer().DarkRPVars.job
Width, Height = surface.GetTextSize(job or "")
[/code]
But I don't know if that works.
That way if job is not valid, then use an "nil" string.[/QUOTE]
Doesn't work with the first code..
Getting this error:
[code]
[ERROR] gamemodes/darkrp/gamemode/client/hud.lua:194: bad argument #1 to 'GetTextSize' (string expected, got nil)
1. GetTextSize - [C]:-1
2. DoActualHUD - gamemodes/darkrp/gamemode/client/hud.lua:194
3. DrawHUD - gamemodes/darkrp/gamemode/client/hud.lua:283
4. unknown - gamemodes/darkrp/gamemode/client/hud.lua:398
[/code]
well then...
[code]
if IsValid(LocalPlayer().DarkRPVars.job) then
Width, Height = surface.GetTextSize( LocalPlayer().DarkRPVars.job)
else
Width, Height = 0,0
end
[/code]
[QUOTE=Pandaman09;39495431]well then...
[code]
if IsValid(LocalPlayer().DarkRPVars.job) then
Width, Height = surface.GetTextSize( LocalPlayer().DarkRPVars.job)
else
Width, Height = 0,0
end
[/code][/QUOTE]
same errors..
[code]
[ERROR] lua/includes/modules/draw.lua:86: bad argument #1 to 'GetTextSize' (string expected, got nil)
1. GetTextSize - [C]:-1
2. SimpleText - lua/includes/modules/draw.lua:86
3. DoActualHUD - gamemodes/darkrp/gamemode/client/hud.lua:251
4. DrawHUD - gamemodes/darkrp/gamemode/client/hud.lua:282
5. unknown - gamemodes/darkrp/gamemode/client/hud.lua:397
[/code]
[lua]
local job = ""
if LocalPlayer().DarkRPVars.job ~= nil then
job = LocalPlayer().DarkRPVars.job
end
Width, Height = surface.GetTextSize(job or "")
[/lua]
I don't why it didn't work because it is checking for a valid job in the first place, so that it will not return nil ever. What line is 86?
[QUOTE=Pandaman09;39495740]I don't why it didn't work because it is checking for a valid job in the first place, so that it will not return nil ever. What line is 86?[/QUOTE]
Line 86 is in draw.lua that I didn't edit.
it might be one of these three:
3. DoActualHUD - gamemodes/darkrp/gamemode/client/hud.lua:251
4. DrawHUD - gamemodes/darkrp/gamemode/client/hud.lua:282
5. unknown - gamemodes/darkrp/gamemode/client/hud.lua:397
[QUOTE=Kuro Light;39495733][lua]
local job = ""
if LocalPlayer().DarkRPVars.job ~= nil then
job = LocalPlayer().DarkRPVars.job
end
Width, Height = surface.GetTextSize(job or "")
[/lua][/QUOTE]
DUUUDE!! YOU ARE DA MAN!!
Thank you!! You fixed it!! Omfg thank you so much!
[QUOTE=Kuro Light;39495733][lua]
local job = ""
if LocalPlayer().DarkRPVars.job ~= nil then
job = LocalPlayer().DarkRPVars.job
end
Width, Height = surface.GetTextSize(job or "")
[/lua][/QUOTE]
You wouldn't need job or "" since you already declared job as an empty string.
[QUOTE=Chessnut;39499076]You wouldn't need job or "" since you already declared job as an empty string.[/QUOTE]
Oh, didn't see that.. lawl
You need to set the font before getting the TextSize.
[url]http://wiki.garrysmod.com/page/Libraries/surface/SetFont[/url]
[QUOTE=ms333;39503529]You need to set the font before getting the TextSize.
[url]http://wiki.garrysmod.com/page/Libraries/surface/SetFont[/url][/QUOTE]
No, because it works.
[QUOTE=addemod;39503573]No, because it works.[/QUOTE]
It's already set then. The size depend on the font.
[QUOTE=ms333;39503683]It's already set then. The size depend on the font.[/QUOTE]
I used exactly the code that Kuro Light posted.
I haven't set any font somewhere except where the Job text is, to display the job text.
[QUOTE=addemod;39503770]I used exactly the code that Kuro Light posted.
I haven't set any font somewhere except where the Job text is, to display the job text.[/QUOTE]
Libraries/surface/GetTextSize
Description: Returns the width and height (in pixels) of the given text, [b]but only if the font has been set with surface/SetFont.[/b]
(Source: [url]http://wiki.garrysmod.com/page/Libraries/surface/GetTextSize[/url])
[QUOTE=ms333;39504000]Libraries/surface/GetTextSize
Description: Returns the width and height (in pixels) of the given text, [b]but only if the font has been set with surface/SetFont.[/b]
(Source: [url]http://wiki.garrysmod.com/page/Libraries/surface/GetTextSize[/url])[/QUOTE]
Okey I don't get this but somehow it works and I won't struggle with this anymore. :D
Thanks for all help I got.
The font is probably already set. Setting the font is usually when you need to change what font it uses to get the size.
Sorry, you need to Log In to post a reply to this thread.