Advertisement
bruno_travi

Smoke13.inc

Dec 18th, 2014
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.36 KB | None | 0 0
  1. /*   
  2.      ######  ##     ##  #######  ##    ## ########    ##    #######  V. 0.2a
  3.     ##    ## ###   ### ##     ## ##   ##  ##        ####   ##     ## 18/12/14
  4.     ##       #### #### ##     ## ##  ##   ##          ##          ##
  5.      ######  ## ### ## ##     ## #####    ######      ##    #######
  6.           ## ##     ## ##     ## ##  ##   ##          ##          ##
  7.     ##    ## ##     ## ##     ## ##   ##  ##          ##   ##     ##
  8.      ######  ##     ##  #######  ##    ## ########  ######  #######
  9.     by Bruno13
  10.    
  11.     Thanks:
  12.         - Y_Less.
  13.         - SA-MP Team.
  14.  
  15.     FUNCTIONS:
  16.         - CreateSmoke(Float:x, Float:y, Float:z, type, time = -1);
  17.             return: Smoke ID criada. -1 caso Smoke não for criado com sucesso.
  18.            
  19.         - DestroySmoke(smokeid);
  20.             return: 1 caso for deletado com sucesso, 0 caso não for.
  21.            
  22.         - ResetSmokes();
  23.             return: Não tem retornos.
  24.            
  25.         - FreeSmokes();
  26.             return: Total de Smoke Slots livres.
  27.  
  28.     CALLBACKS:
  29.         - IsPlayerInSmoke(playerid, smokeid, smoketype);
  30.             * É chamada quando um player está próximo/sobre uma Smoke, especificando
  31.               smokeid e smoketype referente a mesma.
  32. */
  33.  
  34. //===================================[YSI <3]===================================
  35. #include <YSI\y_hooks>
  36. //===============================[DEFINES/MACROS]===============================
  37. #define MAX_SMOKES 50
  38.  
  39. #define callback::%0(%1) forward %0(%1); public %0(%1)
  40. //==================================[VARIÁBLES]=================================
  41. new SmokeID[MAX_SMOKES];
  42. new SmokeSlot[MAX_OBJECTS];
  43. new Float:SmokePos[MAX_SMOKES][3];
  44. new SmokeType[MAX_SMOKES];
  45. new bool:FirstSpawn_SM[MAX_PLAYERS];
  46. //==================================[STOCKS's]==================================
  47. stock CreateSmoke(Float:x, Float:y, Float:z, type, time = -1)
  48. {
  49.     new id = SmokeEmpty();
  50.     if(id == -1)
  51.     {
  52.         printf("%s", SmokeError(0));
  53.         return -1;
  54.     }
  55.     switch(type)
  56.     {
  57.         case 0: type = 18703;
  58.         case 1: type = 18704;
  59.         case 2: type = 18710;
  60.         case 3: type = 18713;
  61.         case 4: type = 18714;
  62.         case 5: type = 18715;
  63.         case 6: type = 18716;
  64.         case 7: type = 18725;
  65.         case 8: type = 18726;
  66.         case 9: type = 18727;
  67.         case 10: type = 18731;
  68.         case 11: type = 18735;
  69.         default:
  70.         {
  71.             printf("%s", SmokeError(1));
  72.             return -1;
  73.         }
  74.     }
  75.     if(time < -1)
  76.     {
  77.         printf("%s", SmokeError(2));
  78.         return -1;
  79.     }
  80.    
  81.     SmokeID[id] = CreateObject(type, x, y, z, 0.0, 0.0, 0.0);
  82.     SmokeSlot[SmokeID[id]] = id;
  83.     SmokePos[SmokeID[id]][0] = x;
  84.     SmokePos[SmokeID[id]][1] = y;
  85.     SmokePos[SmokeID[id]][2] = z;
  86.     SmokeType[SmokeID[id]] = type;
  87.  
  88.     if(time != -1) SetTimerEx("DestroySmoke", time*1000, false, "d", SmokeID[id]);
  89.    
  90.     return SmokeID[id];
  91. }
  92.  
  93. stock ResetSmokes()
  94. {
  95.     for(new i; i < MAX_OBJECTS; i++)
  96.     {
  97.         SmokeSlot[i] = -1;
  98.        
  99.         if(i >= MAX_SMOKES) continue;
  100.        
  101.         if(SmokeID[i] != -1) DestroyObject(SmokeID[i]);
  102.         SmokeID[i] = -1;
  103.         SmokeType[i] = -1;
  104.     }
  105. }
  106.  
  107. stock FreeSmokes()
  108. {
  109.     new a;
  110.     for(new i; i < MAX_SMOKES; i++)
  111.     {
  112.         if(SmokeID[i] == -1) a++;
  113.     }
  114.     return a;
  115. }
  116.  
  117. stock SmokeEmpty()
  118. {
  119.     for(new i; i < MAX_SMOKES; i++)
  120.     {
  121.         if(SmokeID[i] == -1) return i;
  122.     }
  123.     return -1;
  124. }
  125.  
  126. stock SmokeError(erroid)
  127. {
  128.     new str[50];
  129.  
  130.     switch(erroid)
  131.     {
  132.         case 0: str = "[Smoke13 Erro] MAX_SMOKES está limitado";
  133.         case 1: str = "[Smoke13 Erro] Smoke Type inválido";
  134.         case 2: str = "[Smoke13 Erro] Smoke Time inválido";
  135.     }
  136.     return str;
  137. }
  138.  
  139. stock GetSmokeType(smokeid)
  140. {
  141.     switch(smokeid)
  142.     {
  143.         case 18703: smokeid = 0;
  144.         case 18704: smokeid = 1;
  145.         case 18710: smokeid = 2;
  146.         case 18713: smokeid = 3;
  147.         case 18714: smokeid = 4;
  148.         case 18715: smokeid = 5;
  149.         case 18716: smokeid = 6;
  150.         case 18725: smokeid = 7;
  151.         case 18726: smokeid = 8;
  152.         case 18727: smokeid = 9;
  153.         case 18731: smokeid = 10;
  154.         case 18735: smokeid = 11;
  155.         default: smokeid = -1;
  156.     }
  157.     return smokeid;
  158. }
  159.  
  160. stock GetRangeSmoke(smokeid)
  161. {
  162.     new value;
  163.     switch(smokeid)
  164.     {
  165.         case 18703: value = 3;
  166.         case 18704: value = 3;
  167.         case 18710: value = 4;
  168.         case 18713: value = 10;
  169.         case 18714: value = 7;
  170.         case 18715: value = 5;
  171.         case 18716: value = 2;
  172.         case 18725: value = 2;
  173.         case 18726: value = 2;
  174.         case 18727: value = 3;
  175.         case 18731: value = 3;
  176.         case 18735: value = 2;
  177.         default: value = 0;
  178.     }
  179.  
  180.     return _:value;
  181. }
  182. //==================================[CALLBACKS]=================================
  183. callback::DestroySmoke(smokeid)
  184. {
  185.     if(SmokeID[SmokeSlot[smokeid]] == -1) return 0;
  186.     DestroyObject(smokeid);
  187.     SmokeID[SmokeSlot[smokeid]] = -1;
  188.     SmokeSlot[smokeid] = -1;
  189.     SmokeType[smokeid] = -1;
  190.     return 1;
  191. }
  192.  
  193. callback::CheckPlayerInSmoke(playerid)
  194. {
  195.     for(new i; i < MAX_SMOKES; i++)
  196.     {
  197.         if(SmokeID[i] == -1) continue;
  198.         new raio = GetRangeSmoke(SmokeType[SmokeID[i]]);
  199.         if(IsPlayerInRangeOfPoint(playerid, raio, SmokePos[SmokeID[i]][0], SmokePos[SmokeID[i]][1], SmokePos[SmokeID[i]][2]))
  200.         {
  201.             CallLocalFunction("IsPlayerInSmoke", "iii", playerid, SmokeID[i], GetSmokeType(SmokeType[SmokeID[i]]));
  202.             break;
  203.         }
  204.     }
  205. }
  206. //===================================[HOOK'S]===================================
  207. hook OnGameModeInit(playerid)
  208. {
  209.     ResetSmokes();
  210.     return 1;
  211. }
  212.  
  213. hook OnPlayerConnect(playerid)
  214. {
  215.     FirstSpawn_SM[playerid] = true;
  216.     return 1;
  217. }
  218.  
  219. hook OnPlayerSpawn(playerid)
  220. {
  221.     if(FirstSpawn_SM[playerid]) FirstSpawn_SM[playerid] = false, SetTimerEx("CheckPlayerInSmoke", 1000, true, "i", playerid);
  222.     return 1;
  223. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement