Advertisement
Lorenc

Enter Exits - Include

Aug 26th, 2011
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.99 KB | None | 0 0
  1. /*
  2.  *      Enter Exit entrys (Server Side) [INC]
  3.  *
  4.  *          Uses: foreach; streamer; a_samp
  5.  *          codename: a_enterexits.inc
  6.  *
  7.  *      Created by Lorenc (c)
  8. */
  9.  
  10. #include                        <a_samp>
  11. #tryinclude                     <foreach>
  12. #tryinclude                     <streamer>
  13.  
  14. #define FILE_VERSION            "1.0"
  15.  
  16. /* FIXES BY LORENC!!!! */
  17. #if !defined foreach
  18.     #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  19.     #define __SSCANF_FOREACH__
  20. #endif
  21.  
  22. #if !defined _streamer_included
  23. stock CreateDynamicObject(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz, worldid, interiorid, playerid, Float:distance)
  24. {
  25.     #pragma unused worldid
  26.     #pragma unused interiorid
  27.     #pragma unused playerid
  28.     return CreateObject(modelid, x, y, z, rx, ry, rz, distance);
  29. }
  30. stock IsValidDynamicObject(objectid) return IsValidObject(objectid);
  31. stock MoveDynamicObject(objectid, Float: x, Float: y, Float: z, Float: speed) return MoveObject(objectid, x, y, z, speed);
  32. #define _streamer_included
  33. #endif
  34.  
  35. /* ** Configuration ** */
  36. #define POINT_UPDATE_TICKRATE   1000    //DEFAULT
  37.  
  38. #define MAX_POINTS              15
  39. #define MAX_P_STR               24
  40.  
  41. #define function%1(%2)          forward %1(%2); public%1(%2)
  42.  
  43. /* ** Player Data ** */
  44.  
  45. enum P_DATA
  46. {
  47.     Float: P_LOCATION_X,
  48.     Float: P_LOCATION_Y,
  49.     Float: P_LOCATION_Z,
  50.    
  51.     P_OBJECT,
  52.     P_TAG                       [ MAX_P_STR ],
  53.    
  54.     bool: P_UP,
  55.     bool: P_CREATED,
  56. }
  57.  
  58. static
  59.     gPointData                  [ MAX_POINTS ][ P_DATA ],
  60.     cp_Count = -1,
  61.    
  62.     bool: g_Spawned             [ MAX_PLAYERS ],
  63.     bool: g_Entered             [ MAX_PLAYERS ]
  64. ;
  65.  
  66. /*
  67.     native CreateDynamicPoint(&id, tag[], Float: x, Float: y, Float: z)
  68.     native IsValidPoint(pointid)
  69.     native DestroyDynamicPoint(pointid)
  70.     native GetPointTag(pointid)
  71.     native GetTotalPoints()
  72. */
  73.  
  74. forward OnPlayerEnterPoint(playerid, pointid);
  75. forward OnPlayerLeavePoint(playerid, pointid);
  76.  
  77. stock GetTotalPoints() return cp_Count;
  78.  
  79. stock IsValidPoint(pointid)
  80. {
  81.     if(gPointData[ pointid ][ P_CREATED ] == true)
  82.         return true;
  83.     else
  84.         return false;
  85. }
  86.  
  87. stock DestroyDynamicPoint(pointid)
  88. {
  89.     if(IsValidPoint(pointid))
  90.     {
  91.         DestroyDynamicObject(gPointData[ cp_Count ][ P_OBJECT ]);  
  92.         gPointData[ cp_Count ][ P_CREATED ] = false;
  93.     }
  94. }
  95.  
  96. stock GetPointTag(pointid)
  97. {
  98.     new tag[ MAX_P_STR ] = "Invalid Point Tag";
  99.     if(IsValidPoint(pointid)) format(tag, sizeof(tag), "%s", gPointData[ cp_Count ][ P_TAG ]);
  100.     return tag;
  101. }
  102.  
  103. stock CreateDynamicPoint(&id, tag[], Float: x, Float: y, Float: z)
  104. {
  105.     if(cp_Count > MAX_POINTS) return print("Cannot create anymore points..."), 0;
  106.    
  107.     cp_Count++;
  108.    
  109.     id = ( cp_Count );
  110.  
  111.     gPointData[ cp_Count ][ P_LOCATION_X ] = x;
  112.     gPointData[ cp_Count ][ P_LOCATION_Y ] = y;
  113.     gPointData[ cp_Count ][ P_LOCATION_Z ] = z + 1.0;
  114.     gPointData[ cp_Count ][ P_CREATED ] = true;
  115.    
  116.     format(gPointData[ cp_Count ][ P_TAG ], MAX_P_STR, "%s", tag);
  117.  
  118.     gPointData[ cp_Count ][ P_OBJECT ] = CreateDynamicObject(1559, gPointData[ cp_Count ][ P_LOCATION_X ], gPointData[ cp_Count ][ P_LOCATION_Y ], gPointData[ cp_Count ][ P_LOCATION_Z ], 0, 0, 0, -1, -1, -1, 200.0);
  119.     return 1;
  120. }
  121.  
  122. #if defined FILTERSCRIPT
  123.  
  124. public OnFilterScriptInit()
  125. {
  126.     print("\nThis server is using EnterExits by Lorenc - FILE VERSION ( "#FILE_VERSION" )\n");
  127.     SetTimer("PointUpdate", POINT_UPDATE_TICKRATE, true);
  128.     return CallLocalFunction("enex_OnFilterScriptInit", "");
  129. }
  130. #if defined _ALS_OnFilterScriptInit
  131.     #undef OnFilterScriptInit
  132. #else
  133.     #define _ALS_OnFilterScriptInit
  134. #endif
  135.  
  136. #define OnFilterScriptInit enex_OnFilterScriptInit
  137. forward enex_OnFilterScriptInit(playerid);
  138.  
  139. #else
  140. public OnGameModeInit()
  141. {
  142.     print("\nThis server is using EnterExits by Lorenc - FILE VERSION ( "#FILE_VERSION" )\n");
  143.     SetTimer("PointUpdate", POINT_UPDATE_TICKRATE, true);
  144.     return CallLocalFunction("enex_OnGameModeInit", "");
  145. }
  146. #if defined _ALS_OnGameModeInit
  147.     #undef OnGameModeInit
  148. #else
  149.     #define _ALS_OnGameModeInit
  150. #endif
  151.  
  152. #define OnGameModeInit enex_OnGameModeInit
  153. forward enex_OnGameModeInit(playerid);
  154.  
  155. #endif
  156.  
  157. function PointUpdate()
  158. {
  159.     foreach(Player, playerid)
  160.     {
  161.         if(!IsPlayerConnected(playerid)) continue;
  162.         if(g_Spawned[playerid] == true)
  163.         {
  164.             for(new point; point < MAX_POINTS; point++)
  165.             {
  166.                 if(!IsValidPoint(point)) continue;
  167.                
  168.                 if(IsValidDynamicObject(gPointData[ point ][ P_OBJECT ]))
  169.                 {
  170.                     if(gPointData[point][P_UP] == true)
  171.                         MoveDynamicObject(gPointData[ point ][ P_OBJECT ], gPointData[ point ][ P_LOCATION_X ], gPointData[ point ][ P_LOCATION_Y ], gPointData[ point ][ P_LOCATION_Z ] - 0.2, 0.9), gPointData[ point ][ P_UP ] = false;
  172.                     else
  173.                         MoveDynamicObject(gPointData[ point ][ P_OBJECT ], gPointData[ point ][ P_LOCATION_X ], gPointData[ point ][ P_LOCATION_Y ], gPointData[ point ][ P_LOCATION_Z ] + 0.4, 0.9), gPointData[ point ][ P_UP ] = true;
  174.                 }
  175.  
  176.                 if(IsPlayerInRangeOfPoint(playerid, 1.0, gPointData[ point ][ P_LOCATION_X ], gPointData[ point ][ P_LOCATION_Y ], gPointData[ point ][ P_LOCATION_Z ] - 1.0) && !GetPVarInt(playerid, "EnteredPoint") && g_Entered[ playerid ] == false)
  177.                 {
  178.                     SetPVarInt(playerid, "EnteredPoint", point);
  179.                     CallLocalFunction("OnPlayerEnterPoint", "dd", playerid, point);
  180.                     g_Entered[playerid] = true;
  181.                     continue;
  182.                 }
  183.                 else if(!IsPlayerInRangeOfPoint(playerid, 1.0, gPointData[ point ][ P_LOCATION_X ], gPointData[ point ][ P_LOCATION_Y ], gPointData[ point ][ P_LOCATION_Z ] - 1.0) && GetPVarInt(playerid, "EnteredPoint") == point && g_Entered[ playerid ] == true)
  184.                 {
  185.                     CallLocalFunction("OnPlayerLeavePoint", "dd", playerid, GetPVarInt(playerid, "EnteredPoint"));
  186.                     DeletePVar(playerid, "EnteredPoint");
  187.                     g_Entered[playerid] = false;
  188.                     continue;
  189.                 }
  190.             }
  191.         }
  192.     }
  193. }
  194.  
  195. public OnPlayerDeath(playerid, killerid, reason)
  196. {
  197.     g_Spawned[ playerid ] = false;
  198.     return CallLocalFunction("enex_OnPlayerDeath", "ddd", playerid, killerid, reason);
  199. }
  200.  
  201. #if defined _ALS_OnPlayerDeath
  202.     #undef OnPlayerDeath
  203. #else
  204.     #define _ALS_OnPlayerDeath
  205. #endif
  206.  
  207. #define OnPlayerDeath enex_OnPlayerDeath
  208. forward enex_OnPlayerDeath(playerid, killerid, reason);
  209.  
  210. public OnPlayerSpawn(playerid)
  211. {
  212.     g_Spawned[ playerid ] = true;
  213.     return CallLocalFunction("enex_OnPlayerSpawn", "d", playerid);
  214. }
  215.  
  216. #if defined _ALS_OnPlayerSpawn
  217.     #undef OnPlayerSpawn
  218. #else
  219.     #define _ALS_OnPlayerSpawn
  220. #endif
  221.  
  222. #define OnPlayerSpawn enex_OnPlayerSpawn
  223. forward enex_OnPlayerSpawn(playerid);
  224.  
  225. public OnPlayerDisconnect(playerid, reason)
  226. {
  227.     g_Spawned[ playerid ] = false;
  228.     g_Entered[ playerid ] = false;
  229.     return CallLocalFunction("enex_OnPlayerDisconnect", "dd", playerid, reason);
  230. }
  231.  
  232. #if defined _ALS_OnPlayerDisconnect
  233.     #undef OnPlayerDisconnect
  234. #else
  235.     #define _ALS_OnPlayerDisconnect
  236. #endif
  237.  
  238. #define OnPlayerDisconnect enex_OnPlayerDisconnect
  239. forward enex_OnPlayerDisconnect(playerid, reason);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement