Guest User

Untitled

a guest
Apr 3rd, 2017
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.67 KB | None | 0 0
  1. /*
  2. Marcas de objetivo
  3. Jelly23
  4. */
  5.  
  6. #include <a_samp>
  7.  
  8. /*Configuração*/
  9. #define OM_USAR_STREAMER (false)
  10. #define OM_USAR_FOREACH  (false)
  11. #define OM_MAX_GROUPS    (100)
  12.  
  13.  
  14. /*Enumerador*/
  15. enum OM_GROUPS_INF
  16. {
  17.     OM_GROUP_TIMER,
  18.     OM_GROUP_MARKER,
  19.     OM_GROUP_EXISTS
  20. };
  21.  
  22. /*Vars*/
  23. static
  24.     OM_Group[MAX_PLAYERS], //Grupo do jogador.
  25.     OM_Marca[MAX_PLAYERS], //Marcas globais por jogador.
  26.     OM_Timer[MAX_PLAYERS], //Timer de marcas globais.
  27.     OM_Timer_Player[MAX_PLAYERS][MAX_PLAYERS], //Timer de marcas por jogador.
  28.     OM_Marca_Player[MAX_PLAYERS][MAX_PLAYERS], //Marcas por jogador.
  29.     OM_GRINFO[OM_MAX_GROUPS][OM_GROUPS_INF]; //Enumerador de grupos.
  30.  
  31. /*Callback interna*/
  32. forward OM_DestroyObjectiveMarker(playerid, type, attachid);
  33.  
  34. /*Tipos De Marcas*/
  35. #define OM_TYPE_GLOBAL (0)
  36. #define OM_TYPE_PLAYER (1)
  37. #define OM_TYPE_GROUPS (2)
  38.  
  39. public OnPlayerDisconnect(playerid,reason)
  40. {
  41.     OM_Group[playerid] = -1;
  42.     DestroyObjectiveMarker(playerid);
  43.     #if defined OM_OnPlayerDisconnect
  44.         return OM_OnPlayerDisconnect(playerid,reason);
  45.     #else
  46.         return 1;
  47.     #endif
  48. }
  49.  
  50. //Callback de uso interno
  51. public OM_DestroyObjectiveMarker(playerid, type, attachid)
  52. {
  53.     if(type == OM_TYPE_GLOBAL)
  54.     {
  55.         if(!IsPlayerConnected(playerid)) return 0;
  56.         #if OM_USAR_STREAMER true
  57.         if(IsValidDynamicObject(OM_Marca[playerid]))
  58.         {
  59.             DestroyDynamicObject(OM_Marca[playerid]);
  60.         }
  61.         #else
  62.         if(IsValidObject(OM_Marca[playerid]))
  63.         {
  64.             DestroyObject(OM_Marca[playerid]);
  65.         }
  66.         #endif
  67.     }
  68.     else if(type == OM_TYPE_PLAYER)
  69.     {
  70.         if(!IsPlayerConnected(playerid)) return 0;
  71.         if(IsValidPlayerObject(playerid, OM_Marca_Player[playerid][attachid])) DestroyPlayerObject(playerid, OM_Marca_Player[playerid][attachid]);
  72.     }
  73.     else
  74.     {
  75.         if(!IsPlayerConnected(attachid)) return 0;
  76.         #if OM_USAR_FOREACH true
  77.         foreach(new i: Player)
  78.         {
  79.             if(OM_Group[i] == playerid)
  80.             {
  81.                 if(IsValidPlayerObject(i, OM_Marca_Player[i][attachid])) DestroyPlayerObject(i, OM_Marca_Player[i][attachid]);
  82.             }
  83.         }
  84.         #else
  85.         for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
  86.         {      
  87.             if(IsPlayerConnected(i))
  88.             {
  89.                 if(OM_Group[i] == playerid)
  90.                 {
  91.                     if(IsValidPlayerObject(i, OM_Marca_Player[i][attachid])) DestroyPlayerObject(i, OM_Marca_Player[i][attachid]);
  92.                 }
  93.             }
  94.         }
  95.         #endif 
  96.     }
  97.     return 1;
  98. }
  99.  
  100. //Funções Globais
  101. stock CreateObjectiveMarker(playerid, color= -55, time = 0)
  102. {
  103.     if(!IsPlayerConnected(playerid)) return 0;
  104.     #if OM_USAR_STREAMER true
  105.     if(IsValidDynamicObject(OM_Marca[playerid]))
  106.     {
  107.         DestroyDynamicObject(OM_Marca[playerid]);
  108.     }
  109.     #else
  110.     if(IsValidObject(OM_Marca[playerid]))
  111.     {
  112.         DestroyObject(OM_Marca[playerid]);
  113.     }
  114.     #endif
  115.     if(color == -55) color = GetPlayerColor(playerid);
  116.     if(time > 0)
  117.     {
  118.         OM_Timer[playerid] = SetTimerEx("OM_DestroyObjectiveMarker", time, false, "ii", playerid, OM_TYPE_GLOBAL);
  119.     }
  120.     #if OM_USAR_STREAMER true
  121.         OM_Marca[playerid] = CreateDynamicObject(19198, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
  122.         SetDynamicObjectMaterial(OM_Marca[playerid], 0, -1, "none", "none", color >>> 8 | color << 24);
  123.         AttachDynamicObjectToPlayer(OM_Marca[playerid], playerid, 0.0, 0.0, 2.3, 0.000000, 0.000000,0.000000);
  124.     #else
  125.         OM_Marca[playerid] = CreateObject(19198, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
  126.         SetObjectMaterial(OM_Marca[playerid], 0, -1, "none", "none", color >>> 8 | color << 24);
  127.         AttachObjectToPlayer(OM_Marca[playerid], playerid, 0.0, 0.0, 2.3, 0.000000, 0.000000,0.000000);
  128.     #endif
  129.     return 1;
  130. }
  131.  
  132. stock DestroyObjectiveMarker(playerid)
  133. {
  134.     if(!IsPlayerConnected(playerid)) return 0;
  135.     #if OM_USAR_STREAMER true
  136.     if(IsValidDynamicObject(OM_Marca[playerid]))
  137.     {
  138.         DestroyDynamicObject(OM_Marca[playerid]);
  139.     }
  140.     #else
  141.     if(IsValidObject(OM_Marca[playerid]))
  142.     {
  143.         DestroyObject(OM_Marca[playerid]);
  144.     }
  145.     #endif
  146.     return 1;
  147. }
  148.  
  149. stock IsValidMarker(playerid)
  150. {
  151.     if(!IsPlayerConnected(playerid)) return 0;
  152.     #if OM_USAR_STREAMER true
  153.         if(IsValidDynamicObject(OM_Marca[playerid]))
  154.     #else
  155.         if(IsValidObject(OM_Marca[playerid]))
  156.     #endif
  157.     {
  158.         return 1;
  159.     }
  160.     else return 0;
  161. }
  162.  
  163. //Funções de grupos
  164. stock CreateObjectiveMarkerGroup(id, marker_color)
  165. {
  166.     if(0 < id > OM_MAX_GROUPS || OM_GRINFO[id][OM_GROUP_EXISTS]) return 0;
  167.    
  168.     OM_GRINFO[id][OM_GROUP_MARKER] = marker_color;
  169.     OM_GRINFO[id][OM_GROUP_EXISTS] = 1;
  170.     return 1;
  171. }
  172.  
  173. stock DestroyObjectiveMarkerGroup(id)
  174. {
  175.     if(0 < id > OM_MAX_GROUPS) return 0;
  176.     OM_GRINFO[id][OM_GROUP_EXISTS] = 0;
  177.     #if OM_USAR_FOREACH true
  178.     foreach(new i: Player)
  179.     {
  180.         if(OM_Group[i] == id)
  181.         {
  182.             OM_Group[i] = -1;
  183.         }
  184.     }
  185.     #else
  186.     for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
  187.     {      
  188.         if(IsPlayerConnected(i))
  189.         {
  190.             if(OM_Group[i] == id)
  191.             {
  192.                 OM_Group[i] = -1;
  193.             }
  194.         }
  195.     }
  196.     #endif
  197.     return 1;
  198. }
  199.  
  200. stock AddPlayerToObjectiveGroup(playerid, group_id)
  201. {
  202.     if(0 < group_id > OM_MAX_GROUPS || !OM_GRINFO[group_id][OM_GROUP_EXISTS]) return 0;
  203.     OM_Group[playerid] = group_id;
  204.     return 1;
  205. }
  206.  
  207. stock RemovePlayerFromObjectiveGroup(playerid)
  208. {
  209.     OM_Group[playerid] = -1;
  210.     return 1;
  211. }
  212.  
  213. stock DestroyObjectiveMarkerForGroup(groupid, attachid)
  214. {
  215.     if(!IsPlayerConnected(attachid)) return 0;
  216.     #if OM_USAR_FOREACH true
  217.     foreach(new i: Player)
  218.     {
  219.         if(OM_Group[i] == groupid)
  220.         {
  221.             if(IsValidPlayerObject(i, OM_Marca_Player[i][attachid])) DestroyPlayerObject(i, OM_Marca_Player[i][attachid]);
  222.         }
  223.     }
  224.     #else
  225.     for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
  226.     {      
  227.         if(IsPlayerConnected(i))
  228.         {
  229.             if(OM_Group[i] == groupid)
  230.             {
  231.                 if(IsValidPlayerObject(i, OM_Marca_Player[i][attachid])) DestroyPlayerObject(i, OM_Marca_Player[i][attachid]);
  232.             }
  233.         }
  234.     }
  235.     #endif
  236.     return 1;
  237. }
  238.  
  239. stock CreateObjectiveMarkerForGroup(groupid, attachid, color= -55, time = 0)
  240. {
  241.     if(!IsPlayerConnected(attachid) || 0 < groupid > OM_MAX_GROUPS || !OM_GRINFO[groupid][OM_GROUP_EXISTS]) return 0;
  242.     if(color == -55) color = OM_GRINFO[groupid][OM_GROUP_MARKER];
  243.     if(time > 0)
  244.     {
  245.         OM_GRINFO[groupid][OM_GROUP_TIMER] = SetTimerEx("OM_DestroyObjectiveMarker", time, false, "iii", groupid, OM_TYPE_GROUPS, attachid);
  246.     }
  247.     #if OM_USAR_FOREACH true
  248.     foreach(new i: Player)
  249.     {
  250.         if(OM_Group[i] == groupid)
  251.         {
  252.             if(IsValidPlayerObject(i, OM_Marca_Player[i][attachid])) DestroyPlayerObject(i, OM_Marca_Player[i][attachid]);
  253.             OM_Marca_Player[i][attachid] = CreatePlayerObject(i, 19198, 0, 0, 0, 0, 0, 0);
  254.             SetPlayerObjectMaterial(i, OM_Marca_Player[i][attachid], 0, -1, "none", "none", color >>> 8 | color << 24);
  255.             AttachPlayerObjectToPlayer(i, OM_Marca_Player[i][attachid], attachid, 0.0, 0.0, 2.3, 0, 0, 0); 
  256.         }
  257.     }
  258.     #else
  259.     for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
  260.     {
  261.         if(IsPlayerConnected(i))
  262.         {
  263.             if(OM_Group[i] == groupid)
  264.             {  
  265.                 if(IsValidPlayerObject(i, OM_Marca_Player[i][attachid])) DestroyPlayerObject(i, OM_Marca_Player[i][attachid]);
  266.                 OM_Marca_Player[i][attachid] = CreatePlayerObject(i, 19198, 0, 0, 0, 0, 0, 0);
  267.                 SetPlayerObjectMaterial(i, OM_Marca_Player[i][attachid], 0, -1, "none", "none", color >>> 8 | color << 24);
  268.                 AttachPlayerObjectToPlayer(i, OM_Marca_Player[i][attachid], attachid, 0.0, 0.0, 2.3, 0, 0, 0); 
  269.             }
  270.         }
  271.     }
  272.     #endif
  273.     return 1;
  274. }
  275.  
  276. //Funções por Player
  277. stock CreateObjectiveMarkerForPlayer(playerid, attachid, color= -55, time = 0)
  278. {
  279.     if(!IsPlayerConnected(playerid) || !IsPlayerConnected(attachid)) return 0;
  280.     if(IsValidPlayerObject(playerid, OM_Marca_Player[playerid][attachid])) DestroyPlayerObject(playerid, OM_Marca_Player[playerid][attachid]);
  281.     if(color == -55) color = GetPlayerColor(attachid);
  282.     if(time > 0)
  283.     {
  284.         OM_Timer_Player[playerid][attachid] = SetTimerEx("OM_DestroyObjectiveMarker", time, false, "iii", playerid, OM_TYPE_PLAYER, attachid);
  285.     }
  286.     OM_Marca_Player[playerid][attachid] = CreatePlayerObject(playerid, 19198, 0, 0, 0, 0, 0, 0);
  287.     SetPlayerObjectMaterial(playerid, OM_Marca_Player[playerid][attachid], 0, -1, "none", "none", color >>> 8 | color << 24);
  288.     AttachPlayerObjectToPlayer(playerid, OM_Marca_Player[playerid][attachid], attachid, 0.0, 0.0, 2.3, 0, 0, 0);
  289.     return 1;
  290. }
  291.  
  292. stock DestroyObjectiveMarkerForPlayer(playerid, attachid)
  293. {
  294.     if(!IsPlayerConnected(playerid)) return 0;
  295.     if(IsValidPlayerObject(playerid, OM_Marca_Player[playerid][attachid])) DestroyPlayerObject(playerid, OM_Marca_Player[playerid][attachid]);
  296.     return 1;
  297. }
  298.  
  299. stock IsValidPlayerMarker(playerid, attachid)
  300. {
  301.     if(!IsPlayerConnected(playerid)) return 0;
  302.     if(IsValidPlayerObject(playerid, OM_Marca_Player[playerid][attachid])) return 1;
  303.     return 0;
  304. }
  305.    
  306. #if defined _ALS_OnPlayerDisconnect
  307.     #undef OnPlayerDisconnect
  308. #else
  309.     #define _ALS_OnPlayerDisconnect
  310. #endif
  311. #define OnPlayerDisconnect  OM_OnPlayerDisconnect
  312.  
  313. #if defined OM_OnPlayerDisconnect
  314.     forward OM_OnPlayerDisconnect(playerid, reason);
  315. #endif
Advertisement
Add Comment
Please, Sign In to add comment