Liberty Unleashed
Scripting => Script Help => Topic started 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
-
You can create a random integer with the following function:
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:
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:
local rand = RandNum( 0, RandomSpawns.len() );
if ( rand ) pPlayer.Pos = RandomSpawns[ rand ];
Untested, but in theory it should work that way.
Good luck ;)
-
Ok I need help
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
-
The line the error is coming from needs to be:
if ( rand ) plr.Pos = RandomSpawns[ rand ];
-
Lol no, that was a typo, an I fixed it, but still the above error
-
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.
-
Err, here it comes again:
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"