jkub Posted May 21, 2009 Share Posted May 21, 2009 I have made 4 spawn points and I would like to where when someone joins they spawn randomly to one of those points using the mat.random function. ive tried this but it seems to be inaffective g_root = getRootElement() spawnPoints = { } function spawnPlayer ( ) spawnPoints[1] = 0, 0, 5 spawnPoints[2] = 0, 500, 5 spawnPoints[3] = 500, 0, 5 spawnPoints[4] = 1000, 0, 5 randomSpawn = math.random ( 1, #spawnPoints ) spawnPlayer ( source, randomSpawn ) end addEventHandler ( "onPlayerJoin", g_root, spawnPlayer ) Link to comment
[DKR]silverfang Posted May 21, 2009 Share Posted May 21, 2009 I have made 4 spawn points and I would like to where when someone joins they spawn randomly to one of those points using the mat.random function. ive tried this but it seems to be inaffective Ok it's close, but the randomSpawn is only an integer between 1 and #spawnPoints (number in the array) you need to put this: g_root = getRootElement() spawnPoints = { } function spawnPlayer ( ) spawnPoints[1] = 0, 0, 5 spawnPoints[2] = 0, 500, 5 spawnPoints[3] = 500, 0, 5 spawnPoints[4] = 1000, 0, 5 randomSpawn = math.random ( 1, #spawnPoints ) spawnPlayer ( source, spawnPoints[randomSpawn] ) end addEventHandler ( "onPlayerJoin", g_root, spawnPlayer ) That should be ok Link to comment
robhol Posted May 21, 2009 Share Posted May 21, 2009 It's kind of odd how nobody noticed the potential infinite loop. Rename your function. Link to comment
Willy Posted May 21, 2009 Share Posted May 21, 2009 its not an infinite loop, just simple recursion. but yeh, silly function name. Link to comment
robhol Posted May 21, 2009 Share Posted May 21, 2009 Actually, yes, it's an infinite loop, since there's no way it'll break once it's called... Link to comment
jkub Posted May 21, 2009 Author Share Posted May 21, 2009 When I put my first version of this in debug It did say somthing about a "stack overflow" Could that be what you guys are referring to? Link to comment
robhol Posted May 21, 2009 Share Posted May 21, 2009 Yes. Just rename your function and you should be fine. Link to comment
jkub Posted May 21, 2009 Author Share Posted May 21, 2009 I renamed the function and still nothing. It says that the spawnPlayer line is a bad argument Link to comment
Lordy Posted May 21, 2009 Share Posted May 21, 2009 Kinda odd nobody noticed declaring a var like var = value, anothervalue, anothervalue... you can assign only one value to a variable.. So I would just make them into a table spawnPoints[1] ={ 0, 0, 5} spawnPoints[2] = {0, 500, 5} spawnPoints[3] = {500, 0, 5} spawnPoints[4] = {1000, 0, 5} and later use spawnPlayer(source, spawnPoints[randomSpawn][1],spawnPoints[randomSpawn][2],spawnPoints[randomSpawn][3]) Link to comment
50p Posted May 22, 2009 Share Posted May 22, 2009 Kinda odd nobody noticed declaring a var likevar = value, anothervalue, anothervalue... you can assign only one value to a variable.. So I would just make them into a table spawnPoints[1] ={ 0, 0, 5} spawnPoints[2] = {0, 500, 5} spawnPoints[3] = {500, 0, 5} spawnPoints[4] = {1000, 0, 5} and later use spawnPlayer(source, spawnPoints[randomSpawn][1],spawnPoints[randomSpawn][2],spawnPoints[randomSpawn][3]) or this should work too: spawnPlayer( source, unpack( spawnPoints[ randomSpawn ] ) ); Link to comment
jkub Posted May 26, 2009 Author Share Posted May 26, 2009 ok:) Thank you so much. that seemed to work:) Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now