Detect game reload

Define "reload"

If you mean "start a game, play some turns, save the game, exit civ, do something else, come back, start civ, reload saved game, continue playing", then yes

If however you mean "start a game, play some turns, save the game, play some more turns, don't like the outcome, reload the save, try a different strategy", with the aim to detect players "cheating", then, short answer, no.

A player can always rehash the second sequence as "start a game, play some turns, save the game, play some more turns, don't like the outcome, exit civ, start civ, reload the save, try a different strategy" which is indistinguishable from the first sequence.
 
OK. I figured it out. Here is the code in case someone else needs it:
Code:
	iCurTurn = Game.GetGameTurn() 
	if iTurnGameLoaded == nil then  -- iTurnGameLoaded is global
		iTurnGameLoaded = iCurTurn
	end
	if iCurTurn == iTurnGameLoaded  then 
		print ("game loaded this turn")
	end
Is this what you have in mind, Howard?
Cheating that you described can also be detected by saving number of turns played.
 
Cheating that you described can also be detected by saving number of turns played.

Unless you're using a secure third party remote server, I can always delete/edit any data you save onto my system
 
OK. I figured it out. Here is the code in case someone else needs it:
Code:
	iCurTurn = Game.GetGameTurn() 
	if iTurnGameLoaded == nil then  -- iTurnGameLoaded is global
		iTurnGameLoaded = iCurTurn
	end
	if iCurTurn == iTurnGameLoaded  then 
		print ("game loaded this turn")
	end
Is this what you have in mind, Howard?
Cheating that you described can also be detected by saving number of turns played.

Any code outside of a function in a lua file will execute as the game is loaded, so the above can be shortened to

Code:
print ("game loaded this turn")
 
If you only want to run some code as the game reloads, you know it only needs to run once, so shouldn't be checking every turn (waste of CPU cycles) but running the code directly as the game loads.
 
I don't quite understand the reasoning or intention behind this, but assuming you're trying to catch people who fall under whoward's "scenario two" of people loading an earlier save because they weren't satisfied with the outcome of some decision they made after the last game save, I don't think it's possible either.

Your proposed method won't actually persist the data inside either of your variables, which is why whoward says you may as well condense that whole thing into a single print statement saying that a game was loaded. I believe any data held in Lua is cleared when the script is "loaded."

One method around this would be to utilize the MapModData table, as this table is not cleared when reloading a game without quitting at least to the main menu. However, as whoward mentioned, once the player exits to the menu or exits the game completely, that table is also destroyed, and will no longer hold your data on game load.

Even assuming you were to utilize something like Pazyryk's TableSaverLoader to force saving the turn count data into the savegame database every turn, that still won't do much until the player executes an actual game save, so that the game can pack that database into the save file.

If you manage to pack it into the save file somehow without the player executing game saves on his own (setting aside autosaves) the player will simply run into 'future data' if they load the earlier save with your turn data force-packed into it.

Finally, assuming that you were able to do so, let's say that you are able to catch a player loading a turn 160 game save, when they became dissatisfied about the outcome of turn 180. What will you do?
 
I'm not trying to detect if player is cheating. I'm trying to find a simple way of detecting if a unit was created on current turn...
 
If that's the case, then why not use the unit method pUnit:GetGameTurnCreated()?
You can hook that into a loop over a player's units to find out when any of them were created, although I'm not entirely sure why this would be tied into a game reload. If the unit is created after a user has saved their game, and then they quit the game without saving again, the save file that they reload wouldn't have the unit in it until they pass the turn in which it needed to be created again.

Either way, that's one much simpler method to check for unit creation turn. Alternatively, if you want to hook up some data persistence into your script, you could store the turn number of a unit on its creation, although it's a bit risky here since a unit's ID can change. Still, this also would not have any effect on a reload unless the player executes a save post-creation.

Sorry, trying to help, but I'm having trouble understanding the what or why.
The best assumption I have is that you want some sort of effect on a unit a certain number of turns after its creation, and you need to be able to calculate the turn-count delay through game reloads.
 
I am using pUnit:GetGameTurnCreated(). I encountered a minor bug and to fix it I needed to detect if game was loaded on current turn.
Thanks for your replies.
 
pUnit:GetGameTurnCreated() works as expected. I have code that with 50% probability replaces any barbarian unit when it's created. The bug is If player reloads game the code fires again for units created on current turn.
 
If you have some code that you want to ensure is run once (and never more than once) per unit, you can give the unit a meaningless promotion after you run your code. And the code should only run if the unit it is looking at doesn't already have the promotion.

Or if you don't feel like writing all that, I've done it for you.
 
pUnit:GetGameTurnCreated() works as expected. I have code that with 50% probability replaces any barbarian unit when it's created. The bug is If player reloads game the code fires again for units created on current turn.
I for one can attest that using Machiavelli's system will cure that issue.
 
Back
Top Bottom