enclave's Lua thread

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

Moderator: Forum Moderators

Post Reply
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Post by enclave »

Another question.

Is there a function in either WML or Lua which would let me replace the original image of a unit without [unit_type]?
WML: I could guess that there is a chance that somehow I could do it with [object][effect]..? But would it erase the original image anyhow? I dont think so? I really would not like to use fog clearer if there is a chance not to do so.. is there?
LUA: Maybe there is something in Lua for that purpose? Basically i would like to change appearance of mage to start with.. I can not use [unit_type] because it requires players to have add-on to play it.

I guess I could use fog clearer and even would be able to make custom animations to these units.. using [object][effect] but is there any other way? To work on "type=mage" unit.. I don't think that ~MASK or anything else would be able to remove/replace/modify the "units/human-magi/mage.png" original image.. or is there a way? I mean ~BLIT can cover some parts on top of original image, but can anything erase the parts of it? How teleport animation works? ( I've seen teleport mask in core images.. but i never seen teleport in action maybe.. is it erasing or making transparent original image somehow?) How are leader ellipses drawn via Lua?

Thank you!
User avatar
Ravana
Forum Moderator
Posts: 3000
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: enclave's Lua thread

Post by Ravana »

EoHS changes these images with lua, if you want lua specifically you can try look there.

With wml you can achieve effect like http://puu.sh/hJWLg/c4b8a87172.jpg with

Code: Select all

		[object]
			[filter]
			[/filter]
			silent=yes
			[effect]
				apply_to=image_mod
				replace="O(0)"
			[/effect]
			[effect]
				apply_to=image_mod
				add="BLIT(units/monsters/water-serpent-attack-se-1.png)"
			[/effect]
		[/object]
This O(0) basically deletes original image.

With this way only be careful that the original image needs to be same size as the only you place on it.

For my use there object is best way as it remains after unit advances.
User avatar
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: enclave's Lua thread

Post by Elvish_Hunter »

enclave wrote:LUA: Maybe there is something in Lua for that purpose? Basically i would like to change appearance of mage to start with.. I can not use [unit_type] because it requires players to have add-on to play it.
I think that the easiest way will be tto use wesnoth.add_modifications, which works in the same way as [object] [effect].
enclave wrote:I don't think that ~MASK or anything else would be able to remove/replace/modify the "units/human-magi/mage.png" original image.. or is there a way?
Perhaps you can try acquiring the unit with wesnoth.get_units, get its .__cfg field (local u = unit.__cfg), set u.image to another image, then unstore the unit with wesnoth.put_unit. I never tried this, so it may not work at all.
enclave wrote:How are leader ellipses drawn via Lua?
They aren't. Leader and nozoc ellipses are handled directly by the C++ code.
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Post by enclave »

Thank you so much Ravana and Elvish_Hunter, you gave me many great options both Lua and WML!
Must admit Ravana's way looks the easiest for my level of knowledge. I hope these replies will help 1000s of other people who will be searching for similar things.. Will write back if it worked ok for me, but it already looks like it wil be able to solve all my troubles. Thanks again!
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Post by enclave »

Ravana, since your version of image replace code was the best suitable for me, question to you:

Taking as example your water-serpent example.. Do you know if there is a way to ~BLIT something on the image with magenta color, which would automatically convert magenta into side color.. (for example serpent's head I would paint into magenta somehow).. would it convert into team color or the only way to do it automatically team-colored is to use manual way like {TEAMCOLOR_ID} or some self-made macro.. (in my case like this: ~RC(flag_green>$player[$leader_position[$i].side].color) where I used pre-calculated $variable to change green flag into side color..)

So my question in short sounds like:
if I paint unit's part into magenta, through the [object].. image_mod ..., is there a way to automatically convert it into team color, or I must use things like ~RC(magenta>$team_color} because the wesnoth core system would not convert it automatically?

Thank you!

PS. i made a serpent on top of mage unit type.. so funny when it acts like a mage.. shooting fire.. :) thx Ravana

PPS. funny thing i noticed is that
1) if you put image overlay by object, then it flips if unit is moving.. so if u put item overlay in right hand, then after unit moved opposite direction it will be automatically be in the left hand.. so unit always looks same.. its good! its more professional way to do it..
2) if you use just [unit_overlay] then the item is always staying same place.. which may also be good in some case.. for example in my case item in right hand was not blocking the view on the health bar.. but in left hand it was... so I could see the health bar only partly.
So i think in some cases it would be wise to stick to mixing these 2 ways.. creating main unit as [object].. and his items in some cases as [unit_overlay]...
interesting..
with unit_overlay I had to use image="misc/blank-hex.png" and then ~BLIT my image on it.. to be able to specify coordinates, so together it looked like

Code: Select all

image="misc/blank-hex.png~BLIT(
	flags/knalgan-flag-1.png~CS(-40,-40,-40)~RC(flag_green>$player[$leader_position[$i].side].color)~CROP(50,10,20,50)
,40,5)"

