CreativityLacker

[Include] Map icons V0.50

Mar 14th, 2013
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.49 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. native IsValidVehicle(vehicleid);
  4.  
  5. #define UPDATE_TIMER 1000
  6.  
  7. #define MAX_ICONS 99 //As written in SA-MP wiki
  8.  
  9. enum mapiconsinfo
  10. {
  11.     bool:IsInUse[MAX_PLAYERS],
  12.     TypeOfIcon,
  13.     M_UpdateTimer,
  14.     marker,
  15.     colour,
  16.     marker_style
  17. }
  18.  
  19. new MapIcons[MAX_ICONS][mapiconsinfo];
  20.  
  21.  
  22. #define GetIconType(%1) MapIcon[%1][TypeOfIcon] //Thanks to Niko_boy for suggesting this, never knew this could be done like this
  23.  
  24. #define TYPE_NONE -1
  25. #define TYPE_NORMAL 0
  26. #define TYPE_ATTACHED_TO_VEHICLE 1
  27. #define TYPE_ATTACHED_TO_OBJECT 2
  28. #define TYPE_ATTACHED_TO_PLAYER 3
  29.  
  30. stock SetPlayerMapIconEx(playerid, iconid, Float:x, Float:y, Float:z, markertype, color, style)
  31. {
  32.     SetPlayerMapIcon(playerid, iconid, x, y, z, markertype, color, style);
  33.     MapIcons[iconid][IsInUse][playerid] = true;
  34.     MapIcons[iconid][marker] = markertype;
  35.     MapIcons[iconid][colour] = color;
  36.     MapIcons[iconid][marker_style] = style;
  37.     MapIcons[iconid][TypeOfIcon] = TYPE_NORMAL;
  38.     return 1;
  39. }
  40.  
  41. stock AttachMapIconToVehicle(iconid, vehicleid, markertype, color, style)
  42. {
  43.     if(iconid > MAX_ICONS) return printf("[ERROR] Map icon not created as it exceeds MAX_ICONS %d", MAX_ICONS);
  44.     for(new x= 0;x < MAX_PLAYERS; x++)
  45.     {
  46.         new Float:Vp[3];
  47.         GetVehiclePos(vehicleid, Vp[0], Vp[1], Vp[2]);
  48.         if(MapIcons[iconid][IsInUse][x] == true) return printf("[ERROR] Map icon already in use for some players [%d]", iconid);
  49.         else
  50.         {
  51.             SetPlayerMapIcon(x, iconid, Vp[0], Vp[1], Vp[2], markertype, color, style);
  52.             MapIcons[iconid][IsInUse][x] =  true;
  53.             MapIcons[iconid][marker] = markertype;
  54.             MapIcons[iconid][colour] = color;
  55.             MapIcons[iconid][marker_style] = style;
  56.             MapIcons[iconid][M_UpdateTimer] = SetTimerEx("M_UpdateVehIcon", UPDATE_TIMER, true, "dd", iconid, vehicleid);
  57.             MapIcons[iconid][TypeOfIcon] = TYPE_ATTACHED_TO_VEHICLE;
  58.         }
  59.     }
  60.     return 1;
  61. }
  62.  
  63. stock AttachMapIconToObject(iconid, objectid, markertype, color, style)
  64. {
  65.     if(iconid > MAX_ICONS) return printf("[ERROR] Map icon not created as it exceeds MAX_ICONS %d", MAX_ICONS);
  66.     if(!IsValidObject(objectid)) return printf("[ERROR] Object doesn't exist [%d] [%d]", iconid, objectid);
  67.     for(new x=0; x < MAX_PLAYERS; x++)
  68.     {
  69.         new Float:Op[3];
  70.         GetObjectPos(objectid, Op[0], Op[1], Op[2]);
  71.         if(MapIcons[iconid][IsInUse][x] == true) return printf("[ERROR] Map icon already in use for some players [%d]", iconid);
  72.         else
  73.         {
  74.             SetPlayerMapIcon(x, iconid, Op[0], Op[1], Op[2], markertype, color, style);
  75.             MapIcons[iconid][IsInUse][x] =  true;
  76.             MapIcons[iconid][marker] = markertype;
  77.             MapIcons[iconid][colour] = color;
  78.             MapIcons[iconid][marker_style] = style;
  79.             MapIcons[iconid][M_UpdateTimer] = SetTimerEx("M_UpdateObjIcon", UPDATE_TIMER, true, "dd", iconid, objectid);
  80.             MapIcons[iconid][TypeOfIcon] = TYPE_ATTACHED_TO_OBJECT;
  81.         }
  82.     }
  83.     return 1;
  84. }
  85.  
  86. stock AttachMapIconToPlayer(iconid, playerid, markertype, color, style)
  87. {
  88.     if(iconid > MAX_ICONS) return printf("[ERROR] Map icon not created as it exceeds MAX_ICONS %d", MAX_ICONS);
  89.     if(!IsPlayerConnected(playerid)) return printf("[ERROR] Player doesn't exist [%d] [%d]", iconid, playerid);
  90.     for(new x=0; x < MAX_PLAYERS; x++)
  91.     {
  92.         new Float:Pp[3];
  93.         GetPlayerPos(playerid, Pp[0], Pp[1], Pp[2]);
  94.         if(MapIcons[iconid][IsInUse][x] == true) return printf("[ERROR] Map icon already in use for some players [%d]", iconid);
  95.         else
  96.         {
  97.             SetPlayerMapIcon(x, iconid, Pp[0], Pp[1], Pp[2], markertype, color, style);
  98.             MapIcons[iconid][IsInUse][x] =  true;
  99.             MapIcons[iconid][marker] = markertype;
  100.             MapIcons[iconid][colour] = color;
  101.             MapIcons[iconid][marker_style] = style;
  102.             MapIcons[iconid][M_UpdateTimer] = SetTimerEx("M_UpdatePlayerIcon", UPDATE_TIMER, true, "dd", iconid, objectid);
  103.             MapIcons[iconid][TypeOfIcon] = TYPE_ATTACHED_TO_PLAYER;
  104.         }
  105.     }
  106.     return 1;
  107. }
  108.  
  109.  
  110. stock DeattachMapIconFromEverything(iconid)
  111. {
  112.     for(new x= 0; x < MAX_PLAYERS; x++)
  113.     {
  114.         MapIcons[iconid][IsInUse][x] = false;
  115.     }
  116.     MapIcons[marker] = -1;
  117.     MapIcons[colour] = -1;
  118.     MapIcons[marker_style] = -1;
  119.     KillTimer(MapIcons[iconid][M_UpdateTimer]);
  120.     MapIcons[iconid][TypeOfIcon] = TYPE_NONE;
  121.     return 1;
  122. }
  123. forward M_UpdatePlayerIcon(iconid, playerid);
  124. public M_UpdatePlayerIcon(iconid, playerid)
  125. {
  126.     if(MapIcons[iconid][TypeOfIcon] != TYPE_ATTACHED_TO_PLAYER) return printf("[ERROR] Icon not attached to player [%d] [%d]", iconid, playerid);
  127.     if(!IsPlayerConnected(playerid))
  128.     {
  129.         KillTimer(MapIcons[iconid][M_UpdateTimer]);
  130.         return printf("[ERROR] player not connected, timer killed, function aborted ");
  131.     }
  132.     for(new x=0; x < MAX_PLAYERS; x++)
  133.     {
  134.         if(MapIcons[iconid][IsInUse][x] != true) return printf("[ERROR] icon not used by some players, timer continued anyway ");
  135.         new Float:Pp[3];
  136.         GetPlayerPos(playerid, Pp[0], Pp[1], Pp[2]);
  137.         SetPlayerMapIcon(x, iconid, Pp[0], Pp[1], Pp[2], MapIcons[iconid][marker], MapIcons[iconid][colour], MapIcons[iconid][marker_style]);
  138.     }
  139.     return 1;
  140. }
  141.  
  142. forward M_UpdateObjIcon(iconid, objectid);
  143. public M_UpdateObjIcon(iconid, objectid)
  144. {
  145.     if(MapIcons[iconid][TypeOfIcon] != TYPE_ATTACHED_TO_OBJECT) return printf("[ERROR] Icon not attached to object [%d] [%d]", iconid, objectid);
  146.     if(!IsValidObject(objectid))
  147.     {
  148.         KillTimer(MapIcons[iconid][M_UpdateTimer]);
  149.         return printf("[ERROR] object doesn't exist, timer killed, function aborted ");
  150.     }
  151.     for(new x= 0; x <MAX_PLAYERS; x++)
  152.     {
  153.         if(MapIcons[iconid][IsInUse][x] != true) return printf("[ERROR] icon not used by some players, timer continued anyway ");
  154.         new Float:Op[3];
  155.         GetObjectPos(objectid, Op[0], Op[1], Op[2]);
  156.         SetPlayerMapIcon(x, iconid, Op[0], Op[1], Op[2], MapIcons[iconid][marker], MapIcons[iconid][colour], MapIcons[iconid][marker_style]);
  157.     }
  158.     return 1;
  159. }
  160.  
  161. forward M_UpdateVehIcon(iconid, vehicleid);
  162. public M_UpdateVehIcon(iconid, vehicleid)
  163. {
  164.     if(MapIcons[iconid][TypeOfIcon] != TYPE_ATTACHED_TO_VEHICLE) return printf("[ERROR] Icon not attached to vehicle [%d][%d]", iconid, vehicleid);
  165.     if(!IsValidVehicle(vehicleid))
  166.     {
  167.         KillTimer(MapIcons[iconid][M_UpdateTimer]);
  168.         return printf("[ERROR] vehicle doesn't exist, timer killed, function aborted");
  169.     }
  170.     for(new x=0; x < MAX_PLAYERS; x++)
  171.     {
  172.         if(MapIcons[iconid][IsInUse][x] != true) return printf("[ERROR] icon not used by some players, timer continued anyway");
  173.         new Float:Vp[3];
  174.         GetVehiclePos(vehicleid, Vp[0], Vp[1], Vp[2]);
  175.         SetPlayerMapIcon(x, iconid, Vp[0], Vp[1], Vp[2], MapIcons[iconid][marker], MapIcons[iconid][colour], MapIcons[iconid][marker_style]);
  176.     }
  177.     return 1;
  178. }
Advertisement
Add Comment
Please, Sign In to add comment