Time to print money (math.random)?

  • Snip- Fixed.

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.) -

I looked and understand pretty much but this then, explain this…


if math.random(1, 30) == 3 then self:BurstIntoFlames() end

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]
:stuck_out_tongue:

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]

Oh, that was a nice explaination :smiley:
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:



	local job = LocalPlayer().DarkRPVars.job
	Width, Height = surface.GetTextSize(job)


Seems like the job field doesn’t exist.

Could you explain that a little bit better, like how to fix and what made it not make it read…?



if IsValid(LocalPlayer().DarkRPVars.job) then
    local job = LocalPlayer().DarkRPVars.job
else
    local job = ""
end
Width, Height = surface.GetTextSize(job)


You might also be able to



local job = LocalPlayer().DarkRPVars.job
Width, Height = surface.GetTextSize(job or "")


But I don’t know if that works.
That way if job is not valid, then use an “nil” string.

Doesn’t work with the first code…
Getting this error:



[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


well then…



if IsValid(LocalPlayer().DarkRPVars.job) then
    Width, Height = surface.GetTextSize( LocalPlayer().DarkRPVars.job)
else
    Width, Height = 0,0
end



same errors…



[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


[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?

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

DUUUDE!! YOU ARE DA MAN!!
Thank you!! You fixed it!! Omfg thank you so much!

You wouldn’t need job or “” since you already declared job as an empty string.

Oh, didn’t see that… lawl

You need to set the font before getting the TextSize.

No, because it works.