Settlers United Wiki
Settlers UnitedImprint
Settler IV Lua API DE
Settler IV Lua API DE
  • Tutorials
    • Einführung
    • SU Library
    • Erste Schritte
      • Einrichtung & HelloWorld
      • Einstieg: new_game
      • Events: register_functions
      • Siegbedingungen anpassen
    • Erweiterte Tipps
      • Die Vars.Save Variablen
      • Moderner Lua Compiler
      • S4Editor Export Path Changer
      • Anticheat
      • Löschen aller Gebäude
      • Platzieren von Gebäuden
    • Code Schnipsel
      • Soldatenanzahl ermitteln
      • Random innerhalb Bereich
      • Verbesserte Zufallszahlen
      • Neue Minute angebrochen
      • Round & Modulo
      • All Points in a circle (hexagon)
      • foreach_ext
      • Textnachricht nur für einen Spieler
      • Mehr als 8 Waren spawnen
    • Community Bibliotheken
      • MinuteEvents-Library
      • VarsSave-Extender
      • Ground-Library
    • Vollständige Mapscripts
      • Siedler IV WM 2021 "The Woods"
      • Turnier Map Script 2vs2 2022
  • Library Functions
    • Global Functions
      • new_game
      • reg_func
      • register_functions
      • request_event
      • unrequest_event
    • AI
      • AI.AttackNow
      • AI.DarkTribeUseDarkGardeners
      • AI.DarkTribeUseShamans
      • AI.NewSquad
      • AI.SetPlayerVar
    • Buildings
      • Buildings.AddBuilding
      • Buildings.Amount
      • Buildings.CrushBuilding
      • Buildings.Delete
      • Buildings.ExistsBuildingInArea
      • Buildings.GetFirstBuilding
      • Buildings.GetInhabitantAmount
      • Buildings.GetTarget
      • Buildings.IsSelected
    • DarkTribe
      • DarkTribe.AddManakopter
      • DarkTribe.FlyTo
    • Debug
      • Debug.AccessViolation
      • Debug.ActivateAI
      • Debug.DeactivateAI
      • Debug.FatalError
      • Debug.Freeze
      • Debug.MakeDark
      • Debug.MakeGreen
    • Effects
      • Effects.AddEffect
    • Game
      • Game.ArePlayerAreasConnected
      • Game.DefaultGameEndCheck
      • Game.DefaultPlayerLostCheck
      • Game.DefaultPlayersLostCheck
      • Game.DisableLastNPlayersInStatistic
      • Game.EnableLandExploredCheck
      • Game.EnemyPlayersLost
      • Game.FindAnyUnit
      • Game.GetAmountOfTreesInArea
      • Game.GetDifficulty
      • Game.GetNumberOfSquaresWithDarkLand
      • Game.GetOffenceFightingStrength
      • Game.HasPlayerLost
      • Game.IsAlmostAllLandExplored
      • Game.IsAreaDarkLand
      • Game.IsAreaGreen
      • Game.IsAreaOwned
      • Game.LocalPlayer
      • Game.NumberOfPlayers
      • Game.PlayerLost
      • Game.PlayerRace
      • Game.Random
      • Game.Random100
      • Game.ResetFogging
      • Game.SetAlliesDontRevealFog
      • Game.SetFightingStrength
      • Game.ShowClock
      • Game.ShowText
      • Game.Time
    • Goods
      • Goods.AddPileEx
      • Goods.Amount
      • Goods.Delete
      • Goods.GetAmountInArea
    • Magic
      • Magic.CastSpell
      • Magic.CurrentManaAmount
      • Magic.DecreaseMana
      • Magic.IncreaseMana
    • Map
      • Map.AddDecoObject
      • Map.DeleteDecoObject
      • Map.Height
      • Map.PointIsOnScreen
      • Map.SetScreenPos
      • Map.Width
    • Settlers
      • Settlers.AddSettlers
      • Settlers.AddSettlersToFerry
      • Settlers.Amount
      • Settlers.AmountInArea
      • Settlers.AmountInSector
      • Settlers.IsSelected
      • Settlers.KillSelectableSettlers
      • Settlers.ProductionAmount
      • Settlers.SetHealthInArea
    • Statistic
      • Statistic.BuildingsCaptured
      • Statistic.GoodsProduced
      • Statistic.LandOwnedByPlayer
      • Statistic.ManaCollected
      • Statistic.MushroomFarmsDestroyed
      • Statistic.ServantsFreed
      • Statistic.SpellsCast
      • Statistic.UnitsDestroyed
    • Tutorial
      • Tutorial.ClearMarker
      • Tutorial.DeleteWorldCursor
      • Tutorial.DisableControls
      • Tutorial.DisableExcept
      • Tutorial.EnableAllControls
      • Tutorial.EnableControls
      • Tutorial.Exit
      • Tutorial.GetCurrentZoomFactor
      • Tutorial.PressButton
      • Tutorial.RWM
      • Tutorial.SelectNextBuilding
      • Tutorial.SetMarker
      • Tutorial.SetWorldCursor
      • Tutorial.SetZoom
      • Tutorial.ShowText
      • Tutorial.Won
    • Vehicles
      • Vehicles.AddVehicle
      • Vehicles.AddWheelerToFerry
      • Vehicles.Amount
      • Vehicles.AmountInArea
      • Vehicles.AmountInSector
      • Vehicles.GetFerryCargoInArea
      • Vehicles.GetHealth
      • Vehicles.IsSelected
      • Vehicles.KillVehicles
    • dbg
      • dbg.aioff
      • dbg.aion
      • dbg.db
      • dbg.pi
      • dbg.sg
      • dbg.stm
      • dbg.tp
  • SU Library Functions
    • SU.VersionOK
    • SU.Buildings
      • SU.Buildings.AddBuilding
      • SU.Buildings.AddBuildingEx
      • SU.Buildings.AddConstructionSite
      • SU.Buildings.AddConstructionSiteEx
      • SU.Buildings.GarrisonWarriors
      • SU.Buildings.GetConstructionState
      • SU.Buildings.GetHaltedState
      • SU.Buildings.GetPriorityState
      • SU.Buildings.RecruitVehicle
      • SU.Buildings.RecruitWarriors
      • SU.Buildings.SetHaltedState
      • SU.Buildings.SetPriorityState
      • SU.Buildings.SetProduction
      • SU.Buildings.SetProductionPercentMode
      • SU.Buildings.SetProductionPercentage
      • SU.Buildings.SetTradingRoute
      • SU.Buildings.SetWorkarea
      • SU.Buildings.StartPlacement
      • SU.Buildings.StoreGood
      • SU.Buildings.ToggleHalt
      • SU.Buildings.TogglePriority
      • SU.Buildings.TradeGood
      • SU.Buildings.UnGarrisonWarriors
    • SU.Entity
      • SU.Entity.GetBaseType
      • SU.Entity.GetClass
      • SU.Entity.GetEntityType
      • SU.Entity.GetHealth
      • SU.Entity.GetMaxHealth
      • SU.Entity.GetNextEntityID
      • SU.Entity.GetOwner
      • SU.Entity.GetPosition
      • SU.Entity.GetPreviousEntityID
      • SU.Entity.GetRoleClass
      • SU.Entity.GetTribe
      • SU.Entity.GetType
      • SU.Entity.GetUniqueID
      • SU.Entity.PileGetAmount
    • SU.Game
      • SU.Game.AddBeds
      • SU.Game.ClearSelection
      • SU.Game.GetLanguage
      • SU.Game.GetMapName
      • SU.Game.GetMapNameRelativePath
      • SU.Game.GetMaxSelection
      • SU.Game.IsCurrentlyOnScreen
      • SU.Game.Ping
      • SU.Game.PingPlayer
      • SU.Game.PingTeam
      • SU.Game.PingTeamOfPlayer
      • SU.Game.SetBeds
      • SU.Game.SetMaxSelection
      • SU.Game.ShowTextMessage
      • SU.Game.stm
    • SU.Goods
      • SU.Goods.AddPileEx
    • SU.Map
      • SU.Map.GetEcoSector
      • SU.Map.GetFogOfWar
      • SU.Map.GetHeight
      • SU.Map.GetObject
      • SU.Map.GetOwner
      • SU.Map.GetResource
      • SU.Map.GetType
      • SU.Map.IsDarkLand
      • SU.Map.IsDarkLandBorder
      • SU.Map.IsFoundingStone
      • SU.Map.IsOccupied
      • SU.Map.SetResource
    • SU.Settlers
      • SU.Settlers.AddSettlersIfNeeded
      • SU.Settlers.AddSettlersWithBeds
  • API Enums
    • AI
    • Buildings
    • Control
    • Dialog
    • Effects
    • Events
    • Game
    • Goods
    • Magic
    • Menu
    • Settlers
    • Sounds
    • Vehicles
  • SU API Enums
    • SU.Animals
    • SU.BaseTypes
    • SU.Classes
    • SU.EntityTypes
    • SU.Grounds
    • SU.GUIElements
    • SU.Languages
    • SU.Objects
    • SU.Resources
    • SU.RoleClasses
    • SU.Trees
    • SU.Tribes
