[BASIC] Access to bank vault

Started by Diego^, Mar 03, 2015, 02:34 AM

Previous topic - Next topic

Diego^

function onPlayerSpawn( player )
{
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
}

function CheckSafe( user )
{
local player = FindPlayer( user );
if ( player )
{
local EnterSafe = DistanceFromPoint( player.Pos.x, player.Pos.z, -937.731, 17.8038 );
local ExitSafe = DistanceFromPoint( player.Pos.x, player.Pos.z, -937.698, 7.22692 );
if ( EnterSafe.tointeger() < 1 )
{
NewTimer( "ResetFffect", 500, 1, player.ID );
player.Pos = Vector( -937.698, -351.819, 7.22692 );
player.Widescreen = true;
}
else if ( ExitSafe.tointeger() < 1 )
{
NewTimer( "ResetFffect", 500, 1, player.ID );
player.Pos = Vector( -937.731, -351.445, 17.8038 );
player.Widescreen = true;
}
}
}

function ResetFffect( user )
{
local player = FindPlayer( user );
if ( player )
{
player.Widescreen = false;
}
}

function onPlayerTeamKill( killer, player ,reason, bodypart )
{
Safe.Delete();
}

function onPlayerKill( killer,player, reason, bodypart )
{
Safe.Delete();
}

function onPlayerDeath( player, reason )
{
Safe.Delete();
}
BRL's Developer.

Thijn

Try to think what will happen when 2 players are spawned.
Safe is a "global" variable that can only hold one value. So when player 2 spawns, the timer that was created for player 1 will be overwritten and can't be stopped or deleted. Keep doing that for a few times and you got yourself a laggy server.

You can either use 1 timer, and loop through all players checking if they're spawned and near the vault.
Or you need to use an array that will holp the timer for each player.

PsyChO_KiLLeR

can u explain what is this system?

.

Quote from: PsyChO_KiLLeR on Mar 03, 2015, 08:06 AMcan u explain what is this system?

What he means is that you create a timer and then you create another timer and another and another and so on. And you create them all in the same storage unit. A global variable called `Safe`. The line of code in `onPlayerSpawn()` will essentially do this:

Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
// ... Endlesly (So look careful at your mistake)

Which timer instance do you think will be in that variable after a while? All of them or just one? And if is just one then which one?

To make this abundantly clear I want to add this line of code at the beginning in your `CheckSafe()` function:
print("User with ID " + user + " triggered CheckSafe() function.");
  • And then I want you to go in the game and Spawn once. You will see one of those message with your player ID every 3 seconds.
  • Now I want you to die and spawn again. You will see two of those message with your player ID every 3 seconds.
  • Now I want you to die and spawn again. You will see three of those message with your player ID every 3 seconds.
  • Now I want you to die and spawn again. You will see four of those message with your player ID every 3 seconds.
  • Now I want you to die and spawn again. You will see five of those message with your player ID every 3 seconds.
  • Now I want you to die and spawn again. You will see six of those message with your player ID every 3 seconds.
  • Now I want you to die and spawn again. You will see seven of those message with your player ID every 3 seconds.
  • Now I want you to die and spawn again. You will see eight of those message with your player ID every 3 seconds.
  • Now I want you to die and spawn again. You will see nine of those message with your player ID every 3 seconds.
  • Now I want you to die and spawn again. You will see ten of those message with your player ID every 3 seconds.
  • ... Now I want you to keep doing that for a while and keep counting how many of those messages are printed every 3 seconds.

And keep in mind that there's only 1 player on the server now! So I want to to become super genius today and do the math for a normal game session and the amount of spawns that happen during that session.

.

.

I'm not sure how much you will understand from this but here's an example on how you should start your scripts. Look at the `SafeUpdate` function in there:
Core moved to Pastebin to preserver indentation: http://pastebin.com/rqEBH6cu
Note: That thing was just cut from one of my older tests. It's not the code for your needs and it's just an example on how you should do things.
.

Diego^

Quote from: Diego^ on Mar 03, 2015, 02:34 AMfunction onPlayerSpawn( player )
{
Safe <- NewTimer( "CheckSafe", 3000, 0, player.ID );
}

function CheckSafe( user )
{
local player = FindPlayer( user );
if ( player )
{
local EnterSafe = DistanceFromPoint( player.Pos.x, player.Pos.z, -937.731, 17.8038 );
local ExitSafe = DistanceFromPoint( player.Pos.x, player.Pos.z, -937.698, 7.22692 );
if ( EnterSafe.tointeger() < 1 )
{
NewTimer( "ResetFffect", 500, 1, player.ID );
player.Pos = Vector( -937.698, -351.819, 7.22692 );
player.Widescreen = true;
}
else if ( ExitSafe.tointeger() < 1 )
{
NewTimer( "ResetFffect", 500, 1, player.ID );
player.Pos = Vector( -937.731, -351.445, 17.8038 );
player.Widescreen = true;
}
}
}

function ResetFffect( user )
{
local player = FindPlayer( user );
if ( player )
{
player.Widescreen = false;
}
}

function onPlayerTeamKill( killer, player ,reason, bodypart )
{
Safe.Delete();
}

function onPlayerKill( killer,player, reason, bodypart )
{
Safe.Delete();
}

function onPlayerDeath( player, reason )
{
Safe.Delete();
}

Update!

function onScriptLoad()
{
NewTimer( "CheckSafe", 3000, 0 );
}

function CheckSafe()
{
for ( local i = 0; i < GetMaxPlayers(); i++ )
{
local player = FindPlayer( i );
if ( player )
{
            if ( player.IsSpawned )
            {
local EnterSafe = DistanceFromPoint( player.Pos.x, player.Pos.z, -937.731, 17.8038 );
local ExitSafe = DistanceFromPoint( player.Pos.x, player.Pos.z, -937.698, 7.22692 );
if ( EnterSafe.tointeger() < 1 )
{
NewTimer( "ResetFffect", 500, 1, player.ID );
player.Pos = Vector( -937.698, -351.819, 7.22692 );
player.Widescreen = true;
}
else if ( ExitSafe.tointeger() < 0.5 )
{
NewTimer( "ResetFffect", 500, 1, player.ID );
player.Pos = Vector( -937.731, -351.445, 17.8038 );
player.Widescreen = true;
}
}
}
}
}

function ResetFffect( user )
{
local player = FindPlayer( user );
if ( player )
{
player.Widescreen = false;
}
}

This makes it less lag?
BRL's Developer.

Kratos_


I couldn't get one thing .

If the player is at a distance of 1 unit from your specified co-ordinate then it will teleport the player first & then it sets the widescreen mode to true . But just after 0.5 seconds ( Timer Wakeup Iteration : 500 miliseconds ) it will set the game screen back to normal . Both the conditions behave practically same to the game screen except the player will be teleported to different location . ( Your code says it all )

Since the time lag is just 0.5 seconds between the two screen modes , the overall result will be a normal screen . What have you intended to do actually ?
In the middle of chaos , lies opportunity.

.

Quote from: Kratos_ on Mar 04, 2015, 06:44 AMI couldn't get one thing .

I wondering about that too. It made no sense when I read the code. But since I don't play the game and I'm not familiar with all the nonsense in these implementations, I thought it was just me who couldn't get it. But now I see that this whole code is just nonsense.
.

soulshaker


rObInX

Actually, what is the use of this?

Diego^

Quote from: rObInX on Mar 04, 2015, 08:06 PMActually, what is the use of this?

To be teleported to the bank vault.
BRL's Developer.