Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- native IsValidVehicle(vehicleid);
- #define UPDATE_TIMER 1000
- #define MAX_ICONS 99 //As written in SA-MP wiki
- enum mapiconsinfo
- {
- bool:IsInUse[MAX_PLAYERS],
- TypeOfIcon,
- M_UpdateTimer,
- marker,
- colour,
- marker_style
- }
- new MapIcons[MAX_ICONS][mapiconsinfo];
- #define GetIconType(%1) MapIcon[%1][TypeOfIcon] //Thanks to Niko_boy for suggesting this, never knew this could be done like this
- #define TYPE_NONE -1
- #define TYPE_NORMAL 0
- #define TYPE_ATTACHED_TO_VEHICLE 1
- #define TYPE_ATTACHED_TO_OBJECT 2
- #define TYPE_ATTACHED_TO_PLAYER 3
- stock SetPlayerMapIconEx(playerid, iconid, Float:x, Float:y, Float:z, markertype, color, style)
- {
- SetPlayerMapIcon(playerid, iconid, x, y, z, markertype, color, style);
- MapIcons[iconid][IsInUse][playerid] = true;
- MapIcons[iconid][marker] = markertype;
- MapIcons[iconid][colour] = color;
- MapIcons[iconid][marker_style] = style;
- MapIcons[iconid][TypeOfIcon] = TYPE_NORMAL;
- return 1;
- }
- stock AttachMapIconToVehicle(iconid, vehicleid, markertype, color, style)
- {
- if(iconid > MAX_ICONS) return printf("[ERROR] Map icon not created as it exceeds MAX_ICONS %d", MAX_ICONS);
- for(new x= 0;x < MAX_PLAYERS; x++)
- {
- new Float:Vp[3];
- GetVehiclePos(vehicleid, Vp[0], Vp[1], Vp[2]);
- if(MapIcons[iconid][IsInUse][x] == true) return printf("[ERROR] Map icon already in use for some players [%d]", iconid);
- else
- {
- SetPlayerMapIcon(x, iconid, Vp[0], Vp[1], Vp[2], markertype, color, style);
- MapIcons[iconid][IsInUse][x] = true;
- MapIcons[iconid][marker] = markertype;
- MapIcons[iconid][colour] = color;
- MapIcons[iconid][marker_style] = style;
- MapIcons[iconid][M_UpdateTimer] = SetTimerEx("M_UpdateVehIcon", UPDATE_TIMER, true, "dd", iconid, vehicleid);
- MapIcons[iconid][TypeOfIcon] = TYPE_ATTACHED_TO_VEHICLE;
- }
- }
- return 1;
- }
- stock AttachMapIconToObject(iconid, objectid, markertype, color, style)
- {
- if(iconid > MAX_ICONS) return printf("[ERROR] Map icon not created as it exceeds MAX_ICONS %d", MAX_ICONS);
- if(!IsValidObject(objectid)) return printf("[ERROR] Object doesn't exist [%d] [%d]", iconid, objectid);
- for(new x=0; x < MAX_PLAYERS; x++)
- {
- new Float:Op[3];
- GetObjectPos(objectid, Op[0], Op[1], Op[2]);
- if(MapIcons[iconid][IsInUse][x] == true) return printf("[ERROR] Map icon already in use for some players [%d]", iconid);
- else
- {
- SetPlayerMapIcon(x, iconid, Op[0], Op[1], Op[2], markertype, color, style);
- MapIcons[iconid][IsInUse][x] = true;
- MapIcons[iconid][marker] = markertype;
- MapIcons[iconid][colour] = color;
- MapIcons[iconid][marker_style] = style;
- MapIcons[iconid][M_UpdateTimer] = SetTimerEx("M_UpdateObjIcon", UPDATE_TIMER, true, "dd", iconid, objectid);
- MapIcons[iconid][TypeOfIcon] = TYPE_ATTACHED_TO_OBJECT;
- }
- }
- return 1;
- }
- stock AttachMapIconToPlayer(iconid, playerid, markertype, color, style)
- {
- if(iconid > MAX_ICONS) return printf("[ERROR] Map icon not created as it exceeds MAX_ICONS %d", MAX_ICONS);
- if(!IsPlayerConnected(playerid)) return printf("[ERROR] Player doesn't exist [%d] [%d]", iconid, playerid);
- for(new x=0; x < MAX_PLAYERS; x++)
- {
- new Float:Pp[3];
- GetPlayerPos(playerid, Pp[0], Pp[1], Pp[2]);
- if(MapIcons[iconid][IsInUse][x] == true) return printf("[ERROR] Map icon already in use for some players [%d]", iconid);
- else
- {
- SetPlayerMapIcon(x, iconid, Pp[0], Pp[1], Pp[2], markertype, color, style);
- MapIcons[iconid][IsInUse][x] = true;
- MapIcons[iconid][marker] = markertype;
- MapIcons[iconid][colour] = color;
- MapIcons[iconid][marker_style] = style;
- MapIcons[iconid][M_UpdateTimer] = SetTimerEx("M_UpdatePlayerIcon", UPDATE_TIMER, true, "dd", iconid, objectid);
- MapIcons[iconid][TypeOfIcon] = TYPE_ATTACHED_TO_PLAYER;
- }
- }
- return 1;
- }
- stock DeattachMapIconFromEverything(iconid)
- {
- for(new x= 0; x < MAX_PLAYERS; x++)
- {
- MapIcons[iconid][IsInUse][x] = false;
- }
- MapIcons[marker] = -1;
- MapIcons[colour] = -1;
- MapIcons[marker_style] = -1;
- KillTimer(MapIcons[iconid][M_UpdateTimer]);
- MapIcons[iconid][TypeOfIcon] = TYPE_NONE;
- return 1;
- }
- forward M_UpdatePlayerIcon(iconid, playerid);
- public M_UpdatePlayerIcon(iconid, playerid)
- {
- if(MapIcons[iconid][TypeOfIcon] != TYPE_ATTACHED_TO_PLAYER) return printf("[ERROR] Icon not attached to player [%d] [%d]", iconid, playerid);
- if(!IsPlayerConnected(playerid))
- {
- KillTimer(MapIcons[iconid][M_UpdateTimer]);
- return printf("[ERROR] player not connected, timer killed, function aborted ");
- }
- for(new x=0; x < MAX_PLAYERS; x++)
- {
- if(MapIcons[iconid][IsInUse][x] != true) return printf("[ERROR] icon not used by some players, timer continued anyway ");
- new Float:Pp[3];
- GetPlayerPos(playerid, Pp[0], Pp[1], Pp[2]);
- SetPlayerMapIcon(x, iconid, Pp[0], Pp[1], Pp[2], MapIcons[iconid][marker], MapIcons[iconid][colour], MapIcons[iconid][marker_style]);
- }
- return 1;
- }
- forward M_UpdateObjIcon(iconid, objectid);
- public M_UpdateObjIcon(iconid, objectid)
- {
- if(MapIcons[iconid][TypeOfIcon] != TYPE_ATTACHED_TO_OBJECT) return printf("[ERROR] Icon not attached to object [%d] [%d]", iconid, objectid);
- if(!IsValidObject(objectid))
- {
- KillTimer(MapIcons[iconid][M_UpdateTimer]);
- return printf("[ERROR] object doesn't exist, timer killed, function aborted ");
- }
- for(new x= 0; x <MAX_PLAYERS; x++)
- {
- if(MapIcons[iconid][IsInUse][x] != true) return printf("[ERROR] icon not used by some players, timer continued anyway ");
- new Float:Op[3];
- GetObjectPos(objectid, Op[0], Op[1], Op[2]);
- SetPlayerMapIcon(x, iconid, Op[0], Op[1], Op[2], MapIcons[iconid][marker], MapIcons[iconid][colour], MapIcons[iconid][marker_style]);
- }
- return 1;
- }
- forward M_UpdateVehIcon(iconid, vehicleid);
- public M_UpdateVehIcon(iconid, vehicleid)
- {
- if(MapIcons[iconid][TypeOfIcon] != TYPE_ATTACHED_TO_VEHICLE) return printf("[ERROR] Icon not attached to vehicle [%d][%d]", iconid, vehicleid);
- if(!IsValidVehicle(vehicleid))
- {
- KillTimer(MapIcons[iconid][M_UpdateTimer]);
- return printf("[ERROR] vehicle doesn't exist, timer killed, function aborted");
- }
- for(new x=0; x < MAX_PLAYERS; x++)
- {
- if(MapIcons[iconid][IsInUse][x] != true) return printf("[ERROR] icon not used by some players, timer continued anyway");
- new Float:Vp[3];
- GetVehiclePos(vehicleid, Vp[0], Vp[1], Vp[2]);
- SetPlayerMapIcon(x, iconid, Vp[0], Vp[1], Vp[2], MapIcons[iconid][marker], MapIcons[iconid][colour], MapIcons[iconid][marker_style]);
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment