04.01.2010, 01:08
[TUT]Creating Simple Icon Streamers!
The fun defines .pawn Код:
#define MAX_MARKERS 1000 //Max amount of markers (Increasing causes the file to be larger decreasing does the opposite).
enum Info
{
Float:x, //XPos
Float:y, //YPos
Float:z, //ZPos
markertype, //Marker type
color, //Color of the marker
Float:Dist
};
new MarkerInfo[MAX_MARKERS][Info];
new MarkerID = -1;
new PlayerMarkers[MAX_PLAYERS][MAX_MARKERS];
new MarkerUsed[MAX_MARKERS];
new IconID[MAX_PLAYERS][MAX_MARKERS];
new SlotsUsed[MAX_PLAYERS][100];
pawn Код:
stock SetPlayerMapIconEx(Float:X, Float:Y, Float:Z, Markertype, Color, Float:dist = 100.0)
{
MarkerID ++; //Marker ID added
MarkerUsed[MarkerID] = 1; //Enabled = 1 disabled = 0
MarkerInfo[MarkerID][markertype] = Markertype; //Marker type check https://sampwiki.blast.hk/wiki/SetPlayerMapIcon for them
MarkerInfo[MarkerID][x] = X; //X of the icon
MarkerInfo[MarkerID][y] = Y; //Y of the icon
MarkerInfo[MarkerID][z] = Z; //Z of the icon
MarkerInfo[MarkerID][color] = Color; //Color of the icon.
MarkerInfo[MarkerID][Dist] = dist;
}
Firstly we need a stream timer, put it somewhere like OnGameModeInit().
pawn Код:
SetTimer("Stream", 500, true); //You can change it to less time or more time per go.
pawn Код:
forward Stream(); //Forward all timers
public Stream()
{
for(new i; i<MAX_PLAYERS; i++)//Goes through all players
{
if(IsPlayerConnected(i)) //All online players
{
for(new S; S<MarkerID+1; S++) //All active Markers
{
if(MarkerUsed[S] == 1) //Checks if the Marker is enabled
{
if(IsPlayerInRangeOfPoint(i, MarkerInfo[S][Dist], MarkerInfo[S][x], MarkerInfo[S][y], MarkerInfo[S][z]) && PlayerMarkers[i][S] == 0)//Is the player close enough to the Marker and the player does not already have it streamed
{
for(new K; K<100; K++)//Loops
{
if(SlotsUsed[i][K] == 0)//Through all the 100 avalible icon slots
{
SlotsUsed[i][K]++; //Sets the Icon slot to used
IconID[i][S] = K; //Sets the iconid
break; //Breaks out of the variable
}
}
SetPlayerMapIcon(i, IconID[i][S], MarkerInfo[S][x], MarkerInfo[S][y], MarkerInfo[S][z], MarkerInfo[S][markertype], MarkerInfo[S][color]);//Create the Marker
PlayerMarkers[i][S] = 1; //Shows the object streamed for the player
continue; //Pulls out of the loop alliteration.
}
}
if(!IsPlayerInRangeOfPoint(i, MarkerInfo[S][Dist], MarkerInfo[S][x], MarkerInfo[S][y], MarkerInfo[S][z]) && PlayerMarkers[i][S] == 1) //If the player falls out of that distance the marker is destroyed
{
SlotsUsed[i][IconID[i][S]] = 0; //Sets the Icon slot to used
PlayerMarkers[i][S] = 0; //Sets the player marker to 0 so it's not using it
RemovePlayerMapIcon(i, IconID[i][S]); //Deletes the map Icon
continue;//Pulls out of the loop alliteration.
}
}
}
}
return 1;
}
pawn Код:
stock RemoveMapIconEx(IconId) //Destroys the Map Icon
{
MarkerUsed[IconId] = 0;
for(new i; i<MAX_PLAYERS; i++)
{
if(PlayerMarkers[i][ObjectId] == 1)
{
PlayerMarkers[i][ObjectId] = 0;
DestroyPlayerObject(i, IconID[i][ObjecId]);
SlotsUsed[i][IconID[i][IconId]] = 0
}
}
}
stock SetObjectDistance(ObjectId, Float:dist) //Sets the view distance of a Map Icon
{
MarkerInfo[MarkerID][Dist] = dist;
}
pawn Код:
SetPlayerMapIconEx(2317.130615, 692.398498, 11.460937, 31, 0, 25);
SetPlayerMapIconEx(2346.872802, 692.999267, 11.460937, 31, 0, 25);
SetPlayerMapIconEx(2396.482666, 691.487060, 11.453125, 31, 0, 25);
SetPlayerMapIconEx(2398.476074, 735.344665, 11.460937, 31, 0, 25);
If you want the version with the proper indentation http://www.datafilehost.com/download-58b293cd.html