[code]
aTable={
"Mister Havershum",
"Steven Tabernacle",
"Nicholas Halden",
"Mozzy",
"Neal Caffery",
"Jimmy Burger",
"Dexter Morgan"
}
activator:setRPName(table.Random(aTable) )
[/code]
So I have this to choose a random darkrp name out of the table, it dosen't work, though this works singlified:
[code]activator:setRPName( "name" )[/code]
Store the RP names in a file which is shared between the server and the client, then you can network the index of the selected RP name (for less network traffic)
to get a random index, use
[code]
math.random(1, #aTable)
[/code]
That will return a table index beween 1 and the length of the table, which you can use to index your table.
Network that int and you can use that on server and client to get the RP name. This is how it is done in SeriousRP. I have about 30,000 different names (and don't bother with surnames) in the list.
You can use [URL="http://wiki.garrysmod.com/page/util/SharedRandom"]util.SharedRandom[/URL], it's a new function and it's simpler because you don't need to network it. It returns a float so you should also use [URL="http://wiki.garrysmod.com/page/math/Round"]math.Round[/URL].
[lua]local index = math.Round( util.SharedRandom("darkrp_name", 1, #aTable) )
local name = aTable[index]
[/lua]
Though I'm not sure if setRPName needs to be called on the client and the server.
[QUOTE=tommy228;45592950]You can use [URL="http://wiki.garrysmod.com/page/util/SharedRandom"]util.SharedRandom[/URL], it's a new function and it's simpler because you don't need to network it. It returns a float so you should also use [URL="http://wiki.garrysmod.com/page/math/Round"]math.Round[/URL].
[lua]local index = math.floor( util.SharedRandom("darkrp_name", 1, #aTable) )
local name = aTable[index]
[/lua]
Though I'm not sure if setRPName needs to be called on the client and the server.[/QUOTE]
It's called on serverside
[QUOTE=tommy228;45592950]You can use [URL="http://wiki.garrysmod.com/page/util/SharedRandom"]util.SharedRandom[/URL], it's a new function and it's simpler because you don't need to network it. It returns a float so you should also use [URL="http://wiki.garrysmod.com/page/math/Round"]math.Round[/URL].
[lua]local index = math.Round( util.SharedRandom("darkrp_name", 1, #aTable) )
local name = aTable[index]
[/lua]
Though I'm not sure if setRPName needs to be called on the client and the server.[/QUOTE]
The thing with not networking it is this:
What happens when the new players join after the value has been transmitted to all players? That case needs to be handled, then (I think).
[QUOTE=tommy228;45592950]You can use [URL="http://wiki.garrysmod.com/page/util/SharedRandom"]util.SharedRandom[/URL], it's a new function and it's simpler because you don't need to network it. It returns a float so you should also use [URL="http://wiki.garrysmod.com/page/math/Round"]math.Round[/URL].
[lua]local index = math.Round( util.SharedRandom("darkrp_name", 1, #aTable) )
local name = aTable[index]
[/lua]
Though I'm not sure if setRPName needs to be called on the client and the server.[/QUOTE]
Yeah, I have no clue how to do this, could you post an example, I'm stuck.
Please Help!
[QUOTE=Frozendairy;45600644]Please Help![/QUOTE]
I think the issue is that we're not sure exactly how much help you need. What parts don't you understand?
Sorry, you need to Log In to post a reply to this thread.