Powered by GitBook
On this page
Edit on GitHub
  1. SU Library Functions
  2. SU.Entity

SU.Entity.GetUniqueID

SU Library: erst ab Version 0.2.0 verfügbar!

SU.Entity.GetUniqueID(entityID)

Gibt die "eindeutige ID" der Entität zurück - nicht in S4-Funktionen verwendet!

ACHTUNG: In Siedler 4 wird in allen Funktionen ausschließlich die "normale ID" (entityID) der Entity verwendet - nicht die hier zurückgegebene "eindeutige ID"!

Eine Entität ist alles, was im Spiel als "physisches Objekt" vorkommt: d.h. Objekte, Siedler, Gebäude, Fahrzeuge, Warenstapel, Tiere, etc., für Mapper also quasi alles Auswählbare (und noch mehr).

Hintergrund

Entitäten besitzen in Wirklichkeit zwei verschiedene IDs:

  • normale ID: Diese ID wird von allen Spiel-Funktionen verwendet. Sie ist zu einem bestimmten Zeitpunkt eindeutig, wird jedoch nach dem Tod der Entität wiederverwendet! → Das bedeutet: Wenn man eine normale ID über längere Zeit (z. B. über mehrere Ticks) speichert, kann man nicht garantieren, dass sie später noch zur gleichen Entität gehört!

  • eindeutige ID:

    Diese ID ist dauerhaft einzigartig und wird niemals erneut vergeben – sie bleibt also über die gesamte Laufzeit hinweg eindeutig.

