enclave's Lua thread

Discussion of Lua and LuaWML support, development, and ideas.

Moderator: Forum Moderators

Post Reply
Choicerer
Posts: 238
Joined: April 29th, 2017, 11:37 pm

Re: enclave's Lua thread

Post by Choicerer »

There are variables there, in [replay], [ai_something], [turn], but you can't retrieve them.
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: enclave's Lua thread

Post by gfgtdf »

yes the is afaik no way to to know on which turn the save was done when loading a replay.

What could maybe work do is to store the current time in the replay start, (assuming that on_save is also called when [replay_start] is created, not sure on that) and then refuse to load of that happend less that one hour ago. To get the current time you can probably use the lua is function
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: enclave's Lua thread

Post by Ravana »

os.time(os.date("!*t")) gives unix time as reported by local computer, so still possible to deceive it.
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: enclave's Lua thread

Post by gfgtdf »

well yes but as I understood it his point was just to make cheating a little harder.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Post by enclave »

gfgtdf thanks so much! it's a great idea! I will give it a try and report back!
Yeah removing cheating completely is impossible, I will not even go into details for all possible ways, but numbers of cheaters could be reduced by implementing some basic protection... for example when statistics were broken prior to 1.14.3 anyone could cheat with just looking statistics, it was very very simple, very fast, very tempting and some really strong players admitted that they either used it or it was very tempting to use it... 1.14.3 covered that bug, and I realized that cheating could become even a bit more complicated... the harder it is the less chance somebody would do it.. even if cheating would be reduced by 5% its a win :)
Ravana thanks very much for the date/time code, now you wrote it so i don't have to google for it anymore, could you please edit your post to just something like:
os.time(os.date("!*t")) gives unix time, still possible to deceive it.
? Just so nobody could find the workaround too easily, reading your original post gives a big hint on how to break it. Sorry for asking and thanks very much for understanding... =]
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: enclave's Lua thread

Post by Ravana »

If you know how to run command with different system time, then you know how to unpack savefiles and analyse them directly.
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Post by enclave »

Ravana wrote: July 9th, 2018, 2:38 pm If you know how to run command with different system time, then you know how to unpack savefiles and analyse them directly.
i was thinking that system time could be changed just with right clicking on time in bottom right corner of windows?
Choicerer
Posts: 238
Joined: April 29th, 2017, 11:37 pm

Re: enclave's Lua thread

Post by Choicerer »

What Ravana is talking about though, is starting Wesnoth in Unix, with a different system time than what is actually set.
Aside from that, yeah, you are right.
(Sometimes your OS might be set to sync the time with the Bios Time or from the Internet, but it doesn't take great skill to switch it off, I guess)
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Post by enclave »

gfgtdf wrote: July 8th, 2018, 7:42 pm yes the is afaik no way to to know on which turn the save was done when loading a replay.
What could maybe work do is to store the current time in the replay start, (assuming that on_save is also called when [replay_start] is created, not sure on that) and then refuse to load of that happend less that one hour ago. To get the current time you can probably use the lua is function
I have finally tried to do something like that, so far it didnt work..

Question: is there a WML/lua way to access the saved game file "date created" field? (This seems to be the only place where it displays time when loading game, so there would be a chance to compare the savefile creation time to current time if there was a function to do it?..)

Everything that happens during replay seems to happen in realtime.. So replay has it's own starting time, when you start the replay.. I couldn't find any variable that would store anything from original game.. doesnt look like there is anything that I could access..
I tried the code in the spoiler if you curious what exactly I tried to do.. (it doesnt even display any onsave message during replay, only during game)
Spoiler:
Something just came to my mind...
Question #2: Can I modify "mp_village_gold=2" variable from in game? or mp_num_turns?
I will test what effect it has on replay if i change turn limit... this could be the global variable I need if it works..
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: enclave's Lua thread

Post by Ravana »

No. Access to files is very limited.

Village gold and turn limit can be changed during game.
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Post by enclave »

gfgtdf wrote: July 8th, 2018, 7:42 pm yes the is afaik no way to to know on which turn the save was done when loading a replay.
What could maybe work do is to store the current time in the replay start, (assuming that on_save is also called when [replay_start] is created, not sure on that) and then refuse to load of that happend less that one hour ago. To get the current time you can probably use the lua is function
I have finally tried to do something like that, so far it didnt work..

Question: is there a WML/lua way to access the saved game file "date created" field? (This seems to be the only place where it displays time when loading game, so there would be a chance to compare the savefile creation time to current time if there was a function to do it?..)

Everything that happens during replay seems to happen in realtime.. So replay has it's own starting time, when you start the replay.. I couldn't find any variable that would store anything from original game.. doesnt look like there is anything that I could access..
I tried the code in the spoiler if you curious what exactly I tried to do.. (it doesnt even display any onsave message during replay, only during game)
Spoiler:
Something just came to my mind...
Question #2: Can I modify "mp_village_gold=2" variable from in game? or mp_num_turns?
I will test what effect it has on replay if i change turn limit... this could be the global variable I need if it works..

Question #3 when choosing replay file to load, it shows "difficulty: medium" is there a way to change or access that value in game?
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Post by enclave »

Hi, I tried to port somebody's else add-on/campaign to 1.14 (from 1.10) and it apparently gives this error message (log):

Code: Select all

20181206 17:40:22 error scripting/lua: In function lua_kernel::run(): Lua Error:
  When executing, Lua runtime error: ~add-ons/Cities_of_the_Frontier/lua/utils.lua:12: attempt to call a nil value (field 'register_wml_action')
stack traceback:
	~add-ons/Cities_of_the_Frontier/lua/utils.lua:12: in main chunk
	[C]: in field 'dofile'
	[string "wesnoth.dofile '~add-ons/Cities_of_the_Fronti..."]:1: in main chunk
Invalid WML found: unknown conditional wml: [message]
20181206 17:51:34 error ai/engine/cpp: side 3 : UNKNOWN goal[protect_my_unit]
Invalid WML found: [save_map] not supported
20181206 18:13:31 error scripting/lua: In function lua_kernel::run(): Lua Error:
  When executing, Lua runtime error: ~add-ons/Cities_of_the_Frontier/lua/utils.lua:12: attempt to call a nil value (field 'register_wml_action')
stack traceback:
	~add-ons/Cities_of_the_Frontier/lua/utils.lua:12: in main chunk
	[C]: in field 'dofile'
	[string "wesnoth.dofile '~add-ons/Cities_of_the_Fronti..."]:1: in main chunk
20181206 18:13:31 warning unit: Unknown attribute 'previous_recruits' discarded.
Invalid WML found: [load_map] not supported
It looks to me that I just need to change the "register_wml_action" code to make it work correctly, but could you tell me if there is also a problem to perform "dofile" and I need to change the dofile code too? I can't understand lua errors well.. Thanks in advance.
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: enclave's Lua thread

Post by Ravana »

This message says that something.register_wml_action should be a function, but it is nil.
fiestaman
Posts: 3
Joined: February 18th, 2019, 1:41 am

Re: enclave's Lua thread

Post by fiestaman »

Has anyone found a fix for this bug yet?
User avatar
josteph
Inactive Developer
Posts: 741
Joined: August 19th, 2017, 6:58 pm

Re: enclave's Lua thread

Post by josteph »

wesnoth.register_wml_action was deprecated and removed. Someone is going to have to patch the addon to use some other wesnoth.foo function that hasn't been removed. (Or it might be possible to reimplement register_wml_action as a wrapper around some other wesnoth.foo function.)

As a workaround, you can play the addon on 1.10. (I don't know if it works on 1.12.)
Post Reply