-- LUA Script, Player survival code --food entity numbers foodList = {} foodIndex = 1 foodCount = 3 --flag to read all soldiers locatedSoldiers = 0 --how many enemies we have survivalEnemyCount = 0 --array to hold entity list soldierList = {} --store time passed timeRead = 0 --how long befor player looses some health delayBeforeHealthLoss = 10000 --how much does the player loose howMuchHealthLost = 10 --flag for game over gameover = 0 --skip first run survivalSkipFirstLoop = 1 function survival_init(e) foodList [1] = 2 foodList [2] = 3 foodList [3] = 4 ShowHuds() end function survival_main(e) if survivalSkipFirstLoop == 1 then survivalSkipFirstLoop = 0 return end if g_PlayerHealth <= 0 and gameover == 0 then FreezePlayer () FreezeAI() HideHuds () gameover = 1 end if gameover == 0 then updateHealth() else Text (-1,50,3,"YOUDIED") end checkForFood() end function updateHealth() if timeRead == 0 then timeRead = g_Time end if g_Time - timeRead > delayBeforeHealthLoss then HurtPlayer (-1, howMuchHealthLost) timeRead = 0 end end function checkForFood() -- have we grabbed all enemies yet? if locatedSoldiers == 0 then survivalEnemyCount = 0 for c = 1, 300 do if ai_soldier_state[c] ~= nil then if g_Entity[c] ~= nil then survivalEnemyCount = survivalEnemyCount + 1 soldierList[survivalEnemyCount] = c end end end locatedSoldiers = 1 end --check if enemies have died, if so spawn food in if they have for c = 1 , survivalEnemyCount do if soldierList[c] ~= 0 then if g_Entity[soldierList[c]]['health'] <= 0 then x = g_Entity[soldierList[c]]['x'] y = g_Entity[soldierList[c]]['y'] z = g_Entity[soldierList[c]]['z'] SetPosition(foodList[foodIndex],x,y,z) foodIndex = foodIndex + 1 if foodIndex > foodCount then foodIndex = 1 end soldierList[c] = 0 end end end end