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.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.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. Tutorials
  2. Code Schnipsel

Soldatenanzahl ermitteln

Mit diesen Funktionen könnt ihr die Anzahl an Soldaten einer Partei ermitteln.

Hiermit kannst du alle Soldaten getten, diese sich in einem Turm bzw. Burg befinden.

function getUnitsInBuildings(playerId)

Hiermit kannst du alle Soldaten außerhalb von Gebäuden getten.

getAmountOfPlayerUnitsWithoutBuildings(playerId)

Hiermit kannst du alle Soldaten, egal ob in oder außerhalb von Gebäuden, getten.

getAmountOfPlayerUnits(playerId) Wie verwende ich es? Bei den oben genannten Funktionen kannst du sie so verwenden wie sie dort stehen. Du musst nur playerId mit der Parteinummer ersetzten. Du musst nichts anderes machen, als die unten stehenden Logic's irgendwo hin zu copy pasten. Am besten, um die Ordnung beizubehalten, unter dem gesammten Script.

-- Gibt die Anzahl an Soldaten eines Spieler innerhalb seiner Tuerme und Burgen zureck
function getUnitsInBuildings(playerId)
	local allUnits = 0
	allUnits = allUnits + Buildings.Amount(playerId, Buildings.GUARDTOWERSMALL, Buildings.READY)
	allUnits = allUnits + Buildings.Amount(playerId, Buildings.GUARDTOWERBIG, Buildings.READY) * 6
	allUnits = allUnits + Buildings.Amount(playerId,Buildings.CASTLE, Buildings.READY) * 8
	return allUnits
end

-- gibt die Anzahl an Soldaten eines Spieler ohne die Soldaten innerhalb von Gebaeuden zurueck. 
function getAmountOfPlayerUnitsWithoutBuildings(playerId)
	local allUnitsWithoutBuilding = getAmountOfPlayerUnits(playerId)
	allUnitsWithoutBuilding = allUnitsWithoutBuilding - getUnitsInBuildings(playerId)
	return allUnitsWithoutBuilding
end 

-- gibt die Anzahl aller Soldaten eines Spielers zurueck
function getAmountOfPlayerUnits(playerId)
	local AmoutOfMilitary = 0
 	--Soldaten zaehlen	
	AmoutOfMilitary =  AmoutOfMilitary + Settlers.Amount(playerId, Settlers.SWORDSMAN_01) +  Settlers.Amount(playerId, Settlers.SWORDSMAN_02) + Settlers.Amount(playerId, Settlers.SWORDSMAN_03)
	-- Bogenschuetzen
	AmoutOfMilitary =  AmoutOfMilitary + Settlers.Amount(playerId, Settlers.BOWMAN_01) +  Settlers.Amount(playerId, Settlers.BOWMAN_02) + Settlers.Amount(playerId, Settlers.BOWMAN_03)
	-- Spezial Wiki
	AmoutOfMilitary = AmoutOfMilitary + Settlers.Amount(playerId, Settlers.AXEWARRIOR_01) + Settlers.Amount(playerId, Settlers.AXEWARRIOR_02) + Settlers.Amount(playerId, Settlers.AXEWARRIOR_03)
	-- Spezial Maya
	AmoutOfMilitary = AmoutOfMilitary + Settlers.Amount(playerId, Settlers.BLOWGUNWARRIORS_01) + Settlers.Amount(playerId, Settlers.BLOWGUNWARRIORS_02) + Settlers.Amount(playerId, Settlers.BLOWGUNWARRIORS_03)
	-- Spezial Trojaner
	AmoutOfMilitary = AmoutOfMilitary + Settlers.Amount(playerId, Settlers.BACKPACKCATAPULIST_01)	+ Settlers.Amount(playerId, Settlers.BACKPACKCATAPULIST_02) + Settlers.Amount(playerId, Settlers.BACKPACKCATAPULIST_03)
	-- Spezial Römer
	AmoutOfMilitary = AmoutOfMilitary + Settlers.Amount(playerId, Settlers.MEDIC_01) + Settlers.Amount(playerId, Settlers.MEDIC_02) + Settlers.Amount(playerId, Settlers.MEDIC_03)	
	-- Hauptmaenner
	AmoutOfMilitary = AmoutOfMilitary + Settlers.Amount(playerId, Settlers.SQUADLEADER) 	
	
	return AmoutOfMilitary 
end 
PreviousCode SchnipselNextRandom innerhalb Bereich

Last updated 1 month ago