Need more than a radar? how about a full map of your lovely level?
updated to include fog of war
1. create an image for the actual map background
to easily create an accurate map image zoom out and take a picture of your level (best to do this without zones and markers if possible if taking a picture from the editor, otherwise try f9 mode)
2. create an image to use as the player icon and another (optional) icon for the enemies
player icon will rotate so a directional icon is good, enemies wont rotate yet (as no way to get rotation from stock yet) so a circular icon is good.
3. create an (optional) image to use as fog of war (a simple square is all i used)
4. place a non-static entity with map.lua and set it always active
5. press M in game to open the map
as you can see the map can be resized and moved via script settings and will still work correctly
it can also (optionally) be moved in game via the mouse (left click and drag) if you have no weapon equipped.
if i get chance i will take a look at the objectives code and see if i can add that too.
map.lua
--dont need to change
local map_sprite = nil
local player_sprite = nil
local enemy_sprite = {}
local cursor_sprite = nil
local enemyCount = 0
local map_enemies = {}
local fog_sprite = {}
local fog_explored = {}
local posx = 50
local iposx = 50
local posy = 50
local iposy = 50
pressed = 0
local fogx = 0
local fogy = 0
local fx = 0
local oldmx = 0
local oldmy = 0
--------------------------------
--show map (1 = yes, 0 = no)
--press M in game to toggle
local show_map = 0
--image locations and names
local map_image = "scriptbank\\images\\map\\map.png"
local player_marker = "scriptbank\\images\\map\\player marker.png"
local enemy_marker = "scriptbank\\images\\map\\enemy marker.png" --not needed if you aren't showing enemies
--not needed if you aren't using fog
local fog_i = "scriptbank\\images\\map\\fog.png"
--not needed if you dont want a moveable map
local mouse_i = "scriptbank\\images\\map\\cursor.png"
--how much of the game map you are using (entire map is 0,0,51100,51100)
--this should match the viewable area on the map image (so you can use smaller maps/levels if you know the size in GG)
local game_map_size_min_x = 0
local game_map_size_min_z = 0
local game_map_size_max_x = 51100
local game_map_size_max_z = 51100
--where the map should appear on the screen (top left of image)
--if you want an even gap of screen space use; 100 - (map_image_size_x / 2)
local map_posx = 0
local map_posy = 50
--how much % of the screen the map image takes up
local map_image_size_x = 30
local map_image_size_y = 50
--how big the player marker is on screen (%)
local player_marker_size = 0.5
--display markers for enemies on the map (1 = yes, 0 = no)
local show_enemies = 1
--how far away to stop displaying enemies (0 = always, 3000 is about when the enemy script will turn off/become active, 1500 is the maximum distance they can fire at you from)
local enemy_range = 3000
--how big the enemy markers are (5)
local enemy_marker_size = 0.25
--set fog of war (0 = off, 1 = on)
local fog = 1
--fog will reappear once player leaves area (0 = no, 1 = yes)
local fog_restore = 0
--important; fog_in_row x fog_in_column must be less than 98
--how many images to use in 1 row
local fog_in_row = 13
--how many images to use in 1 column
local fog_in_column = 7
--sets map moveable (1 = yes, 0 = no)
local moveable_map = 1
--size of the cursor/mouse on the screen
local mouse_size = 1.5
--map script by smallg
--place object always active
function map_init(e)
Hide(e)
CollisionOff(e)
end
function map_main(e)
--load map images when game starts
if map_sprite == nil then
Hide(e)
CollisionOff(e)
map_sprite = CreateSprite(LoadImage(map_image))
SetSpritePosition(map_sprite,200,200)
SetSpriteSize(map_sprite,map_image_size_x,map_image_size_y)
player_sprite = CreateSprite(LoadImage(player_marker))
SetSpritePosition(player_sprite,200,200)
SetSpriteOffset(player_sprite,player_marker_size/2,-1)
SetSpriteSize(player_sprite,player_marker_size,-1)
enemy_image = LoadImage(enemy_marker)
--find all enemies loaded at start of game
if show_enemies == 1 then
for c = 1, 9999 do
if ai_soldier_state[c] ~= nil then
enemyCount = enemyCount + 1
map_enemies[enemyCount] = c
enemy_sprite[enemyCount] = CreateSprite( enemy_image )
SetSpriteSize ( enemy_sprite[enemyCount] , enemy_marker_size , -1 )
SetSpritePosition ( enemy_sprite[enemyCount] , 200 , 200 )
end
end
end
if fog == 1 then
for a = 1,fog_in_row*fog_in_column do
fog_sprite[a] = CreateSprite(LoadImage(fog_i))
SetSpritePosition(fog_sprite[a],200,200)
SetSpriteSize(fog_sprite[a],map_image_size_x/fog_in_row,map_image_size_y/fog_in_column)
--SetSpriteSize(fog_corner_sprite[a],map_image_size_x/fog_in_row,-1)
fog_explored[fog_sprite[a]] = 0
end
end
if moveable_map == 1 then
cursor_sprite = CreateSprite(LoadImage(mouse_i))
SetSpritePosition(cursor_sprite,200,200)
SetSpriteSize(cursor_sprite,mouse_size,-1)
end
else
SetPosition(e,g_PlayerPosX,g_PlayerPosY,g_PlayerPosZ)
--if a new enemy is spawned then add a new marker sprite (if we're showing enemies)
if show_enemies == 1 then
if GetFirstEntitySpawn() ~= 0 then
if ai_soldier_state[newEntity] ~= nil then
enemyCount = enemyCount + 1
map_enemies[enemyCount] = c
enemy_sprite[enemyCount] = CreateSprite( enemy_image )
SetSpriteSize ( enemy_sprite[enemyCount] , enemy_marker_size , -1 )
SetSpritePosition ( enemy_sprite[enemyCount] , 200 , 200 )
end
end
end
--player presses m
if GetScancode() == 50 and pressed == 0 then
pressed = 1
--if we're currently showing the map then hide it
if show_map == 1 then
show_map = 0
SetSpritePosition(map_sprite,200,200)
SetSpritePosition(player_sprite,200,200)
if show_enemies == 1 then
for a = 1,enemyCount do
if enemy_sprite[a] ~= nil then
SetSpritePosition(enemy_sprite[a],200,200)
end
end
end
if fog == 1 then
for a = 1, fog_in_row*fog_in_column do
if fog_sprite[a] ~= nil then
SetSpritePosition(fog_sprite[a],200,200)
end
end
end --fog
if moveable_map == 1 then
DeactivateMouse(e)
SetSpritePosition(cursor_sprite,200,200)
end
--else show the map
else
show_map = 1
if moveable_map == 1 and g_PlayerGunID == 0 then
ActivateMouse()
oldmx = -10
oldmy = -10
end
end
end --press m to toggle map
if show_map == 1 then
SetSpritePosition(map_sprite,map_posx,map_posy)
posx = ((g_PlayerPosX - game_map_size_min_x)/(game_map_size_max_x - game_map_size_min_x)) * 100
posy = ((g_PlayerPosZ - game_map_size_min_z)/(game_map_size_max_z - game_map_size_min_z)) * 100
iposx = (posx*(map_image_size_x / 100))+map_posx
iposy = ((map_image_size_y-((posy*(map_image_size_y / 100))))+map_posy)
SetSpritePosition(player_sprite,iposx,iposy)
SetSpriteAngle(player_sprite,g_PlayerAngY)
if show_enemies == 1 then
for a = 1, enemyCount do
if enemy_sprite[a] ~= nil then
if g_Entity[map_enemies[a]]['health'] > 0 then
if GetPlayerDistance(map_enemies[a]) < enemy_range or enemy_range < 1 then
posx = ((g_Entity[map_enemies[a]]['x'] - game_map_size_min_x)/(game_map_size_max_x - game_map_size_min_x)) * 100
posy = ((g_Entity[map_enemies[a]]['z'] - game_map_size_min_z)/(game_map_size_max_z - game_map_size_min_z)) * 100
iposx = (posx*(map_image_size_x / 100))+map_posx
iposy = ((map_image_size_y-((posy*(map_image_size_y / 100))))+map_posy)
SetSpritePosition(enemy_sprite[a],iposx,iposy)
else
SetSpritePosition(enemy_sprite[a],200,200)
end
else
SetSpritePosition(enemy_sprite[a],200,200)
end
end
end
end --enemies
if fog == 1 then
fogx = map_posx
fogy = map_posy
fx = 0
for a = 1, fog_in_row*fog_in_column do
if fog_sprite[a] ~= nil then
if fx > 0 then
if fx < fog_in_row then
fogx = fogx + (map_image_size_x/fog_in_row)
else
fogx = map_posx
fogy = fogy + (map_image_size_y/fog_in_column)
fx = 0
end
end
if fog_explored[fog_sprite[a]] == 0 then
SetSpritePosition(fog_sprite[a],fogx,fogy)
end
fx = fx + 1
if fogx + ((map_image_size_x/fog_in_row)/2) > iposx - (map_image_size_x/fog_in_row) and fogx + ((map_image_size_x/fog_in_row)/2) < iposx + (map_image_size_x/fog_in_row) and fogy + ((map_image_size_y/fog_in_column)/2) > iposy - (map_image_size_y/fog_in_column) and fogy + ((map_image_size_y/fog_in_column)/2) < iposy + (map_image_size_y/fog_in_column) then
if fog_restore == 0 then
fog_explored[fog_sprite[a]] = 1
end
SetSpritePosition(fog_sprite[a],200,200)
end
end
end
end --fog
if moveable_map == 1 then
if g_PlayerGunID == 0 then
if g_MouseClick == 2 then
DeactivateMouse(e)
SetSpritePosition(cursor_sprite,200,200)
else
ActivateMouse(e)
if (oldmx ~= g_MouseX or oldmy ~= g_MouseY) and g_MouseClick ~= 1 then
oldmx = g_MouseX
oldmy = g_MouseY
SetSpritePosition(cursor_sprite,g_MouseX,g_MouseY)
end
if g_MouseClick == 1 then
if g_MouseX < oldmx then
map_posx = map_posx - (oldmx-g_MouseX)
elseif g_MouseX > oldmx then
map_posx = map_posx - (oldmx-g_MouseX)
end
if g_MouseY < oldmy then
map_posy = map_posy - (oldmy-g_MouseY)
elseif g_MouseY > oldmy then
map_posy = map_posy - (oldmy-g_MouseY)
end
oldmx = g_MouseX
oldmy = g_MouseY
SetSpritePosition(cursor_sprite,g_MouseX,g_MouseY)
end
end
else
DeactivateMouse(e)
SetSpritePosition(cursor_sprite,200,200)
end
end--moveable map
else
posx = ((g_PlayerPosX - game_map_size_min_x)/(game_map_size_max_x - game_map_size_min_x)) * 100
posy = ((g_PlayerPosZ - game_map_size_min_z)/(game_map_size_max_z - game_map_size_min_z)) * 100
iposx = (posx*(map_image_size_x / 100))+map_posx
iposy = ((map_image_size_y-((posy*(map_image_size_y / 100))))+map_posy)
if fog == 1 then
fogx = map_posx
fogy = map_posy
fx = 0
for a = 1, fog_in_row*fog_in_column do
if fog_sprite[a] ~= nil then
if fx > 0 then
if fx < fog_in_row then
fogx = fogx + (map_image_size_x/fog_in_row)
else
fogx = map_posx
fogy = fogy + (map_image_size_y/fog_in_column)
fx = 0
end
end
if fog_explored[fog_sprite[a]] == 0 then
--SetSpritePosition(fog_sprite[a],fogx,fogy)
end
fx = fx + 1
if fogx + ((map_image_size_x/fog_in_row)/2) > iposx - (map_image_size_x/fog_in_row) and fogx + ((map_image_size_x/fog_in_row)/2) < iposx + (map_image_size_x/fog_in_row) and fogy + ((map_image_size_y/fog_in_column)/2) > iposy - (map_image_size_y/fog_in_column) and fogy + ((map_image_size_y/fog_in_column)/2) < iposy + (map_image_size_y/fog_in_column) then
if fog_restore == 0 then
fog_explored[fog_sprite[a]] = 1
end
SetSpritePosition(fog_sprite[a],200,200)
end
end
end
end --fog
end --map on screen
end --images loaded
if GetScancode() == 0 then
pressed = 0
end
end --main
function map_exit(e)
end
life\'s one big game
windows vista ultimate
i5 @3.3ghz, 4gb ram, AMD R9 200 series , directx 11