sp00n
Prince
- Joined
- Jan 4, 2007
- Messages
- 371
Is there any decent way to detect when a city changes its owner? Or when it is razed?
There are events for CityAddedToMap and CityRemovedFromMap, and apparently a city is first "removed" from the map when being conquered, and then "added" back in when assigned to another player. The problem is that the cities don't have a global unique ID, they only have a player unique ID, i.e. that ID changes when another player takes control of the city, so you can't just compare the city ID from CityRemovedFromMap to the one from CityAddedToMap. Of course I could simply assume that if the two events happen in consecutive order, that a city has changed it's ownership, regardless of the city ID. But that seems like a very weak condition.
To make matters worse, once the city has been removed from the map, you can't even check if a new city is in that plot right now in the CityRemovedFromMap event function. Firstly, you cannot use Player:GetCities():FindID() request for that city ID, as the city just has been removed. And secondly, you also can't check if the plot currently has a city with Plot:IsCity() (if you somehow managed to the the x,y coordinations for this city before it was removed), apparently there really is no city before the CityAddedToMap event takes place.
Is there an established way to detect city ownership changes?
There are events for CityAddedToMap and CityRemovedFromMap, and apparently a city is first "removed" from the map when being conquered, and then "added" back in when assigned to another player. The problem is that the cities don't have a global unique ID, they only have a player unique ID, i.e. that ID changes when another player takes control of the city, so you can't just compare the city ID from CityRemovedFromMap to the one from CityAddedToMap. Of course I could simply assume that if the two events happen in consecutive order, that a city has changed it's ownership, regardless of the city ID. But that seems like a very weak condition.
To make matters worse, once the city has been removed from the map, you can't even check if a new city is in that plot right now in the CityRemovedFromMap event function. Firstly, you cannot use Player:GetCities():FindID() request for that city ID, as the city just has been removed. And secondly, you also can't check if the plot currently has a city with Plot:IsCity() (if you somehow managed to the the x,y coordinations for this city before it was removed), apparently there really is no city before the CityAddedToMap event takes place.
Is there an established way to detect city ownership changes?