Liberty Unleashed

Scripting => Script Help => Topic started by: IdkanYavuk X on October 18, 2012, 06:05:38 am

Title: Random!
Post by: IdkanYavuk X 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
Title: Re: Random!
Post by: Thijn 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 ;)
Title: Re: Random!
Post by: IdkanYavuk X 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
Title: Re: Random!
Post by: Thijn on October 24, 2012, 09:26:16 pm
The line the error is coming from needs to be:
if ( rand ) plr.Pos = RandomSpawns[ rand ];
Title: Re: Random!
Post by: IdkanYavuk X on October 25, 2012, 02:05:04 am
Lol no, that was a typo, an I fixed it, but still the above error
Title: Re: Random!
Post by: Thijn 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.
Title: Re: Random!
Post by: IdkanYavuk X 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"