You want to calculate the players position into a screen coordinate?
Do something like:
var map_ratio[2]; // saves the ratio from real world coordinates to map coordinates
var icon_pos[2]; // where the icon can be placed on the 2d map (screen position)
var map_size[2] = 1024,768;
var terrain_size[2] = 4000,4000;
function map_CalcIconPos(&_WorldPos)
{
icon_pos.x = _WorldPos[0] * map_ratio.x + (map_size.x / 2);
icon_pos.y = _WorldPos[1] * map_ratio.y + (map_size.y / 2);
}
function map_startup()
{
map_ratio.x = map_size.x / terrain_size.x;
map_ratio.y = map_size.y / terrain_size.y;
}
Now if you happen to change the terrain to have its upper left corner at 0 you just have to remove the + (..) part of the icon_pos.x/y calculation lines.
If you want to have it the other way around:
Use the code from above plus this function
function map_CalcEntPos(&_MapPos, _ent)
{
_ent.x = (_MapPos[0] - (map_size.x/2)) / map_ratio.x;
_ent.y = (_MapPos[1] - (map_size.y/2)) / map_ratio.y;
}
How to call these functions:
map_CalcIconPos(&_WorldPos)
This function expects a vector as parameter. Thus you can call it like this:
map_CalcIconPos(player.x);
or:
map_CalcIconPos(vector(x,y,z));
(the z component will not be used in the calculation.
map_CalcEntPos(&_MapPos, _ent);
This function expects a vector and an entity pointer as parameters.
Example:
map_CalcEntPos(vector(256,20,0),player);
Now the player entity will be set at the world coordinates of the map location (256,20).
NOTE:
None of this code is tested! Used it at your own risk

If it crashes your computer its not my fault
