RanAway

[ Pawn ] Teleport menu

May 10th, 2022 (edited)
905
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 10.58 KB | None | 0 0
  1. /************* Includes ***************/
  2. #include < amxmodx >
  3. #include < cstrike >
  4. #include < fakemeta >
  5.  
  6. /************* Defines ***************/
  7. #define Prefix          "AMXX"
  8. #define ADMIN_ACCESS        ADMIN_IMMUNITY
  9.  
  10. /************* News ***************/
  11. new bool: HasCheckPoint[ 33 ], MyTitle[ 33 ], InviteAcception[ 33 ], Float: MyXYZ[ 33 ][ 3 ], Float:LocationXYZ[ 3 ]
  12.  
  13. public plugin_init()
  14. {
  15.     register_plugin( "Teleport menu", "v1.0", "RanAway`" )
  16.    
  17.     /************* Commands ***************/
  18.     register_clcmd( "say /teleport", "TeleportMenu" )
  19. }
  20.  
  21. /************* Connect ***************/
  22. public client_authorized( id ) HasCheckPoint[ id ] = false
  23.  
  24. /************* Teleport menu ***************/
  25. public TeleportMenu( id )
  26. {
  27.     if( cs_get_user_team( id ) == CS_TEAM_SPECTATOR )
  28.         return ColorChat( id, "You can't teleport as ^3spectator" )
  29.    
  30.     new szMenu[ 500 ]
  31.    
  32.     pev( id, pev_origin, LocationXYZ )
  33.    
  34.     formatex( szMenu, charsmax( szMenu ), "\r[\w %s \r]\w Teleport menu", Prefix )
  35.    
  36.     new menu = menu_create( szMenu, "sub_teleportmenu" )
  37.    
  38.     menu_additem( menu, "Save my current location as checkpoint" )
  39.     menu_additem( menu, "Teleport to my last checkpoint", .callback = menu_makecallback( "blockitem" ) )
  40.     menu_additem( menu, "Remove your checkpoint^n", .callback = menu_makecallback( "blockitem" ) )
  41.     menu_additem( menu, "Teleport someone to your last checkpoint^n", .callback = menu_makecallback( "blockitem" ) )
  42.     menu_additem( menu, "Teleport someone to your location" )
  43.     menu_additem( menu, "Teleport to someone's location" )
  44.    
  45.     formatex( szMenu, charsmax( szMenu ), "check my location \d- \rX\w - \r%f\w | \rY\w - \r%f \w| \rZ\w - \r%f", LocationXYZ[ 0 ], LocationXYZ[ 1 ], LocationXYZ[ 2 ] )
  46.     menu_additem( menu, szMenu )
  47.    
  48.     menu_display( id, menu )
  49.     return 1
  50. }
  51.  
  52. public blockitem( id, menu, item )
  53. {
  54.     if( !HasCheckPoint[ id ] )
  55.         return ITEM_DISABLED
  56.    
  57.     return 0
  58. }
  59.  
  60. public sub_teleportmenu( id, menu, item )
  61. {
  62.     if( item == MENU_EXIT ) return menu_destroy( menu )
  63.    
  64.     if( cs_get_user_team( id ) == CS_TEAM_SPECTATOR )
  65.         return ColorChat( id, "You can't teleport as ^3spectator" )
  66.    
  67.     if( item == 0 )
  68.     {
  69.         pev( id, pev_origin, LocationXYZ )
  70.         ColorChat( id, "Your ^3checkpoint^1 has set to: ^3X^1 - ^3%f ^1| ^3Y^1 - ^3%f ^1| ^3Z^1 - ^3%f", LocationXYZ[ 0 ], LocationXYZ[ 1 ], LocationXYZ[ 2 ] )
  71.         MyXYZ[ id ][ 0 ] = LocationXYZ[ 0 ]
  72.         MyXYZ[ id ][ 1 ] = LocationXYZ[ 1 ]
  73.         MyXYZ[ id ][ 2 ] = LocationXYZ[ 2 ]
  74.         HasCheckPoint[ id ] = true
  75.     }
  76.    
  77.     if( item == 1 )
  78.     {
  79.         ColorChat( id, "You ^3teleported^1 to your ^3checkpoint^1" )
  80.         engfunc( EngFunc_SetOrigin, id, MyXYZ[ id ][ 0 ], MyXYZ[ id ][ 1 ], MyXYZ[ id ][ 2 ] )
  81.     }
  82.    
  83.     if( item == 2 ) HasCheckPoint[ id ] = false
  84.     if( item == 3 )
  85.     {
  86.         MyTitle[ id ] = 1
  87.         return playermenu( id )
  88.     }
  89.     if( item == 4 )
  90.     {
  91.         MyTitle[ id ] = 2
  92.         return playermenu( id )
  93.     }
  94.     if( item == 5 )
  95.     {
  96.         MyTitle[ id ] = 3
  97.         return playermenu( id )
  98.     }
  99.     if( item == 6 )
  100.     {
  101.         pev( id, pev_origin, LocationXYZ )
  102.         ColorChat( id, "Your location is: ^3X^1 - ^3%f ^1| ^3Y^1 - ^3%f ^1| ^3Z^1 - ^3%f", LocationXYZ[ 0 ], LocationXYZ[ 1 ], LocationXYZ[ 2 ] )
  103.     }
  104.    
  105.     return TeleportMenu( id )
  106. }
  107.  
  108. /************* Player menu ***************/
  109. public playermenu( id )
  110. {
  111.     new szMenu[ 130 ], num[ 33 ]
  112.    
  113.     if( MyTitle[ id ] == 1 ) formatex( szMenu, charsmax( szMenu ), "\r[\w %s \r]\w Select player to teleport to your last checkpoint", Prefix )
  114.     if( MyTitle[ id ] == 2 ) formatex( szMenu, charsmax( szMenu ), "\r[\w %s \r]\w Select player to teleport to your location", Prefix )
  115.     if( MyTitle[ id ] == 3 ) formatex( szMenu, charsmax( szMenu ), "\r[\w %s \r]\w Select player to teleport to his location", Prefix )
  116.    
  117.     new menu = menu_create( szMenu, "sub_playermenu" )
  118.    
  119.     menu_additem( menu, "Everyone", .callback = menu_makecallback( "blockplayer" ) )
  120.     menu_additem( menu, "Everyone except me", .callback = menu_makecallback( "blockplayer" ) )
  121.    
  122.     for( new i; i < get_maxplayers() ; i++ )
  123.     {
  124.         if( !is_user_connected( i ) || is_user_bot( i ) || is_user_hltv(i) || i == id || cs_get_user_team( i ) == CS_TEAM_SPECTATOR ) continue
  125.        
  126.         num_to_str( i, num, charsmax( num ) )
  127.        
  128.         formatex( szMenu, charsmax( szMenu ), "\w%s", GetUserName( i ) )
  129.         menu_additem( menu, szMenu, num )
  130.     }
  131.    
  132.     menu_setprop( menu, MPROP_BACKNAME, "Previus Page" )
  133.     menu_setprop( menu, MPROP_NEXTNAME, "Next Page" )
  134.     menu_setprop( menu, MPROP_EXITNAME, "Back to the menu" )
  135.     menu_display( id, menu )
  136.     return 1
  137. }
  138.  
  139. public blockplayer( id, menu, item )
  140. {
  141.     if( MyTitle[ id ] == 3 || !( get_user_flags( id ) & ADMIN_ACCESS ) )
  142.         return ITEM_DISABLED
  143.    
  144.     return 0
  145. }
  146.  
  147. public sub_playermenu(id, menu, item)
  148. {
  149.     if( item == MENU_EXIT ) return TeleportMenu( id )
  150.    
  151.     new Data[ 6 ], access, callback
  152.     menu_item_getinfo( menu, item, access, Data, charsmax( Data ), "", 0, callback )
  153.    
  154.     new tempid = str_to_num( Data )
  155.    
  156.     if( item == 0 )
  157.     {
  158.         for( new i; i < get_maxplayers(); i++ )
  159.         {
  160.             if( MyTitle[ id ] == 1 ) engfunc( EngFunc_SetOrigin, i, MyXYZ[ id ][ 0 ], MyXYZ[ id ][ 1 ], MyXYZ[ id ][ 2 ] )
  161.             if( MyTitle[ id ] == 2 )
  162.             {
  163.                 pev( id, pev_origin, LocationXYZ )
  164.                 engfunc( EngFunc_SetOrigin, i, LocationXYZ[ 0 ], LocationXYZ[ 1 ], LocationXYZ[ 2 ] )
  165.             }
  166.            
  167.             if( MyTitle[ id ] == 3 )
  168.             {
  169.                 pev( tempid, pev_origin, LocationXYZ )
  170.                 engfunc( EngFunc_SetOrigin, i, LocationXYZ[ 0 ], LocationXYZ[ 1 ], LocationXYZ[ 2 ] )
  171.             }
  172.         }
  173.         return playermenu( id )
  174.     }
  175.    
  176.     if( item == 1 )
  177.     {
  178.         for( new i; i < get_maxplayers(); i++ )
  179.         {
  180.             if( i == id ) continue
  181.            
  182.             if( MyTitle[ id ] == 1 ) engfunc( EngFunc_SetOrigin, i, MyXYZ[ id ][ 0 ], MyXYZ[ id ][ 1 ], MyXYZ[ id ][ 2 ] )
  183.             if( MyTitle[ id ] == 2 )
  184.             {
  185.                 pev( id, pev_origin, LocationXYZ )
  186.                 engfunc( EngFunc_SetOrigin, i, LocationXYZ[ 0 ], LocationXYZ[ 1 ], LocationXYZ[ 2 ] )
  187.             }
  188.            
  189.             if( MyTitle[ id ] == 3 )
  190.             {
  191.                 pev( tempid, pev_origin, LocationXYZ )
  192.                 engfunc( EngFunc_SetOrigin, i, LocationXYZ[ 0 ], LocationXYZ[ 1 ], LocationXYZ[ 2 ] )
  193.             }
  194.         }
  195.         return playermenu( id )
  196.     }
  197.    
  198.     if( MyTitle[ id ] == 1 )
  199.     {
  200.         InviteAcception[ tempid ] = id
  201.        
  202.         if( !( get_user_flags( id ) & ADMIN_ACCESS ) )
  203.         {
  204.             ColorChat( id, "You ask ^3%s^1 to teleport to you", GetUserName( tempid ) )
  205.             ColorChat( tempid, "^3%s^1 want you to teleport to him. do you ^3agree?", GetUserName( id ) )
  206.            
  207.             return TeleportAcception( tempid )
  208.         }
  209.        
  210.         if( get_user_flags( tempid ) & ADMIN_IMMUNITY )
  211.         {
  212.             ColorChat( id, "^3%s^1 is ^3immunity^1. you can't ^3teleport^1 him without asking", GetUserName( tempid ) )
  213.             ColorChat( tempid, "^3%s^1 want you to teleport to him. do you ^3agree?", GetUserName( id ) )
  214.            
  215.             return TeleportAcception( tempid )
  216.         }
  217.        
  218.         engfunc( EngFunc_SetOrigin, tempid, MyXYZ[ id ][ 0 ], MyXYZ[ id ][ 1 ], MyXYZ[ id ][ 2 ] )
  219.     }
  220.    
  221.     if( MyTitle[ id ] == 2 )
  222.     {
  223.         InviteAcception[ tempid ] = id
  224.         pev( id, pev_origin, LocationXYZ )
  225.        
  226.         if( !( get_user_flags( id ) & ADMIN_ACCESS ) )
  227.         {
  228.             ColorChat( id, "You ask ^3%s^1 to teleport to you", GetUserName( tempid ) )
  229.             ColorChat( tempid, "^3%s^1 want you to teleport to him. do you ^3agree?", GetUserName( id ) )
  230.            
  231.             return TeleportAcception( tempid )
  232.         }
  233.        
  234.         if( get_user_flags( tempid ) & ADMIN_IMMUNITY )
  235.         {
  236.             ColorChat( id, "^3%s^1 is ^3immunity^1. you can't ^3teleport^1 him without asking", GetUserName( tempid ) )
  237.             ColorChat( tempid, "^3%s^1 want you to teleport to him. do you ^3agree?", GetUserName( id ) )
  238.            
  239.             return TeleportAcception( tempid )
  240.         }
  241.        
  242.         engfunc( EngFunc_SetOrigin, tempid, LocationXYZ[ 0 ], LocationXYZ[ 1 ], LocationXYZ[ 2 ] )
  243.     }
  244.    
  245.     if( MyTitle[ id ] == 3 )
  246.     {
  247.         pev( tempid, pev_origin, LocationXYZ )
  248.         engfunc( EngFunc_SetOrigin, id, LocationXYZ[ 0 ], LocationXYZ[ 1 ], LocationXYZ[ 2 ] )
  249.         ColorChat( id, "You ^3teleported^1 to ^3%s^1", GetUserName( tempid ) )
  250.     }
  251.    
  252.     return playermenu( id )
  253. }
  254.  
  255. /************* Teleport Acception ***************/
  256. public TeleportAcception( id )
  257. {
  258.     if( cs_get_user_team( id ) == CS_TEAM_SPECTATOR )
  259.         return ColorChat( id, "You can't teleport as ^3spectator" )
  260.    
  261.     new szMenu[ 500 ]
  262.    
  263.     if( MyTitle[ InviteAcception[ id ] ] == 1 ) formatex( szMenu, charsmax( szMenu ), "\r[\w %s \r]\w You got teleportaion invite from \r%s's\w checkpoint", Prefix, GetUserName( InviteAcception[ id ] ) )
  264.     else if( MyTitle[ InviteAcception[ id ] ] == 2 ) formatex( szMenu, charsmax( szMenu ), "\r[\w %s \r]\w You got teleportaion invite from \r%s", Prefix, GetUserName( InviteAcception[ id ] ) )
  265.    
  266.     new menu = menu_create( szMenu, "sub_teleportacception" )
  267.    
  268.     menu_additem( menu, "Accept" )
  269.     menu_additem( menu, "Ignore" )
  270.    
  271.     menu_display( id, menu )
  272.     return 1
  273. }
  274.  
  275. public sub_teleportacception( id, menu, item )
  276. {
  277.     if( item == MENU_EXIT ) return TeleportMenu( id )
  278.    
  279.     if( cs_get_user_team( id ) == CS_TEAM_SPECTATOR )
  280.         return ColorChat( id, "You can't teleport as ^3spectator" )
  281.    
  282.     new Data[ 6 ], access, callback
  283.     menu_item_getinfo( menu, item, access, Data, charsmax( Data ), "", 0, callback )
  284.    
  285.     new tempid = InviteAcception[ id ]
  286.    
  287.     if( item == 0 )
  288.     {
  289.         if( MyTitle[ InviteAcception[ id ] ] == 1 )
  290.         {
  291.             engfunc( EngFunc_SetOrigin, id, MyXYZ[ tempid ][ 0 ], MyXYZ[ tempid ][ 1 ], MyXYZ[ tempid ][ 2 ] )
  292.             ColorChat( id, "You accepted to teleport to ^3%s's^1 checkpoint", GetUserName( tempid ) )
  293.         }
  294.         else if( MyTitle[ InviteAcception[ id ] ] == 2 )
  295.         {
  296.             pev( InviteAcception[ id ], pev_origin, LocationXYZ )
  297.             engfunc( EngFunc_SetOrigin, id, LocationXYZ[ 0 ], LocationXYZ[ 1 ], LocationXYZ[ 2 ] )
  298.             ColorChat( id, "You accepted to teleport to ^3%s^1", GetUserName( tempid ) )
  299.         }
  300.        
  301.         ColorChat( tempid, "^3%s^1 accepted your ^3invite", GetUserName( id ) )
  302.     }
  303.    
  304.     if( item == 1 )
  305.     {
  306.         ColorChat( id, "You decline to teleport to ^3%s^1", GetUserName( tempid ) )
  307.         ColorChat( tempid, "^3%s^1 decline your ^3invite", GetUserName( id ) )
  308.     }
  309.    
  310.     return 1
  311. }
  312.  
  313. /************* Stocks ***************/
  314. stock GetUserName( id )
  315. {
  316.     static szName[ 32 ]
  317.     get_user_name( id, szName, charsmax( szName ) )
  318.     return szName
  319. }
  320.  
  321. /************* ColorChat ***************/
  322. stock ColorChat( const client, const string[ ], { Float, Sql, Resul, _ } :... )
  323. {
  324.     new msg[ 191 ], players[ 32 ], count = 1
  325.    
  326.     static len; len = formatex( msg, charsmax( msg ), "^3[^1 %s ^3]^1 ", Prefix )
  327.     vformat( msg[ len ], charsmax( msg ) - len, string, 3 )
  328.    
  329.     if( client )
  330.         players[ 0 ] = client
  331.     else
  332.         get_players( players, count, "ch" )
  333.    
  334.     for( new i; i < count; i++ )
  335.     {
  336.         if( is_user_connected( players[ i ] ) )
  337.         {
  338.             message_begin( MSG_ONE_UNRELIABLE, get_user_msgid( "SayText" ),_, players[ i ] )
  339.             write_byte( players[ i ] )
  340.             write_string( msg )
  341.             message_end()
  342.         }
  343.     }
  344.     return 1
  345. }
Add Comment
Please, Sign In to add comment