Advertisement
soulshaker

VCMP 0.4 Spectate System

Feb 23rd, 2015
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 4.01 KB | None | 0 0
  1. This Function is made by Stormeus( I got from public beta Script). I just extracted this function from the script
  2.  
  3. ====Installation====
  4.  
  5. http://s14.postimg.org/u1skhm2q5/hint_spectate.png
  6. http://s14.postimg.org/cagy35nbh/hint_specmenu.png
  7.  
  8. Put the hint_spectate.png and hint_specmenu.png in /store/sprites folder
  9.  
  10. ///Official Events///
  11.  
  12. Global Variables:-
  13.  
  14. BIND_SPEC_TOGGLE      <- null;
  15. BIND_SPEC_NEXT        <- null;
  16. BIND_SPEC_PREV        <- null;
  17.  
  18. SPRITE_SPECHINT       <- null;
  19. SPRITE_SPECTATEMENU   <- null;
  20.  
  21. function onScriptLoad()
  22. {
  23.     SPRITE_SPECHINT = CreateSprite("hint_spectate.png", -150, -384, 0, 0, 0, 255);
  24.     SPRITE_SPECTATEMENU = CreateSprite("hint_specmenu.png", -220, -384, 0, 0, 0, 255);
  25.     BIND_SPEC_TOGGLE      = BindKey( true, 0x53, 0, 0 );
  26.     BIND_SPEC_NEXT        = BindKey( true, 0x27, 0, 0 );
  27.     BIND_SPEC_PREV        = BindKey( true, 0x25, 0, 0 );
  28. }
  29.  
  30. function onPlayerRequestClass( player, classID, team, skin )
  31. {
  32.     if(player.SpectateTarget == null)
  33.     SPRITE_SPECHINT.ShowForPlayer(player);
  34.     else if(player.SpectateTarget == null)
  35.     {
  36.     return 1;
  37.     }
  38. }
  39.  
  40. function onPlayerSpawn( player )
  41. {
  42. player.SpectateTarget = null;
  43. SPRITE_SPECHINT.HideFromPlayer(player);
  44. SPRITE_SPECTATEMENU.HideFromPlayer(player);
  45. }
  46.  
  47. function onKeyDown( player, key )
  48. {
  49. if ( key == BIND_SPEC_NEXT )
  50.     {
  51.         if( player.SpectateTarget != null && !player.Spawned )
  52.             {
  53.                 local pTargetID = player.SpectateTarget.ID;
  54.                 local pTargetFind = pTargetID + 1;
  55.                 local pNewTarget = null;
  56.  
  57.                 while(pNewTarget == null && pTargetFind != pTargetID)
  58.                 {
  59.                     if(pTargetFind > GetMaxPlayers() - 1)
  60.                         pTargetFind = 0;
  61.  
  62.                     pNewTarget = FindPlayer(pTargetFind++);
  63.                     if(pNewTarget != null && !pNewTarget.Spawned)
  64.                         pNewTarget = null;
  65.                 }
  66.  
  67.                 if(pNewTarget == null || pNewTarget.ID == pTargetID)
  68.                     ClientMessage( "[#ed4242]Error: [#e9e9e9]No one else can be spectated.", player, 0, 0, 0 );
  69.                 else
  70.                 {
  71.                     player.SpectateTarget = pNewTarget;
  72.                     local szMsg = "[#e9e9e9]You are now spectating [#80eb7a]" + pNewTarget.Name + " (" + pNewTarget.ID + ")";
  73.                     MessagePlayer(szMsg, player);
  74.                 }
  75.  
  76.                 return;
  77.             }
  78.     }
  79. if ( key == BIND_SPEC_PREV )
  80.     {
  81.         if( player.SpectateTarget != null && !player.Spawned )
  82.             {
  83.                 local pTargetID = player.SpectateTarget.ID;
  84.                 local pTargetFind = pTargetID - 1;
  85.                 local pNewTarget = null;
  86.  
  87.                 while(pNewTarget == null && pTargetFind != pTargetID)
  88.                 {
  89.                     if(pTargetFind < 0)
  90.                         pTargetFind = GetMaxPlayers() - 1;
  91.  
  92.                     pNewTarget = FindPlayer(pTargetFind--);
  93.                     if(pNewTarget != null && !pNewTarget.Spawned)
  94.                         pNewTarget = null;
  95.                 }
  96.  
  97.                 if(pNewTarget == null || pNewTarget.ID == pTargetID)
  98.                     ClientMessage( "[#ed4242]Error: [#e9e9e9]No one else can be spectated.", player, 0, 0, 0 );
  99.                 else
  100.                 {
  101.                     player.SpectateTarget = pNewTarget;
  102.                     local szMsg = "[#e9e9e9]You are now spectating [#80eb7a]" + pNewTarget.Name + " (" + pNewTarget.ID + ")";
  103.                     MessagePlayer(szMsg, player);
  104.                 }
  105.                
  106.                 return;
  107.             }
  108.     }
  109. if ( key == BIND_SPEC_TOGGLE )
  110.     {
  111.             if(!player.Spawned)
  112.             {
  113.                 if(player.SpectateTarget != null)
  114.                 {
  115.                     SPRITE_SPECTATEMENU.HideFromPlayer(player);
  116.                     SPRITE_SPECHINT.ShowForPlayer(player);
  117.                     player.SpectateTarget = null;
  118.                 }
  119.                 else
  120.                 {
  121.                     local pTargetID = 0;
  122.                     local pNewTarget = null;
  123.                
  124.                     while(pNewTarget == null && pTargetID < GetMaxPlayers())
  125.                     {
  126.                         pNewTarget = FindPlayer(pTargetID++);
  127.                         if(pNewTarget != null && !pNewTarget.Spawned)
  128.                             pNewTarget = null;
  129.                     }
  130.                
  131.                     if(pNewTarget == null)
  132.                         ClientMessage( "[#ed4242]Error: [#e9e9e9]No one can be spectated at this time.", player, 0, 0, 0 );
  133.                     else
  134.                     {
  135.                         player.SpectateTarget = pNewTarget;
  136.                         local szMsg = "[#e9e9e9]You are now spectating [#80eb7a]" + pNewTarget.Name + " (" + pNewTarget.ID + ")";
  137.                         MessagePlayer(szMsg, player);
  138.  
  139.                         SPRITE_SPECTATEMENU.ShowForPlayer(player);
  140.                         SPRITE_SPECHINT.HideFromPlayer(player);
  141.                     }
  142.                 }
  143.  
  144.                 return;
  145.             }
  146.     }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement