perelect wrote: "The problem was with the delete sprite command
so you need to replace... "DeleteSprite ( radarObjectiveSprites[c] )" with "SetSpritePosition ( radarObjectiveSprites[c], 200 , 200 ) "
Indeed, there was the problem
For the friends AI doesn't need (maybe just if their is killed in game), this modified script must be used
just to show the new enemies on the radar after the next spawn was activated (wave0, wave1, wave2 etc. in my map, as example).
So, I put here the last "radar_mod.lua" by @perelect for all there:
-- https://forum.game-guru.com/thread/214054
-- radar_mod.lua
-- Original Radar script using sprites
-- Modified to include Friendly AI, Collectable Objectives and to also remove friendly and objective images from radar once completed or destroyed
-- Modified by perelect 07/12/2015, updated 16/12/2015, updated 21/12/2015
radarFoundEnemies = 0
enemyCount = 0
objectiveCount = 0
friendlyCount = 0
radarEnemies = {}
radarObjectives = {}
radarFriendly = {}
radarEnemySprites = {}
radarObjectiveSprites = {}
radarFriendlySprites = {}
radarSprite = 0
radarImageBack = 0
radarImageRed = 0
radarImageGreen = 0
radarImageYellow = 0
aspectRatio = 0
waitForAllEntities = 1
function radar_mod_init(e)
radarImageBack = LoadImage ( "scriptbank\\radar\\radar-back.png" )
radarImageRed = LoadImage ( "scriptbank\\radar\\radar-red.png" )
radarImageGreen = LoadImage ( "scriptbank\\radar\\radar-green.png" )
radarImageYellow = LoadImage ( "scriptbank\\radar\\radar-yellow.png" )
radarSprite = CreateSprite ( radarImageBack )
SetSpriteDepth ( radarSprite , 100 )
end
function radar_mod_main(e)
SetSpriteSize ( radarSprite , 15 , -1 )
SetSpriteOffset ( radarSprite , 7.5 , -1 )
SetSpritePosition ( radarSprite , 90 - 0.7 , 15 ) -- the - 0.7 is to align the radar with other sprites -- a fine tune for my system
SetSpriteAngle ( radarSprite , -g_PlayerAngY )
if waitForAllEntities == 1 then
waitForAllEntities = 0
return
end
if radarFoundEnemies == 0 then
enemyCount = 0
for c = 1, 3000 do
if ai_soldier_state[c] ~= nil then
if g_Entity[c] ~= nil then
enemyCount = enemyCount + 1
radarEnemies[enemyCount] = c
radarEnemySprites[enemyCount] = CreateSprite( radarImageRed )
SetSpriteOffset ( radarEnemySprites[enemyCount] , 1 , 1 )
SetSpriteSize ( radarEnemySprites[enemyCount] , 0.5 , -1 )
SetSpritePosition ( radarEnemySprites[enemyCount] , 200 , 200 )
end
end
end
radarFoundEnemies = 1
end
newEntity = GetFirstEntitySpawn()
if newEntity ~= 0 then
if ai_soldier_state[newEntity] ~= nil then
if g_Entity[newEntity] ~= nil then
enemyCount = enemyCount + 1
radarEnemies[enemyCount] = newEntity
radarEnemySprites[enemyCount] = CreateSprite( radarImageRed )
SetSpriteOffset ( radarEnemySprites[enemyCount] , 0.25 , -1 )
SetSpriteSize ( radarEnemySprites[enemyCount] , 0.5 , -1 )
SetSpritePosition ( radarEnemySprites[enemyCount] , 200 , 200 )
end
end
end
for c = 1 , enemyCount do
if g_Entity[radarEnemies[c]]['health'] > 0 then
angle = pointAtPlayer(radarEnemies[c]) + math.rad(g_PlayerAngY)
dist = GetPlayerDistance(radarEnemies[c])
if dist > 2576 then
dist = 2576
end
x = 90 + (( math.sin(angle) * ( dist / 200.0 ) * (GetDeviceHeight()/GetDeviceWidth()) ))
y = 15 + ( math.cos(angle) * ( dist / 200.0 ) )
SetSpritePosition ( radarEnemySprites[c] , x , y )
else
SetSpritePosition ( radarEnemySprites[c] , 200 , 200 )
end
end
-- This section is for Objectives
for c = 1 , objectiveCount do
angle = pointAtPlayer(radarObjectives[c]) + math.rad(g_PlayerAngY)
dist = GetPlayerDistance(radarObjectives[c])
if dist > 2576 then
dist = 2576
end
x = 90 + (( math.sin(angle) * ( dist / 200.0 ) * (GetDeviceHeight()/GetDeviceWidth()) ))
y = 15 + ( math.cos(angle) * ( dist / 200.0 ) )
SetSpritePosition ( radarObjectiveSprites[c] , x , y )
-- This removes the objective image from the radar
if g_Entity[radarObjectives[c]]['health'] <= 0 or g_Entity[radarObjectives[c]]['collected'] == 1 then
--DeleteSprite ( radarObjectiveSprites[c] )
SetSpritePosition ( radarObjectiveSprites[c] , 200 , 200 )
end
end
-- This section is for Friendly AI
for c = 1 , friendlyCount do
angle = pointAtPlayer(radarFriendly[c]) + math.rad(g_PlayerAngY)
dist = GetPlayerDistance(radarFriendly[c])
if dist > 2576 then
dist = 2576
end
x = 90 + (( math.sin(angle) * ( dist / 200.0 ) * (GetDeviceHeight()/GetDeviceWidth()) ))
y = 15 + ( math.cos(angle) * ( dist / 200.0 ) )
SetSpritePosition ( radarFriendlySprites[c] , x , y )
-- This removes the friendly image from the radar
if g_Entity[radarFriendly[c]]['health'] <= 0 then
--DeleteSprite ( radarFriendlySprites[c] )
SetSpritePosition ( radarFriendlySprites[c], 200 , 200 )
end
end
end
function pointAtPlayer (i)
x = g_PlayerPosX - g_Entity[i]['x'];
z = g_PlayerPosZ - g_Entity[i]['z'];
angle = math.atan2( z , x );
angle = angle + (-90.0*0.0174533);
return angle;
end
-- This section is for Objectives
function addObjective (i)
objectiveCount = objectiveCount + 1
radarObjectives[objectiveCount] = i
radarObjectiveSprites[objectiveCount] = CreateSprite( radarImageYellow )
SetSpriteOffset ( radarObjectiveSprites[objectiveCount] , 1 , 1 )
SetSpriteSize ( radarObjectiveSprites[objectiveCount] , 0.5 , -1 )
SetSpritePosition ( radarObjectiveSprites[objectiveCount] , 200 , 200 )
end
-- This section is for Friendly AI
function addFriendly (i)
friendlyCount = friendlyCount + 1
radarFriendly[friendlyCount] = i
radarFriendlySprites[friendlyCount] = CreateSprite( radarImageGreen ) -- this sets friendly to the green image
SetSpriteOffset ( radarFriendlySprites[friendlyCount] , 1 , 1 )
SetSpriteSize ( radarFriendlySprites[friendlyCount] , 0.5 , -1 )
SetSpritePosition ( radarFriendlySprites[friendlyCount] , 200 , 200 )
end
Many thanks @perelect !
Smile today, tomorrow could be worse
http://bestradiolarry.ro/fps/
"The best forum, game software, operating system or web platform, it's that software which can give you most of the features and speed, not just amazing graphics."