DakiLLa Posted January 7, 2009 Share Posted January 7, 2009 Hello. I have one question about randoms: let's suppose that i have 3 spawnpoints with coordinates X1 Y1 Z1, X2 Y2 Z2, X3 Y3 Z3. How to make that player will be spawns randomly in one of these spawnpoints ? Link to comment
Willy Posted January 7, 2009 Share Posted January 7, 2009 spawns = {} --table that will hold all the spawn points spawns[1] = {123,423,1}--{ x1,y1,z1 } spawns[2] = {342,-2341,3}--{ x2,y2,z2 } spawns[3] = {-5,3,8}--{ x3,y3,z3 } --use math.random to generate a number between 1 and #spawns (the length of the table spawns) randomNumber = math.random(1,#spawns) --assign the numbers within the table to x y and z x = spawns[randomNumber][1] y = spawns[randomNumber][2] z = spawns[randomNumber][3] spawnPlayer(player,x,y,z) there is an easier way to declare the initial table, but i did it that way so you would understand it. If you don't get it then post back. Link to comment
DakiLLa Posted January 7, 2009 Author Share Posted January 7, 2009 well, and if i want to use more than three spawnpoits, how will be looking this part of script ? in my first post we have three sp.points and three coordinates (xyz). how to be with five sp.points and three coordinates ? i mean this part: x = spawns[randomNumber][1] y = spawns[randomNumber][2] z = spawns[randomNumber][3] Link to comment
Willy Posted January 7, 2009 Share Posted January 7, 2009 if you look at the code, i'm generating a random number based on how many entries you have in the table, all you would need to do is add the extra spawns to the spawns table, like this: spawns[4] = {-934,133,418}--{ x4,y4,z4 } the last bit of the script will stay the same, for example if we generated a random number, and the randomNumber variable was 2, the last bit is the same as: x = spawns[2][1] y = spawns[2][2] z = spawns[2][3] instead of the variable "randomNumber" we are using the number value 2, because randomNumber = 2. which would mean that the x, y and z values would be: --spawns[2] = {342,-2341,3} --spawns[2][1] = 342 = x --spawns[2][2] = -2341 = y --spawns[2][3] = 3 = z Link to comment
DakiLLa Posted January 7, 2009 Author Share Posted January 7, 2009 Great, thx for help. This is what i need.. 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