Zweck dieser Funktion

Diese Funktion richtet sich speziell an Mapper, die normale IDs über längere Zeiträume speichern möchten und dabei sicherstellen wollen, dass eine gespeicherte ID immer noch zur ursprünglichen Entität gehört, um nicht alle paar Ticks wieder alle Entitäten durchiterieren zu müssen. Durch einen Abgleich zwischen vorheriger und jetziger eindeutigen ID kann diese Zuordnung überprüft werden.

Beispiel Skript
firstTowerID = 0
lastGameMinute = -1
idMap = {}

-- register pair {entityID, uniqueID}
function regID(entityID)
  local uniqueID = SU.Entity.GetUniqueID(entityID)
  if uniqueID ~= 0 then -- entity still exists
    idMap[entityID] = uniqueID
  end
end

-- checks if {entityID} is still valid (and was registered)
function checkID(entityID)
  local uniqueID = SU.Entity.GetUniqueID(entityID)
  if uniqueID ~= 0 then -- entity still exists
    local previousUniqueID = idMap[entityID]
    if previousUniqueID ~= nil then -- entityID was registered
      if previousUniqueID == uniqueID then
        return 1
      end
    end
  end
  return 0
end

function five_ticks()
  local time = Game.Time()
  if lastGameMinute ~= time then -- new minute
    lastGameMinute = time
    
    -- check if ID still valid
    if checkID(firstTowerID) == 0 then  -- NOT valid
      dbg.stm("ID is not longer valid!")
    else  -- valid
      dbg.stm("ID still valid!")
    end
  end
end

function new_game()
  -- don't add anything in this function above these lines
  if SU then
    local requiredVersion = "0.2.0" -- change this to the version your map-script requires
    if SU.VersionOK(requiredVersion) == 0 then
      dbg.stm("SU Library Version requirement not met! The Map-Script needs at least Version "..requiredVersion..", you have Version "..SU.VERSION.."!")
      dbg.stm("Update (and restart The Settlers IV via) Settlers United to get the latest Version installed.")
      return
    end
  else
    dbg.stm("SU Library is missing!")
    dbg.stm("Update (and restart The Settlers IV via) Settlers United to get the latest Version installed.")
    return
  end
  
  -- SU Library loaded and required Version fulfilled
  -- add your normal code here...
  firstTowerID = Buildings.GetFirstBuilding(1, Buildings.GUARDTOWERSMALL)
  regID(firstTowerID)
  
  request_event(tick, Events.FIVE_TICKS)
end

function register_functions()
  reg_func(five_ticks)
end

Parameter

  • entityID: ID der Entität

Rückgabewert

  • "eindeutige ID" der Entität

Beispiel

local uniqueID = SU.Entity.GetUniqueID(entityID)
PreviousSU.Entity.GetTypeNextSU.Entity.PileGetAmount

Last updated 1 month ago