Faction API
Faction exposes diplomacy helpers and faction identification.
Reference
Identification
getFactionId()- Returns the numeric faction IDgetName()- Returns the faction’s display nameisNPCFaction()- Returns true if this is an NPC faction
Diplomacy
isSameFaction(otherFaction)- Check if two factions are the sameisFriend(otherFaction)- Check if friendly relation existsgetFriends()- Get array of friendly factionsisEnemy(otherFaction)- Check if hostile relation existsgetEnemies()- Get array of enemy factionsisNeutral(otherFaction)- Check if neutral relation exists
Examples
-- Get player's faction
playerShip = console.getEntity()
faction = playerShip:getFaction()
-- Check faction properties
print("Faction: " .. faction:getName())
print("Faction ID: " .. faction:getFactionId())
print("Is NPC: " .. tostring(faction:isNPCFaction()))
-- Check diplomatic relations
if faction:isFriend(otherFaction) then
print("We are friends!")
end
-- Iterate enemies
enemies = faction:getEnemies()
for i, enemy in ipairs(enemies) do
print("Enemy: " .. enemy:getName())
end