Author Topic: Random!  (Read 4903 times)

IdkanYavuk X

  • Jr. Member
  • **
  • Posts: 91
  • Karma: +37/-36
  • Developer for The Newport Experience
    • View Profile
Random!
« on: October 18, 2012, 06:05:38 am »
Hello people!

Is it possible to make the server choose one random spawn from 10 predefined locations on each respawn / connection?

You know... "I die, I respawn on Chinatown, I die again, and I respawn under a bridge, I reconnect and I spawn on the airport" :D

That's a great idea and I can use it for many things

Thank You
« Last Edit: December 08, 2012, 09:46:50 pm by IdkanYavuk »

Thijn

  • Tester
  • Sr. Member
  • ****
  • Posts: 531
  • Karma: +27/-16
    • View Profile
Re: Random!
« Reply #1 on: October 18, 2012, 11:17:23 am »
You can create a random integer with the following function:
Code: [Select]
function RandNum ( start, ... )
{
if ( vargv.len() > 0 ) local end = vargv[ 0 ];
else { local end = start; start = 1; }
local ticks = GetTickCount();
return start + ( ticks % ( end - start ) );
}

To have a random respawn. Make an array with all vector's of the spawn positions you want.
Something like this:
Code: [Select]
RandomSpawns <- [ Vector( 1, 1, 1 ), Vector( 2, 2, 2 ) ];

Then on spawn, Pick a random number with that ^^ function, and teleport the player to the position in the array.
Something like:
Code: [Select]
local rand = RandNum( 0, RandomSpawns.len() );
if ( rand ) pPlayer.Pos = RandomSpawns[ rand ];

Untested, but in theory it should work that way.

Good luck ;)

IdkanYavuk X

  • Jr. Member
  • **
  • Posts: 91
  • Karma: +37/-36
  • Developer for The Newport Experience
    • View Profile
Re: Random!
« Reply #2 on: October 23, 2012, 06:27:37 pm »
Ok I need help

Code: [Select]
RandomSpawns <- [ Vector( -1540.2, -950.1, 14.51 ), Vector( 1360.5, -437.5, 50.01 ) ];

function RandNum ( start, ... )
{
if ( vargv.len() > 0 ) local end = vargv[ 0 ];
else { local end = start; start = 1; }
local ticks = GetTickCount();
*return start + ( ticks % ( end - start ) );
}

function onPlayerSpawn( plr, spn )
{
local bank = GetPlayerBank( plr.Name );
PlrTeamCheck( plr, bank );
local rand = RandNum( 1, RandomSpawns.len() );
if ( rand ) plr.Pos = RandomSpawns[ rand ];
}

* means a console error
« Last Edit: December 08, 2012, 09:46:20 pm by IdkanYavuk »

Thijn

  • Tester
  • Sr. Member
  • ****
  • Posts: 531
  • Karma: +27/-16
    • View Profile
Re: Random!
« Reply #3 on: October 24, 2012, 09:26:16 pm »
The line the error is coming from needs to be:
if ( rand ) plr.Pos = RandomSpawns[ rand ];

IdkanYavuk X

  • Jr. Member
  • **
  • Posts: 91
  • Karma: +37/-36
  • Developer for The Newport Experience
    • View Profile
Re: Random!
« Reply #4 on: October 25, 2012, 02:05:04 am »
Lol no, that was a typo, an I fixed it, but still the above error
« Last Edit: December 08, 2012, 09:45:55 pm by IdkanYavuk »

Thijn

  • Tester
  • Sr. Member
  • ****
  • Posts: 531
  • Karma: +27/-16
    • View Profile
Re: Random!
« Reply #5 on: October 25, 2012, 02:24:42 pm »
What error?

Why does everyone on this forum keeps saying "it gives an error" but fail to say WHAT ERROR.
How can we actually help people if they don't say what error they're giving.
Sorry to rage on your topic, but it had to be said.

IdkanYavuk X

  • Jr. Member
  • **
  • Posts: 91
  • Karma: +37/-36
  • Developer for The Newport Experience
    • View Profile
Re: Random!
« Reply #6 on: October 25, 2012, 04:45:04 pm »
Err, here it comes again:

Code: [Select]
RandomSpawns <- [ Vector( -1540.2, -950.1, 14.51 ), Vector( 1360.5, -437.5, 50.01 ) ];

function RandNum ( start, ... )
{
if ( vargv.len() > 0 ) local end = vargv[ 0 ];
else { local end = start; start = 1; }
local ticks = GetTickCount();
*return start + ( ticks % ( end - start ) );
}

* means an error
Thijn, calm down! I've already posted it
If you mean the console error, well, is the typical "Could not retrieve User Data"
« Last Edit: December 08, 2012, 09:45:37 pm by IdkanYavuk »

 

© Liberty Unleashed Team.