-- FallOut4 Style HUD using text and sprites -- Also uses Ravey & !nullptr refactored code -- By cybernescence (JAN 2016) --position of NAV HUD - screen %---------------------------------------------------------------- barY =90 -- this is the only one to adjust as items may move off screen horizontally otherwise barX =50 --health bar------------------------------------------------------------------------------------ playerMaxHealth = 500 -- set to -1 to default to using the player start marker health as the max --objectives------------------------------------------------------------------------------------ noSeqObjectives = 1 -- number of sequential objectives to show as well as primary objectReachedIfWithin = 200 --if player gets within this distance of objective, next one is set ------------------------------------------------------------------------------------------------ ----------------------- radarFoundEnemies = 0 enemyCount = 0 objectiveCount = 0 radarEnemies = {} radarObjectives = {} radarEnemySprites = {} radarObjectiveSprites = {} radarObjectiveSpritesNP = {} radarSprite = 0 compassText= {} compass_bar = "" radarImageRed = 0 radarImageGreen = 0 radarImageYellow = 0 innerHealth = 0 baseBarH = 0 max_health = 0 waitForAllEntities = 1 objectiveTarget = 1 function radar2_init(e) baseBarimage = LoadImage ( "scriptbank\\radar\\FO4BaseBar.png" ) baseBarH = CreateSprite ( baseBarimage ) SetSpriteDepth ( baseBarH , 99 ) SetSpriteSize ( baseBarH , 20 , -1 ) SetSpritePosition ( baseBarH ,barX-42 , barY-3.5) -- baseBarN = CreateSprite ( baseBarimage ) SetSpriteDepth ( baseBarN , 99 ) SetSpriteSize ( baseBarN , 32.5 , 7 ) SetSpritePosition ( baseBarN ,barX-16.1 , barY-4) innerHealthimage = LoadImage ( "scriptbank\\radar\\FO4HealthInner.png" ) innerhealth = CreateSprite ( innerHealthimage ) SetSpriteDepth ( innerhealth , 90 ) SetSpriteSize ( innerhealth , 20 , 6.5 ) SetSpritePosition ( innerhealth ,200 , 200 ) --off screen for a = 1, 100 do --assumes no more than 100 radarObjectives[a] = {eNum=0; objectPriority=0; objectName="";} end radarImageRed = LoadImage ( "scriptbank\\radar\\radar-red.png" ) radarImageGreen = LoadImage ( "scriptbank\\radar\\radar-green.png" ) radarImageYellow = LoadImage ( "scriptbank\\radar\\FO4ObjMarker.png" ) radarImageYellowNonPrimary = LoadImage ( "scriptbank\\radar\\FO4ObjMarkerNP.png" ) --text compass heading (!nullptr code) for i=1, 360, 1 do if i == 1 then compassText[i] = "N" elseif i == 46 then compassText[i] = "NE" elseif i == 91 then compassText[i] = "E" elseif i == 136 then compassText[i] = "SE" elseif i == 181 then compassText[i] = "S" elseif i == 226 then compassText[i] = "SW" elseif i == 271 then compassText[i] = "W" elseif i == 316 then compassText[i] = "NW" elseif math.fmod(i,10) == 1 then compassText[i] = " " --"|" else compassText[i] = " " --"." end end end function radar2_main(e) ----------------------------------------------------- HideHuds() --ShowHuds() ----------------------------------------------------- if waitForAllEntities == 1 then waitForAllEntities = 0 return end --Display Ammo Counts --if g_PlayerGunAmmoCount > 0 or g_PlayerGunClipCount > 0 then if g_PlayerGunID ~= 0 then TextCenterOnXColor(barX+40,barY-10.5,1,g_PlayerGunAmmoCount,0,255,0) TextCenterOnXColor(barX+40,barY-9,1,"____",0,255,0) TextCenterOnXColor(barX+40,barY-6,1,g_PlayerGunClipCount,0,255,0) end -- --HP TextCenterOnXColor(barX-43,barY,3,"HP",0,255,0) if g_PlayerHealth <= 0 then playerMaxHealth = max_health SetSpriteSize ( innerhealth , 0 , 6.5 ) return end if playerMaxHealth == -1 then max_health = g_PlayerHealth playerMaxHealth = -2 elseif playerMaxHealth ~= -2 then max_health = playerMaxHealth SetPlayerHealth(max_health) playerMaxHealth = -2 end local perc = (g_PlayerHealth / max_health ) * 100 local healthBarwidth = (g_PlayerHealth/max_health) * 18.5 SetSpriteSize ( innerhealth , healthBarwidth , 6.5 ) SetSpritePosition ( innerhealth ,barX-41.3 , barY-3.6) -- --text compass local start=0 local compass_str="" local bearing=0 bearing = math.floor(math.fmod(g_PlayerAngY, 360)) if bearing < 0 then bearing=bearing+360 end if bearing < 45 then start = 315 + bearing else start=bearing-45 end local arraypos=start for i=1,91, 1 do if arraypos==360 or arraypos<=0 then arraypos=1 -- we reached end of table, reset else arraypos=arraypos+1 end compass_str=compass_str..compassText[arraypos] end TextCenterOnXColor(barX,barY+3,1,compass_str,0,255,0) TextCenterOnXColor(barX,barY+5,3,"^",0,255,0) --TextCenterOnXColor(barX+1,barY+5,2,bearing,0,255,0) -- --A lot of Ravey code follows 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] , 0.25 , -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 --enemies 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 > 3000 then dist = 3000 end x = barX + (( math.sin(angle) * ( dist / 80.0 ) * (GetDeviceHeight()/GetDeviceWidth()) )) if x >=64.5 then x=64.5 end if x <=35.7 then x=35.7 end y = barY + ( math.cos(angle) * ( dist / 80.0 ) ) if math.floor(y) > barY then SetSpritePosition ( radarEnemySprites[c] , 200 , 200 ) else SetSpritePosition ( radarEnemySprites[c] , x , barY+0.5 ) end else SetSpritePosition ( radarEnemySprites[c] , 200 , 200 ) end end --objectives for c = 1 , objectiveCount do --if radarObjectives[c]['objectPriority'] == objectiveTarget then if radarObjectives[c]['objectPriority'] >= objectiveTarget and radarObjectives[c]['objectPriority'] <= (objectiveTarget+noSeqObjectives) then angle = pointAtPlayer(radarObjectives[c]['eNum']) + math.rad(g_PlayerAngY) dist = GetPlayerDistance(radarObjectives[c]['eNum']) --+ objectReachedIfWithin if dist > 3000 then dist = 3000 end x = barX + (( math.sin(angle) * ( dist / 80.0 ) * (GetDeviceHeight()/GetDeviceWidth()) )) if x >=65 then x=65 end if x <=35 then x=35 end y = barY + ( math.cos(angle) * ( dist / 80.0 ) ) if dist <= objectReachedIfWithin and radarObjectives[c]['objectPriority'] == objectiveTarget then ----------OBJECTIVE REACHED! dist=0 --select next objective objectiveTarget = objectiveTarget + 1 if objectiveTarget > objectiveCount then --PromptDuration("All Done!", 5000) end SetSpritePosition ( radarObjectiveSprites[c] , 200 , 200 ) SetSpritePosition ( radarObjectiveSpritesNP[c] , 200 , 200 ) return -- end if math.floor(y) > barY then --ie objective behind player --may want to do something perhaps SetSpritePosition ( radarObjectiveSprites[c] , 200 , 200 ) SetSpritePosition ( radarObjectiveSpritesNP[c] , 200 , 200 ) else --ie objective in front of player if radarObjectives[c]['objectPriority'] == objectiveTarget then if dist >= 3000 then TextCenterOnXColor(x,barY-4,1,"+",0,250,0) else TextCenterOnXColor(x,barY-4,1,math.floor(dist/10),0,250,0) end SetSpritePosition ( radarObjectiveSprites[c] , x , barY-1 ) SetSpritePosition ( radarObjectiveSpritesNP[c] , 200 , 200 ) else SetSpritePosition ( radarObjectiveSpritesNP[c] , x , barY-1 ) end end 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 function addObjective2 (i,objPriority) objectiveCount = objectiveCount + 1 radarObjectives[objectiveCount]['eNum'] = i radarObjectives[objectiveCount]['objectPriority'] = objPriority radarObjectiveSprites[objectiveCount] = CreateSprite( radarImageYellow ) SetSpriteOffset ( radarObjectiveSprites[objectiveCount] , 1 , -1 ) SetSpritePosition ( radarObjectiveSprites[objectiveCount] , 200 , 200 ) radarObjectiveSpritesNP[objectiveCount] = CreateSprite( radarImageYellowNonPrimary ) SetSpriteOffset ( radarObjectiveSpritesNP[objectiveCount] , 1 , -1 ) SetSpritePosition ( radarObjectiveSpritesNP[objectiveCount] , 200 , 200 ) end