PPPS. it is so strange.. i was sure first time it convered my unit from magenta to team color without any modifications.. but now it doesnt :( now i need to use my $player[$leader_position[$i].side].color...... Should it convert magenta into team color automatically Ravana? what am i missing? :(
Last edited by Ravana on May 14th, 2015, 12:59 pm, edited 1 time in total.
Reason: Removed colors. Suggested alternative readable format for image mod code.
User avatar
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: enclave's Lua thread

Post by Elvish_Hunter »

enclave wrote:Do you know if there is a way to ~BLIT something on the image with magenta color, which would automatically convert magenta into side color
Yes, there is: the ~TC() function. Clearly, it may become confusing if you don't use the default side colors, but if do your code:

Code: Select all

~RC(flag_green>$player[$leader_position[$i].side].color)
may become something like this (I don't know how your array is structured, so I'm guessing):

Code: Select all

~TC($leader_position[$i].side, flag_green)
enclave wrote:~BLIT something on the image with magenta color, which would automatically convert magenta into side color
If you look here, you'll see that the TC and RC functions are always applied before any other function. So, my guess is that you'll have to TC or RC each element of the image.
enclave wrote:I must use things like ~RC(magenta>$team_color} because the wesnoth core system would not convert it automatically?
You must use TC or RC (as I said, TC looks like is better suited for your case). The units themselves are team colored through the {MAGENTA_IS_THE_TEAM_COLOR} macro, which in turn uses the flag_rgb= key. So no, it isn't automatic.
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
User avatar
Ravana
Forum Moderator
Posts: 3000
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: enclave's Lua thread

Post by Ravana »

I do not know about image mods that much, only what I have read from EoHS(like water serpent) or used in addon icon(for xp mod). Therefore I cant really answer these questions.

You should not use this much colors however. Especially dark red, it is too similar to the one used for commit info. For readability you can place image mod code on multiple lines.
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Post by enclave »

Thank you Elvish_Hunter and Ravana!
Elvish_Hunter, I couldn't understand what is the difference between RC and TC from reading help... what is the largest main difference?
User avatar
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: enclave's Lua thread

Post by Elvish_Hunter »

enclave wrote:Elvish_Hunter, I couldn't understand what is the difference between RC and TC from reading help... what is the largest main difference?
If you want to indicate the new color using the team number, then TC is the best choice.
If you want to indicate the new color using a color name, then RC is the best choice.
Once again, it depends pretty much on the structure of your $player array.
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Post by enclave »

Do you mean that ~TC(1,magenta) means magenta turns into red
and then if I use ~RC(magenta>red) is the same..
is this how TC works?

if yes, then what would happen if host specified player 1 as orange? will ~TC(1,magenta) turn into orange?

Thanks!
User avatar
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: enclave's Lua thread

Post by Elvish_Hunter »

enclave wrote:Do you mean that ~TC(1,magenta) means magenta turns into red
and then if I use ~RC(magenta>red) is the same..
is this how TC works?
Correct. :)
enclave wrote:if yes, then what would happen if host specified player 1 as orange? will ~TC(1,magenta) turn into orange?
Given that ImagePath functions are available at any moment, even when no team is defined (think for example at the campaign selection dialog, where campaign icons can be altered using these functions), I'm quite sure that ~TC(1,magenta) will always convert magenta to red.
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Post by enclave »

so if I understand you right, there is no point to use ~TC when you can not be 100% sure that host hasn't changed the colors? Otherwise red may have orange images.. or black.. or brown.. or blue or any other.. :)
but you still can use ~TC if you prefer using numbers instead of words :D ?
User avatar
Elvish_Hunter
Posts: 1575
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: enclave's Lua thread

Post by Elvish_Hunter »

enclave wrote:so if I understand you right, there is no point to use ~TC when you can not be 100% sure that host hasn't changed the colors? Otherwise red may have orange images.. or black.. or brown.. or blue or any other.. :)
but you still can use ~TC if you prefer using numbers instead of words :D ?
Think of "1" as a synonymous for "red", "2" for "blue" and so on. :)
The palettes are defined in the data/team-colors.cfg file. This is why even ~RC supports numeric values, although our wiki says that it's better to avoid them in ~RC.
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Post by enclave »

Thank you very much Elvish_Hunter!
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: enclave's Lua thread

Post by enclave »

Sorry if I write it in a wrong place, I'm not sure where is better.. from one point of view synchronized choice is lua.. so here is a right place.. from another point of view.. its related to OOS..

I'm observing replay of a game of my mod..
The players got OOS in turn 1.. and again i see "calculated movement destination (x=39 y=7) didn't match the original destination (x=38 y=7)".. Why could it be?

I guess if somebody moves in a wrong place.. it means he has units in different places.. (I have no chance to check save game of each player unfortunately).

Could it be that [unit] may place unit in a different place for a different client if you specify x,y already taken by another unit?
I would like to put any suspicious commands into synchronized choice.. but I need to try to find out which ones are potentially dangerous..
I read from OOS help and your answerts that unsynced things are:
controller
events:
select
preload
victory
defeat
ai turn

is prestart synced? my placement of [unit] units is happening in prestart event.. should i put it with synchronized choice or move it to turn 1 or leaving it as is is safe? Any advices very much appreciated, thank you!!!
PS. also what could i sync for save game and then load game? all the time replay from reload is corrupted.
PPS. how to use this http://wiki.wesnoth.org/ReplayWML ??? where to put it? why? any information would help :) thanks!
PPPS. the latest bug I just got is: some OOSes.. and then I was offered to recruit a unit in a saved replay game.. ??? wth.. I was also able to recruit, but the units were becoming different color (becoming previous side's ownership on current side territory.. or similar.. hard to understand) and was given hell lot of other options, please check attachment for replay.. I think it is because by mistake they gave control to non-existing side in this particular case.. was 7 players, they gave observer control of side 8.. So i guess this particular replay is not bugged by code.. but by user's actions.. in the end of replay blue's units were in 4 different parts of world..
Attachments
NS_Random_Map_x9_Long_Turn_5_(51580).bz2
(82.86 KiB) Downloaded 370 times
Post Reply