FoxHound

Ultimate Gate Include (UGI)

Mar 7th, 2011
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.19 KB | None | 0 0
  1. /*
  2.  *            ULTIMATE GATE INCLUDE 0.1
  3.  *       (c) Copyright 2010-2011 by FoxHound
  4.  *
  5.  * @author    : FoxHound aka PSPgamer_10
  6.  * @date      : 11 September 2010
  7.  *
  8.  * This file is provided as is (no warranties).
  9.  *
  10.  */
  11.  
  12. /*********** MAX. GATES ***********/
  13. #define     MAX_GATES       50      // The MAX Amount of Gates
  14. //         Max.  :  N/A
  15. //  Recommended  :  50
  16.  
  17. /********** DRAWDISTANCE **********/
  18. #define GATE_DRAWDISTANCE   100.0   // Drawdistance of the Gate-Objects
  19. //         Max.  :  300.0
  20. //  Recommended  :  100.0
  21.  
  22. /********* GATE ACTIVATION *********/
  23. #define  GATE_ACTIVATE_RANGE  5.0   // If the Player is nearer than X meters, the Gate will open and "OnGateOpen" Callback will be called
  24. //         Max.  :  N/A
  25. //  Recommended  :  5.0
  26.  
  27. /*********** CHECK-TIME ***********/
  28. #define  GATES_CHECKTIME    1000    // All x MiLiSECONDS, ALL avaible Gates will be checked.
  29.                                     // +> IMPORTANT:
  30.                                     //     Use this Carefully, 'cause this Number could make your Server Lagg.
  31.                                     //     The best way to escape the laggs is to hold the Number ON/OVER 1000 MS.
  32.  
  33. #define ToggleGateLockForPlayer(%0,%1,%2); new _UGI_togNumb=%2;if(_UGI_togNumb<=0){UGI_gateLockedStatus[%0][%1]=0;}else{UGI_gateLockedStatus[%0][%1]=1;}
  34. #define ToggleGateLockForAll(%0,%1); for(new p=0;p<MAX_PLAYERS;p++){new UGI_togNumb=%1;if(UGI_togNumb<=0){UGI_gateLockedStatus[p][%0]=0;}else{UGI_gateLockedStatus[p][%0]=1;}}
  35.  
  36. new UGI_delGateIdCount=0,UGI_delGateCreate[MAX_GATES]=0;
  37. new UGI_gateTimerStatus=0;
  38. new UGI_gateIdCount=0, UGI_gateObj[MAX_GATES]=0;
  39. new Float:UGI_gatePos[MAX_GATES][6], UGI_gateStatus[MAX_GATES];
  40. new UGI_gateLockedStatus[MAX_PLAYERS][MAX_GATES];
  41.  
  42. forward OnGateOpen(gateid, byplayerid);
  43. forward OnGateClose(gateid);
  44.  
  45. forward CreateGate(modelid, Float:closedX, Float:closedY, Float:closedZ, Float:openX, Float:openY, Float:openZ, Float:rX, Float:rY, Float:rZ);
  46. public  CreateGate(modelid, Float:closedX, Float:closedY, Float:closedZ, Float:openX, Float:openY, Float:openZ, Float:rX, Float:rY, Float:rZ)
  47. {
  48.     new UGI_creatingGateId,UGI_gateCreatedFromDeletedId=0;
  49.     if(!UGI_delGateIdCount) { UGI_creatingGateId=UGI_gateIdCount; UGI_gateCreatedFromDeletedId=0; }
  50.     else { for(new i=MAX_GATES;i>UGI_delGateIdCount;i++) { if(UGI_delGateCreate[i]==1) { UGI_creatingGateId = i; UGI_delGateIdCount-=1; UGI_delGateCreate[i]=0; UGI_gateCreatedFromDeletedId=1; break; } } }
  51.     if(UGI_creatingGateId==MAX_GATES) { printf("[UGI] Couldn't create Gate ID '%d': Set the MAX_GATES definition to a higher Value (Current value: %d)",UGI_creatingGateId,MAX_GATES); return 0; }
  52.     UGI_gateObj[UGI_creatingGateId] = CreateObject(modelid, closedX, closedY, closedZ, rX, rY, rZ, GATE_DRAWDISTANCE);
  53.     if(UGI_gateTimerStatus == 0) {
  54.         SetTimer("UGI_gateUpdate",GATES_CHECKTIME,true);
  55.         UGI_gateTimerStatus = 1; }
  56.     UGI_gatePos[UGI_creatingGateId][0] = closedX; UGI_gatePos[UGI_creatingGateId][1] = closedY; UGI_gatePos[UGI_creatingGateId][2] = closedZ;
  57.     UGI_gatePos[UGI_creatingGateId][3] = openX; UGI_gatePos[UGI_creatingGateId][4] = openY; UGI_gatePos[UGI_creatingGateId][5] = openZ;
  58.     UGI_gateStatus[UGI_creatingGateId]=0; UGI_creatingGateId += 1;
  59.     for(new p=0;p<MAX_PLAYERS;p++) { UGI_gateLockedStatus[p][UGI_creatingGateId-1] = 0; }
  60.     if(!UGI_gateCreatedFromDeletedId) { UGI_gateIdCount=UGI_creatingGateId; return UGI_creatingGateId-1; }
  61.     else { return UGI_creatingGateId; }
  62. }
  63.  
  64. forward IsGateLockedForPlayer(forplayerid, gateid);
  65. public IsGateLockedForPlayer(forplayerid, gateid)
  66. {
  67.     if(UGI_gateLockedStatus[forplayerid][gateid]==1) { return 1; }
  68.     return 0;
  69. }
  70.  
  71. forward DestroyGate(gateid);
  72. public  DestroyGate(gateid)
  73. {
  74.     UGI_delGateCreate[UGI_delGateIdCount]=1;
  75.     UGI_delGateIdCount+=1;
  76.     DestroyObject(UGI_gateObj[gateid]);
  77.     UGI_gateIdCount-=1;
  78.     return 1;
  79. }
  80.  
  81. forward UGI_gateUpdate();
  82. public UGI_gateUpdate()
  83. {
  84.     new UGI_isAnyoneOnline=0;
  85.     for(new p=0;p<MAX_PLAYERS;p++) { if(IsPlayerConnected(p)) { UGI_isAnyoneOnline=1; p=(MAX_PLAYERS-1); break; } }
  86.     if(UGI_isAnyoneOnline)
  87.     {
  88.         new UGI_noPersonFound=(MAX_GATES+1);
  89.         for(new g=0;g<UGI_gateIdCount;g++)
  90.         {
  91.             for(new p=0;p<MAX_PLAYERS;p++)
  92.             {
  93.                 if(IsPlayerConnected(p))
  94.                 {
  95.                     new Float:objX, Float:objY, Float:objZ;
  96.                     new Float:gateActivateRange = GATE_ACTIVATE_RANGE;
  97.                     GetObjectPos(UGI_gateObj[g],objX,objY,objZ);
  98.                     if(IsPlayerInAnyVehicle(p)) { gateActivateRange += 2.0; }
  99.                     if(IsPlayerInRangeOfPoint(p,gateActivateRange,objX,objY,objZ))
  100.                     {
  101.                         if(UGI_gateLockedStatus[p][g]==0)
  102.                         {
  103.                             if(UGI_gateStatus[g]==0)
  104.                             {
  105.                                 UGI_gateStatus[g]=1;
  106.                                 MoveObject(UGI_gateObj[g], UGI_gatePos[g][3], UGI_gatePos[g][4], UGI_gatePos[g][5], 3.0);
  107.                                 CallLocalFunction("OnGateOpen","dd",g,p);
  108.                             }
  109.                         }
  110.                     }
  111.                     if(!IsPlayerInRangeOfPoint(p,gateActivateRange,objX,objY,objZ))
  112.                     {
  113.                         if(UGI_gateStatus[g]==1)
  114.                         {
  115.                             UGI_noPersonFound=g;
  116.                         }
  117.                     }
  118.                 }
  119.             }
  120.         }
  121.         if(UGI_noPersonFound!=(MAX_GATES+1))
  122.         {
  123.             UGI_gateStatus[UGI_noPersonFound] = 0;
  124.             MoveObject(UGI_gateObj[UGI_noPersonFound], UGI_gatePos[UGI_noPersonFound][0], UGI_gatePos[UGI_noPersonFound][1], UGI_gatePos[UGI_noPersonFound][2], 3.0);
  125.             CallLocalFunction("OnGateClose","d",UGI_noPersonFound);
  126.             UGI_noPersonFound=(MAX_GATES+1);
  127.         }
  128.     }
  129.     return 0;
  130. }
Add Comment
Please, Sign In to add comment