Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // A Simple Suggestion into Souly's Automatic Gate System
- function onScriptLoad()
- {
- gate <- CreateObject( 310, 1, -276.618, -495.992, 10.2778, 255 );
- gate_timer<-NewTimer("gatesystem", 500, 0 );
- //Using Global array for timer so that timer should not be running when no player is online of no one spawned.
- gate_timer.Stop(); // No one will be spawned on startup so no need for that.
- g_Spawned<-array(1,101); // This is the global array to insert the id of player who are spawned.
- }
- function onPlayerSpawn(player){
- //and then onPlayerSpawn insert the id of spawned player by calling Add_p function
- Add_p(player);
- //you stuff after this.
- }
- // and then call this function Remove_p where player dies or leaves.
- onPlayerDeath( player, reason )
- {
- Remove_p(player);
- //you stuff after this.
- }
- onPlayerKill( killer, player, reason, bodypart )
- {
- Remove_p(player);
- //you stuff after this.
- }
- onPlayerTeamKill( killer, player, reason, bodypart )
- {
- Remove_p(player);
- //you stuff after this.
- }
- onPlayerPart(player,reason)
- {
- Remove_p(player);
- //you stuff after this.
- }
- function Add_p(player)
- {
- local id = player.ID;
- g_Spawned.push(id); //pushing the id of player who just spawned.
- if (gate_timer.Paused) // if the timer was stopped or wasn't started.
- {
- gate_timer.Start(); //Start the timer as one or someone is spawned.
- }
- }
- function Remove_p(player)
- {
- local id = player.ID;
- if (g_Spawned.find(id)) //if player's id was inside the spawned players array.
- {
- local i = g_Spawned.find(id);
- // array.find(val) returns the slot or index of the array where val is present.
- g_Spawned.remove(i);
- // removing player's id from the array.
- }
- //now to decrease further lag we will stop the timer if no one is spawned.
- if (g_Spawned.len()<2) gate_timer.Stop();
- //Smaller then 2 equals 1 which means no one is spawned and now we can stop the timer.
- //as i have already created an extra value in array 101 at index 0.
- }
- //So now you can use your function something like this.
- function gatesystem()
- {
- local gatestatus = 0;
- foreach(i in g_Spawned ) //This will get the value from each array.
- {
- if (i < 100)
- {
- local player = FindPlayer( i);
- if ( player )
- {
- if ( InPoly( player.Pos.x, player.Pos.y, -276.2,-503.462,-268.675,-502.296,-268.887,-488.42,-276.471,-487.991 ) ) gatestatus = 1;
- }
- }
- }
- if ( gatestatus ) gate.MoveTo( Vector( -268.576, -495.99, 10.2778 ), 2800 );
- else gate.MoveTo( Vector( -276.618, -495.992, 10.2778 ), 2800 );
- }
Advertisement
Add Comment
Please, Sign In to add comment