fr1kin

Stronghold Anti-Spawn Protection

Jan 1st, 2012
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. // alternative to checking alpha
  2.  
  3. local plInfo = {}
  4.  
  5. // Check if player is dead or alive
  6. local function CheckLifeState( pl )
  7. // Init varaibles if they didn't exist before
  8. if( !plInfo[pl] ) then
  9. plInfo[pl] = {};
  10.  
  11. // Varaibles
  12. plInfo[pl].IsAlive = false;
  13. plInfo[pl].DiedThisFrame = false;
  14. plInfo[pl].SpawnedThisFrame = false;
  15. plInfo[pl].IsSpawnProtected = false;
  16.  
  17. plInfo[pl].LF = {}
  18. plInfo[pl].LF.IsAlive = false;
  19. end
  20.  
  21. // Restor these back to normal as they only are true for ONE frame
  22. plInfo[pl].DiedThisFrame = false;
  23. plInfo[pl].SpawnedThisFrame = false;
  24.  
  25. // Normal check
  26. plInfo[pl].IsAlive = c.Player['Alive']( pl );
  27.  
  28. // Player is DEAD and was ALIVE last frame.
  29. if( ( plInfo[pl].IsAlive == false ) && ( plInfo[pl].LF.IsAlive == true ) ) then
  30. plInfo[pl].DiedThisFrame = true;
  31. end
  32.  
  33. // Player is ALIVE and was DEAD last frame.
  34. if( ( plInfo[pl].IsAlive == true ) && ( plInfo[pl].LF.IsAlive == false ) ) then
  35. plInfo[pl].SpawnedThisFrame = true;
  36. end
  37.  
  38. // Check if the player has spawn protection
  39. if( plInfo[pl].SpawnedThisFrame && ( ( GAMEMODE.Name ):lower() ):find( "stronghold" ) ) then
  40. local bShouldProtect, spawners = true, ents.FindByClass( "sent_spawnpoint" ) || nil;
  41. if( spawners ) then
  42. for m, n in pairs( spawners ) do
  43. local entDist = n:GetPos():Distance( pl:GetPos() );
  44. if( entDist < 45 ) then
  45. bShouldProtect = false;
  46. end
  47. end
  48. end
  49. if( bShouldProtect ) then
  50. plInfo[pl].IsSpawnProtected = true;
  51. timer.Simple( 4, function()
  52. plInfo[pl].IsSpawnProtected = false;
  53. end )
  54. end
  55. end
  56.  
  57. // Save data for this frame
  58. plInfo[pl].LF.IsAlive = c.Player['Alive']( pl );
  59. end
Advertisement
Add Comment
Please, Sign In to add comment