Advertisement
Gigi_Falcone

doors.inc

Jan 11th, 2016
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.88 KB | None | 0 0
  1. /*
  2.     Made by: Gigi_Falcone (http://forum.sa-mp.com/member.php?u=76822)
  3.     forum.sa-mp.com
  4.     11.01.2016
  5.     Version: v0.1 Alpha
  6. */
  7.  
  8. #include <a_samp>
  9. #include <streamer>
  10.  
  11. #define DS_MAX_DOORS   10
  12. #define DS_DOOR_NONE    0
  13. #define DS_DOOR_CLOSE   1
  14. #define DS_DOOR_OPEN    2
  15.  
  16.  
  17. #define DS_DEBUG
  18.  
  19. enum doors_data
  20. {
  21.     bool:ds_used,
  22.     ds_streamerid,
  23.     ds_areaid,
  24.     ds_model,
  25.     ds_state,//closed or open
  26.     Float:ds_x,
  27.     Float:ds_y,
  28.     Float:ds_z,
  29.     Float:ds_rx,
  30.     Float:ds_ry,
  31.     Float:ds_rz,
  32.     //debug objects
  33.     #if defined DS_DEBUG
  34.     ds_debug1,
  35.     ds_debug2,
  36.     ds_debug3,
  37.     ds_debug4
  38.     #endif
  39. }
  40. static DoorsData[DS_MAX_DOORS + 1][doors_data];//slot 0 not used - invalid
  41.  
  42. //Returns ID from 1 to 100, not including 0
  43. stock CreateDoor(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz)
  44. {
  45.     //== Find Empty Slot
  46.     static slot = 0;
  47.     for(new i = 1; i < sizeof(DoorsData); i++)//Loop array to find empty spot
  48.     {
  49.         if(DoorsData[i][ds_used] == false)//Check if slot is used
  50.         {
  51.             slot = i;
  52.             break;
  53.         }
  54.     }
  55.     if(!slot) return 0;//Doors could not be created! Max limit reached
  56.    
  57.     //== Find Coordinates For Area
  58.     static Float:tx;
  59.     static Float:ty;
  60.  
  61.     static Float:tAreaCoord[8];//x,y,x,y,...
  62.  
  63.     //bottom left
  64.     tx = x;
  65.     ty = y;
  66.     GetPosInFrontOfPoint(tx,ty, rz + 180.0, 1.5);
  67.     tAreaCoord[0] = tx;
  68.     tAreaCoord[1] = ty;
  69.     #if defined DS_DEBUG
  70.     DoorsData[slot][ds_debug1] = CreateDynamicObject(1455,tx,ty,z,rx,ry,rz);
  71.     #endif
  72.  
  73.     //top left
  74.     tx = x;
  75.     ty = y;
  76.     GetPosInFrontOfPoint(tx,ty, rz, 1.5);
  77.     tAreaCoord[2] = tx;
  78.     tAreaCoord[3] = ty;
  79.     #if defined DS_DEBUG
  80.     DoorsData[slot][ds_debug2] = CreateDynamicObject(1455,tx,ty,z,rx,ry,rz);
  81.     #endif
  82.     //top right
  83.     tx = x;
  84.     ty = y;
  85.     GetPosInFrontOfPoint(tx,ty, rz + 270.0, 1.5);
  86.     GetPosInFrontOfPoint(tx,ty, rz, 1.5);
  87.     tAreaCoord[4] = tx;
  88.     tAreaCoord[5] = ty;
  89.     #if defined DS_DEBUG
  90.     DoorsData[slot][ds_debug3] = CreateDynamicObject(1455,tx,ty,z,rx,ry,rz);
  91.     #endif
  92.     //bottom right
  93.     tx = x;
  94.     ty = y;
  95.     GetPosInFrontOfPoint(tx,ty, rz + 270.0, 1.5);
  96.     GetPosInFrontOfPoint(tx,ty, rz + 180, 1.5);
  97.     tAreaCoord[6] = tx;
  98.     tAreaCoord[7] = ty;
  99.     #if defined DS_DEBUG
  100.     DoorsData[slot][ds_debug4] = CreateDynamicObject(1455,tx,ty,z,rx,ry,rz);
  101.     #endif
  102.    
  103.     //== Set Variables
  104.     DoorsData[slot][ds_used] = true;
  105.     DoorsData[slot][ds_streamerid] = CreateDynamicObject(modelid,x,y,z,rx,ry,rz);
  106.     DoorsData[slot][ds_areaid] = CreateDynamicPolygon(tAreaCoord);
  107.     DoorsData[slot][ds_model] = modelid;
  108.     DoorsData[slot][ds_state] = DS_DOOR_CLOSE;
  109.     DoorsData[slot][ds_x] = x;
  110.     DoorsData[slot][ds_y] = y;
  111.     DoorsData[slot][ds_z] = z;
  112.     DoorsData[slot][ds_rx] = rx;
  113.     DoorsData[slot][ds_ry] = ry;
  114.     DoorsData[slot][ds_rz] = rz;
  115.  
  116.     SendClientMessage(0,-1,"created door");
  117.     return slot;
  118. }
  119.  
  120.  
  121. stock DestroyDoor(doorid)
  122. {
  123.     if(!DoorsData[doorid][ds_used]) return 0;//Door invalid
  124.     DoorsData[doorid][ds_used] = false;
  125.     if(IsValidDynamicObject(DoorsData[doorid][ds_streamerid])) DestroyDynamicObject(DoorsData[doorid][ds_streamerid]);
  126.     DoorsData[doorid][ds_streamerid] = 0;
  127.     if(IsValidDynamicArea(DoorsData[doorid][ds_areaid])) DestroyDynamicArea(DoorsData[doorid][ds_areaid]);
  128.     DoorsData[doorid][ds_areaid] = 0;
  129.     DoorsData[doorid][ds_model] = 0;
  130.     DoorsData[doorid][ds_state] = DS_DOOR_NONE;
  131.     DoorsData[doorid][ds_x] = 0.0;
  132.     DoorsData[doorid][ds_y] = 0.0;
  133.     DoorsData[doorid][ds_z] = 0.0;
  134.     DoorsData[doorid][ds_rx] = 0.0;
  135.     DoorsData[doorid][ds_ry] = 0.0;
  136.     DoorsData[doorid][ds_rz] = 0.0;
  137.     #if defined DS_DEBUG
  138.     if(IsValidDynamicObject(DoorsData[doorid][ds_debug1])) DestroyDynamicObject(DoorsData[doorid][ds_debug1]);
  139.     if(IsValidDynamicObject(DoorsData[doorid][ds_debug2])) DestroyDynamicObject(DoorsData[doorid][ds_debug2]);
  140.     if(IsValidDynamicObject(DoorsData[doorid][ds_debug3])) DestroyDynamicObject(DoorsData[doorid][ds_debug3]);
  141.     if(IsValidDynamicObject(DoorsData[doorid][ds_debug4])) DestroyDynamicObject(DoorsData[doorid][ds_debug4]);
  142.     #endif
  143.     return 1;
  144. }
  145.  
  146. //Slow open/close speed: 0.01 to 0.001
  147. stock MoveDoor(doorid, doorstate, Float:speed = 1.0)//open/close
  148. {
  149.     if(!DoorsData[doorid][ds_used]) return 0;//If door does not exist, return 0
  150.     if(DoorsData[doorid][ds_state] == doorstate) return 0;//If door state is same, return 0
  151.     switch(doorstate)
  152.     {
  153.         case DS_DOOR_CLOSE://Close the door
  154.         {
  155.             DoorsData[doorid][ds_state] = DS_DOOR_CLOSE;
  156.             MoveDynamicObject(DoorsData[doorid][ds_streamerid],
  157.             DoorsData[doorid][ds_x],
  158.             DoorsData[doorid][ds_y],
  159.             DoorsData[doorid][ds_z] + 0.01,
  160.             speed,
  161.             -1000.0,
  162.             -1000.0,
  163.             DoorsData[doorid][ds_rz]);
  164.         }
  165.         case DS_DOOR_OPEN://Open the door
  166.         {
  167.             DoorsData[doorid][ds_state] = DS_DOOR_OPEN;
  168.             MoveDynamicObject(DoorsData[doorid][ds_streamerid],
  169.             DoorsData[doorid][ds_x],
  170.             DoorsData[doorid][ds_y],
  171.             DoorsData[doorid][ds_z] - 0.01,
  172.             speed,
  173.             -1000.0,
  174.             -1000.0,
  175.             DoorsData[doorid][ds_rz] - 90.0);
  176.         }
  177.         default: return 0;
  178.     }
  179.     return 1;
  180. }
  181.  
  182. stock IsPlayerInDoorZone(playerid, doorid)//1 yes, 0 no
  183. {
  184.     if(!DoorsData[doorid][ds_used]) return 0;//If door does not exist, return 0
  185.     if(IsPlayerInDynamicArea(playerid,DoorsData[doorid][ds_areaid])) return 1;
  186.     else return 0;
  187. }
  188.  
  189. stock IsPlayerInAnyDoorZone(playerid)//id yes, 0 no
  190. {
  191.     static doorid = 0;
  192.     for(new i = 1; i < sizeof(DoorsData); i++)
  193.     {
  194.         if(!DoorsData[i][ds_used]) continue;//dor does not exist
  195.         if(IsPlayerInDynamicArea(playerid,DoorsData[i][ds_areaid]))
  196.         {
  197.             doorid = i;
  198.             break;
  199.         }
  200.     }
  201.     return doorid;
  202. }
  203.  
  204.  
  205. //Input X & Y coordinates, angle & distance
  206. //Return X & Y coordinates changed for the offset
  207. stock GetPosInFrontOfPoint(&Float:OutputX, &Float:OutputY, Float:Angle, Float:Distance)
  208. {
  209.     if(!Distance) return 0;
  210.     OutputX += floatmul(Distance, floatsin(-Angle, degrees));
  211.     OutputY += floatmul(Distance, floatcos(-Angle, degrees));
  212.     return 1;
  213. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement