Advertisement
Guest User

entrance.inc

a guest
May 10th, 2018
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.93 KB | None | 0 0
  1. #if defined _entrance_included
  2.     #endinput
  3. #endif
  4.  
  5. #if !defined _streamer_included
  6.     #tryinclude <streamer>
  7.     #if !defined _streamer_included
  8.         #error You must have Streamer include in order to use this one.
  9.     #endif
  10. #endif
  11.  
  12. #define _entrance_included
  13.  
  14. #if !defined MAX_ENTRANCES
  15.     #define MAX_ENTRANCES (Entrance:50)
  16. #endif
  17.  
  18. #if !defined MAX_ENTRANCE_NAME
  19.     #define MAX_ENTRANCE_NAME (32)
  20. #endif
  21.  
  22. #define INVALID_ENTRANCE (Entrance:-1)
  23.  
  24. enum E_ENTRANCE_DATA
  25. {
  26.     E_ENTRANCE_NAME[MAX_ENTRANCE_NAME],
  27.     Float:E_ENTRANCE_OUT_X,
  28.     Float:E_ENTRANCE_OUT_Y,
  29.     Float:E_ENTRANCE_OUT_Z,
  30.     Float:E_ENTRANCE_OUT_A,
  31.     E_ENTRANCE_OUT_I,
  32.     E_ENTRANCE_OUT_V,
  33.     Float:E_ENTRANCE_IN_X,
  34.     Float:E_ENTRANCE_IN_Y,
  35.     Float:E_ENTRANCE_IN_Z,
  36.     Float:E_ENTRANCE_IN_A,
  37.     E_ENTRANCE_IN_I,
  38.     E_ENTRANCE_IN_V,
  39.     Text3D:E_ENTRANCE_OUT_LBL,
  40.     Text3D:E_ENTRANCE_IN_LBL
  41. }
  42.  
  43. static
  44.     gEntranceData[MAX_ENTRANCES][E_ENTRANCE_DATA],
  45.     Entrance:gTotalEntrances;
  46.  
  47. forward OnPlayerEnterEntrance(playerid, Entrance:entranceid);
  48. forward OnPlayerExitEntrance(playerid, Entrance:entranceid);
  49.  
  50. // ------------------------------------------------------------------------------------
  51.  
  52. stock Entrance:CreateEntrance(name[], Float:out_x, Float:out_y, Float:out_z, Float:out_a, out_i, out_v, Float:in_x, Float:in_y, Float:in_z, Float:in_a, in_i, in_v)
  53. {
  54.     if (gTotalEntrances >= MAX_ENTRANCES)
  55.         return INVALID_ENTRANCE;
  56.  
  57.     strcat(gEntranceData[gTotalEntrances][E_ENTRANCE_NAME], name);
  58.     gEntranceData[gTotalEntrances][E_ENTRANCE_OUT_X] = out_x;
  59.     gEntranceData[gTotalEntrances][E_ENTRANCE_OUT_Y] = out_y;
  60.     gEntranceData[gTotalEntrances][E_ENTRANCE_OUT_Z] = out_z;
  61.     gEntranceData[gTotalEntrances][E_ENTRANCE_OUT_A] = out_a;
  62.     gEntranceData[gTotalEntrances][E_ENTRANCE_OUT_I] = out_i;
  63.     gEntranceData[gTotalEntrances][E_ENTRANCE_OUT_V] = out_v;
  64.     gEntranceData[gTotalEntrances][E_ENTRANCE_IN_X] = in_x;
  65.     gEntranceData[gTotalEntrances][E_ENTRANCE_IN_Y] = in_y;
  66.     gEntranceData[gTotalEntrances][E_ENTRANCE_IN_Z] = in_z;
  67.     gEntranceData[gTotalEntrances][E_ENTRANCE_IN_A] = in_a;
  68.     gEntranceData[gTotalEntrances][E_ENTRANCE_IN_I] = in_i;
  69.     gEntranceData[gTotalEntrances][E_ENTRANCE_IN_V] = in_v;
  70.  
  71.     gEntranceData[gTotalEntrances][E_ENTRANCE_OUT_LBL] = CreateDynamic3DTextLabel(name, 0xFFD9D7FF, out_x, out_y, out_z - 0.5, 10.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, out_v, out_i);
  72.     gEntranceData[gTotalEntrances][E_ENTRANCE_IN_LBL] = CreateDynamic3DTextLabel("Exit", 0xFFD9D7FF, in_x, in_y, in_z - 0.5, 10.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, in_v, in_i);
  73.     return gTotalEntrances ++;
  74. }
  75.  
  76. // ------------------------------------------------------------------------------------
  77.  
  78. stock GetEntranceName(Entrance:index, name[], length = sizeof(name))
  79. {
  80.     name[0] = EOS;
  81.  
  82.     strcat(name, gEntranceData[index][E_ENTRANCE_NAME], length);
  83. }
  84.  
  85. // ------------------------------------------------------------------------------------
  86.  
  87. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  88. {
  89.     if ((newkeys & KEY_SECONDARY_ATTACK))
  90.     {
  91.         for (new Entrance:i; i < gTotalEntrances; i ++)
  92.         {
  93.             if (IsPlayerInRangeOfEntrance(playerid, i))
  94.             {
  95.                 if (OnPlayerEnterEntrance(playerid, i) != 0)
  96.                 {
  97.                     SetPlayerPos(playerid, gEntranceData[i][E_ENTRANCE_IN_X], gEntranceData[i][E_ENTRANCE_IN_Y], gEntranceData[i][E_ENTRANCE_IN_Z]);
  98.                     SetPlayerFacingAngle(playerid, gEntranceData[i][E_ENTRANCE_IN_A]);
  99.                     SetPlayerInterior(playerid, gEntranceData[i][E_ENTRANCE_IN_I]);
  100.                     SetPlayerVirtualWorld(playerid, gEntranceData[i][E_ENTRANCE_IN_V]);
  101.                     SetCameraBehindPlayer(playerid);
  102.                 }
  103.             }
  104.             else if (IsPlayerInEntrance(playerid, i, 3.0))
  105.             {
  106.                 if (OnPlayerExitEntrance(playerid, i) != 0)
  107.                 {
  108.                     SetPlayerPos(playerid, gEntranceData[i][E_ENTRANCE_OUT_X], gEntranceData[i][E_ENTRANCE_OUT_Y], gEntranceData[i][E_ENTRANCE_OUT_Z]);
  109.                     SetPlayerFacingAngle(playerid, gEntranceData[i][E_ENTRANCE_OUT_A]);
  110.                     SetPlayerInterior(playerid, gEntranceData[i][E_ENTRANCE_OUT_I]);
  111.                     SetPlayerVirtualWorld(playerid, gEntranceData[i][E_ENTRANCE_OUT_V]);
  112.                     SetCameraBehindPlayer(playerid);
  113.                 }
  114.             }
  115.         }
  116.     }
  117.     #if defined inc_Ent_OnPlayerKeyStateChange
  118.         return inc_Ent_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
  119.     #else
  120.         return 0;
  121.     #endif
  122. }
  123. #if defined _ALS_OnPlayerKeyStateChange
  124.     #undef OnPlayerKeyStateChange
  125. #else
  126.     #define _ALS_OnPlayerKeyStateChange
  127. #endif
  128.  
  129. #define OnPlayerKeyStateChange inc_Ent_OnPlayerKeyStateChange
  130. #if defined inc_Ent_OnPlayerKeyStateChange
  131.     forward inc_Ent_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
  132. #endif
  133.  
  134. // ------------------------------------------------------------------------------------
  135.  
  136. stock IsPlayerInRangeOfEntrance(playerid, Entrance:index, Float:range = 3.0)
  137.     return (IsPlayerInRangeOfPoint(playerid, range, gEntranceData[index][E_ENTRANCE_OUT_X], gEntranceData[index][E_ENTRANCE_OUT_Y], gEntranceData[index][E_ENTRANCE_OUT_Z]) ? true : false);
  138.  
  139. // ------------------------------------------------------------------------------------
  140.  
  141. stock IsPlayerInEntrance(playerid, Entrance:index, Float:range = 20.0)
  142.     return ((IsPlayerInRangeOfPoint(playerid, range, gEntranceData[index][E_ENTRANCE_IN_X], gEntranceData[index][E_ENTRANCE_IN_Y], gEntranceData[index][E_ENTRANCE_IN_Z]) && GetPlayerVirtualWorld(playerid) == gEntranceData[index][E_ENTRANCE_IN_V]) ? true : false);
  143.  
  144. // ------------------------------------------------------------------------------------
  145.  
  146. stock GetPlayerClosestEntranceID(playerid, Float:range = 3.0)
  147. {
  148.     new Entrance:index = INVALID_ENTRANCE, Float:dist = range, Float:tempdist;
  149.  
  150.     for (new Entrance:i; i < gTotalEntrances; i ++)
  151.     {
  152.         tempdist = GetPlayerDistanceFromPoint(playerid, gEntranceData[i][E_ENTRANCE_OUT_X], gEntranceData[i][E_ENTRANCE_OUT_Y], gEntranceData[i][E_ENTRANCE_OUT_Z]);
  153.  
  154.         if (tempdist > range)
  155.             continue;
  156.  
  157.         if (tempdist <= dist)
  158.         {
  159.             dist = tempdist;
  160.             index = i;
  161.         }
  162.     }
  163.     return _:index;
  164. }
  165.  
  166. // ------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement