_Sk_

Automatic Gate System Suggestion

Feb 28th, 2015
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 2.48 KB | None | 0 0
  1. // A Simple Suggestion into Souly's Automatic Gate System
  2. function onScriptLoad()
  3. {
  4.         gate <- CreateObject( 310, 1, -276.618, -495.992, 10.2778, 255 );
  5.         gate_timer<-NewTimer("gatesystem", 500, 0 );
  6.         //Using Global array for timer so that timer should not be running when no player is online of no one spawned.
  7.         gate_timer.Stop(); // No one will be spawned on startup so no need for that.
  8.         g_Spawned<-array(1,101); // This is the global array to insert the id of player who are spawned.
  9. }
  10. function onPlayerSpawn(player){
  11. //and then onPlayerSpawn insert the id of spawned player by calling Add_p function
  12. Add_p(player);
  13. //you stuff after this.
  14.  
  15. }
  16. // and then call this function Remove_p where player dies or leaves.
  17.  onPlayerDeath( player, reason )
  18. {
  19. Remove_p(player);
  20. //you stuff after this.
  21.  
  22. }
  23. onPlayerKill( killer, player, reason, bodypart )
  24. {
  25. Remove_p(player);
  26. //you stuff after this.
  27.  
  28. }
  29. onPlayerTeamKill( killer, player, reason, bodypart )
  30. {
  31. Remove_p(player);
  32. //you stuff after this.
  33.  
  34. }
  35. onPlayerPart(player,reason)
  36. {
  37. Remove_p(player);
  38. //you stuff after this.
  39.  
  40. }
  41. function Add_p(player)
  42. {
  43. local id = player.ID;
  44. g_Spawned.push(id); //pushing the id of player who just spawned.
  45. if (gate_timer.Paused) // if the timer was stopped or wasn't started.
  46.     {
  47.     gate_timer.Start(); //Start the timer as one or someone is spawned.
  48.     }
  49. }
  50. function Remove_p(player)
  51. {
  52. local id = player.ID;
  53. if (g_Spawned.find(id)) //if player's id was inside the spawned players array.
  54.     {
  55.     local i = g_Spawned.find(id);
  56.     // array.find(val) returns the slot or index of the array where val is present.
  57.     g_Spawned.remove(i);
  58.     // removing player's id from the array.
  59.     }
  60.     //now to decrease further lag we will stop the timer if no one is spawned.
  61. if (g_Spawned.len()<2) gate_timer.Stop();
  62. //Smaller then 2 equals 1 which means no one is spawned and now we can stop the timer.
  63. //as i have already created an extra value in array 101 at index 0.
  64. }
  65.  
  66. //So now you can use your function something like this.
  67. function gatesystem()
  68. {
  69. local gatestatus = 0;
  70. foreach(i in g_Spawned ) //This will get the value from each array.
  71. {
  72. if (i < 100)
  73. {
  74. local player = FindPlayer( i);
  75. if ( player )
  76. {
  77. 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;
  78. }
  79. }
  80. }
  81. if ( gatestatus ) gate.MoveTo( Vector( -268.576, -495.99, 10.2778 ), 2800 );
  82. else gate.MoveTo( Vector( -276.618, -495.992, 10.2778 ), 2800 );    
  83. }
Advertisement
Add Comment
Please, Sign In to add comment