Advertisement
RanAway

[ Pawn ] Teleport menu

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