Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Random spawn players
#1
Hello, Polish friends)

How do I make random player spawn? 
For a person to spawn on one of the many recorded coordinates.

p.s
Thank you, you are cool
Reply
#2
Use rand() function
Reply
#3
(09.02.2020, 18:00)Quarchodron Wrote: Use rand() function

sorry, i noob,
but I know about this command, I just don't understand how to connect it to coordinates...
Reply
#4
local tab = [
[x,y,z,angle],
[x,y,z,angle],
[x,y,z,angle]
];

addEventHandler("onPlayerSpawn", function(pid) {
local random = (rand() % tab.len())-1;
setPlayerPosition(pid, tab[random][0], tab[random][1],tab[random][2]);
setPlayerAngle(pid, tab[random][3]);
});
Reply
#5
(09.02.2020, 23:05)Quarchodron Wrote: local tab = [
[x,y,z,angle],
[x,y,z,angle],
[x,y,z,angle]
];

addEventHandler("onPlayerSpawn", function(pid) {
  local random = (rand() % tab.len())-1;
  setPlayerPosition(pid, tab[random][0], tab[random][1],tab[random][2]);
  setPlayerAngle(pid, tab[random][3]);
});
Thank you very much. I suffered for several days, with this.
May Sleeper protect you))

(09.02.2020, 23:05)Quarchodron Wrote: local tab = [
[x,y,z,angle],
[x,y,z,angle],
[x,y,z,angle]
];

addEventHandler("onPlayerSpawn", function(pid) {
  local random = (rand() % tab.len())-1;
  setPlayerPosition(pid, tab[random][0], tab[random][1],tab[random][2]);
  setPlayerAngle(pid, tab[random][3]);
});
Hello again. Random works every other time.
If it didn't work, the console shows an error:

[squirrel] runtime Error: 'gamemodes/prototype/server-scripts/main.nut' (Ln: 162): the index '-1' does not exist

-== Local varaiable: ==-
+ array: tab
+ integer: random (-1)
+ integer: pid (0)
+ table: this
Reply
#6
Sorru but in arg random delete this - 1 aftee bracket. And add - 1 after. Len()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Give random item for Player liegav 6 6,348 14.02.2018, 18:30
Last Post: Patrix
  Random Number Osmith 5 4,585 20.02.2016, 14:21
Last Post: Blacha

Forum Jump:


Users browsing this thread: 1 Guest(s)