Advertisement
Guest User

dEntrances by KarolisK

a guest
Dec 22nd, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.11 KB | None | 0 0
  1. /*
  2.  
  3.  
  4.             dynamicEntrances by KarolisK
  5.             ----------------------------
  6.                     2013-12-22
  7.  
  8.  
  9.  
  10. */
  11. #if !defined PRESSED
  12.     #define PRESSED(%0) \
  13.         (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
  14. #endif
  15.  
  16. #if !defined MAX_ENTRANCE_TEXT
  17.     #define MAX_ENTRANCE_TEXT       500
  18. #endif
  19.  
  20. #if !defined MAX_ENTRANCES
  21.     #define MAX_ENTRANCES           100
  22. #endif
  23.  
  24. #if !defined MAX_DRAW_DISTANCE
  25.     #define MAX_DRAW_DISTANCE       25.0
  26. #endif
  27.  
  28. #if !defined OBJECTS_CREATE_DELAY
  29.     #define OBJECTS_CREATE_DELAY    2000
  30. #endif
  31.  
  32. #if !defined KEY_TO_ENTER
  33.     #define KEY_TO_ENTER            KEY_SECONDARY_ATTACK
  34. #endif
  35.  
  36.  
  37.  
  38.  
  39. new createdEntrances = 1;
  40.  
  41. enum ENTRANCE_DATA
  42. {
  43.     e_ENTRANCE_ID,
  44.     e_ENTRANCE_TEXT[MAX_ENTRANCE_TEXT],
  45.     Float:e_ENTRANCE_POS_X,
  46.     Float:e_ENTRANCE_POS_Y,
  47.     Float:e_ENTRANCE_POS_Z,
  48.     Float:e_ENTRANCE_EXIT_POS_X,
  49.     Float:e_ENTRANCE_EXIT_POS_Y,
  50.     Float:e_ENTRANCE_EXIT_POS_Z,
  51.     e_INTERIOR,
  52.     Text3D:e_ENTRANCE_LABEL,
  53.     Text3D:e_ENTRANCE_EXIT_LABEL,
  54.     bool:destroyed
  55. }
  56.  
  57. new entrances[ MAX_ENTRANCES ][ ENTRANCE_DATA ];
  58.  
  59. stock CreateEntrance( e_entrance_string[], Float:e_entrance_pos_x, Float:e_entrance_pos_y, Float:e_entrance_pos_z, Float:e_entrance_exit_pos_x, Float:e_entrance_exit_pos_y, Float:e_entrance_exit_pos_z, e_interior )
  60. {
  61.     entrances[createdEntrances][e_ENTRANCE_ID] = createdEntrances;
  62.     format( entrances[createdEntrances][e_ENTRANCE_TEXT], MAX_ENTRANCE_TEXT, e_entrance_string );
  63.     entrances[createdEntrances][e_INTERIOR] = e_interior;
  64.     entrances[createdEntrances][destroyed] = false;
  65.     // iejimas
  66.     entrances[createdEntrances][e_ENTRANCE_POS_X] = e_entrance_pos_x;
  67.     entrances[createdEntrances][e_ENTRANCE_POS_Y] = e_entrance_pos_y;
  68.     entrances[createdEntrances][e_ENTRANCE_POS_Z] = e_entrance_pos_z;
  69.     // isejimas
  70.     entrances[createdEntrances][e_ENTRANCE_EXIT_POS_X] = e_entrance_exit_pos_x;
  71.     entrances[createdEntrances][e_ENTRANCE_EXIT_POS_Y] = e_entrance_exit_pos_y;
  72.     entrances[createdEntrances][e_ENTRANCE_EXIT_POS_Z] = e_entrance_exit_pos_z;
  73.     // 3dlabelis
  74.     entrances[createdEntrances][e_ENTRANCE_LABEL] = Create3DTextLabel(e_entrance_string, 0xFFFFFFFF,e_entrance_pos_x,e_entrance_pos_y, e_entrance_pos_z, MAX_DRAW_DISTANCE, 0);
  75.     entrances[createdEntrances][e_ENTRANCE_EXIT_LABEL]= Create3DTextLabel("Išėjimas", 0xFFFFFFFF,e_entrance_exit_pos_x, e_entrance_exit_pos_y, e_entrance_exit_pos_z, MAX_DRAW_DISTANCE, 0);
  76.     // else
  77.     printf( "[dynamicEntrances]: Iejimas pavadinimu %s sukurtas %f %f %f pozicijoje.",e_entrance_string,e_entrance_pos_x,e_entrance_pos_y, e_entrance_pos_z );
  78.     return entrances[createdEntrances][e_ENTRANCE_ID], createdEntrances++;
  79. }
  80.  
  81. stock entrances_init(playerid, newkeys, oldkeys)
  82. {
  83.     if (PRESSED( KEY_TO_ENTER ))
  84.     {
  85.         for( new e; e < MAX_ENTRANCES; e++)
  86.         {
  87.             if( !entrances[ e ][ destroyed ] )
  88.             {
  89.                
  90.                 if( IsPlayerInRangeOfPoint( playerid, 2, entrances[createdEntrances][e_ENTRANCE_POS_X],entrances[createdEntrances][e_ENTRANCE_POS_Y],entrances[createdEntrances][e_ENTRANCE_POS_Z] ))
  91.                 {
  92.                     if( GetPlayerInterior( playerid ) == 0)
  93.                     {
  94.                         #if defined LOAD_OBJECTS_ON_ENTER
  95.                             TogglePlayerControllable( playerid, false );
  96.                             GameTextForPlayer(playerid, "Kraunasi objektai...", OBJECTS_CREATE_DELAY, 5);
  97.                             SetTimerEx("dynamicLoadObjects", 3000, false, "i", playerid );
  98.                         #endif
  99.                         SetPlayerPos( playerid, entrances[createdEntrances][e_ENTRANCE_EXIT_POS_X],entrances[createdEntrances][e_ENTRANCE_EXIT_POS_Y],entrances[createdEntrances][e_ENTRANCE_EXIT_POS_Z] );
  100.                         SetPlayerInterior( playerid, entrances[createdEntrances][e_INTERIOR] );
  101.                     }
  102.                 }
  103.                 else if( IsPlayerInRangeOfPoint( playerid, 2, entrances[createdEntrances][e_ENTRANCE_EXIT_POS_X],entrances[createdEntrances][e_ENTRANCE_EXIT_POS_Y],entrances[createdEntrances][e_ENTRANCE_EXIT_POS_Z] ) )
  104.                 {
  105.                     if( GetPlayerInterior( playerid ) == entrances[createdEntrances][e_INTERIOR] )
  106.                     {
  107.                         #if defined LOAD_OBJECTS_ON_ENTER
  108.                             TogglePlayerControllable( playerid, false );
  109.                             GameTextForPlayer(playerid, "Kraunasi objektai...", OBJECTS_CREATE_DELAY, 5);
  110.                             SetTimerEx("dynamicLoadObjects", 3000, false, "i", playerid );
  111.                         #endif
  112.                         SetPlayerPos( playerid, entrances[createdEntrances][e_ENTRANCE_POS_X],entrances[createdEntrances][e_ENTRANCE_POS_Y],entrances[createdEntrances][e_ENTRANCE_POS_Z] );
  113.                         SetPlayerInterior( playerid, 0 );
  114.                     }
  115.                 }
  116.             }
  117.         }
  118.     }
  119.     return 1;
  120. }
  121.  
  122. stock DestroyEntrance( entranceid )
  123. {
  124.     Delete3DTextLabel( entrances[ entranceid ][ e_ENTRANCE_LABEL ] );
  125.     Delete3DTextLabel( entrances[ entranceid ][ e_ENTRANCE_EXIT_LABEL ] );
  126.     entrances[ entranceid ][ destroyed ] = true;
  127.     return printf("[dynamicEntrances]: %i iejimas sunaikintas!", entranceid ), 1;
  128. }
  129.  
  130. stock UpdateEntranceText( entranceid, _text[] )
  131. {
  132.     Update3DTextLabelText( entrances[ entranceid ][ e_ENTRANCE_LABEL ], 0xFFFFFFFF, _text);
  133.     return printf("[dynamicEntrances]: %i iejimo tekstas atnaujintas!", entranceid ), 1;
  134. }
  135.  
  136. #if defined LOAD_OBJECTS_ON_ENTER
  137. forward dynamicLoadObjects(playerid);
  138. public dynamicLoadObjects( playerid )
  139. {
  140.     TogglePlayerControllable(playerid, true);
  141. }
  142. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement