LUA Resources, Help and a tiny Beginners Guide by enclave
Moderator: Forum Moderators
Re: LUA Resources, Help and a tiny Beginners Guide by enclav
woooohoooooo gfgtdf you are great!
your approach is not what I could see in wiki or in eohs codes or somewhere else.. it's different! And I think it's just what i needed!
Your code worked brilliantly for me:
And after your message I think I now understand how it works and what to do to achieve what I want.. ! Or at least I'm much closer to understanding! Thanks!
PS. This is so great!!!!!! Can't thank you enough
This is working perfectly fine =] It inserts a new table element in the end of old unit weapons! (funny thing is that with select event it keeps adding this image after each click) And what makes me really happy, is that I understand how it works now!!! Your answer should be in wiki instead of what they put there.. it is clearer than anything... And I can finally rest. Will experiment more with it tomorrow.. Thanks!
You already gave me all the information I need, but maybe you also know how to replace particular part of old wml?
table.insert(oldvalue,newtag) - can it be inserted into particular place of oldvalue table?
can some particular part of oldvalue table be erased?
your approach is not what I could see in wiki or in eohs codes or somewhere else.. it's different! And I think it's just what i needed!
Your code worked brilliantly for me:
Code: Select all
wesnoth.theme_items.unit_weapons = function()
return {
T.element {
image="items/archery-target-right.png~CROP(25,28,25,28)~SCALE(25,25)"
}
}
end
PS. This is so great!!!!!! Can't thank you enough
Code: Select all
local old_unit_weapons = wesnoth.theme_items.unit_weapons
wesnoth.theme_items.unit_weapons = function()
local oldvalue = old_unit_weapons()
local newtag = T.element { image="items/archery-target-right.png~CROP(25,28,25,28)~SCALE(25,25)",
tooltip="hrenj" }
table.insert(oldvalue,newtag)
return oldvalue
end
You already gave me all the information I need, but maybe you also know how to replace particular part of old wml?
table.insert(oldvalue,newtag) - can it be inserted into particular place of oldvalue table?
can some particular part of oldvalue table be erased?
Re: LUA Resources, Help and a tiny Beginners Guide by enclav
table.insert(oldvalue, pos, newtag)
can insert the new tag at a given position pos, for example table.insert(oldvalue, 1, newtag)
will insert t the new tag at the top, table.remove(oldvalue, pos)
can remove subtag number pos, for example table.remove(oldvalue, 1)
will remove the first element of oldvalue.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.
Re: LUA Resources, Help and a tiny Beginners Guide by enclav
Thanks so much gfgtdf!!!!
Updated this post to say thank you so much again!!!
And here is a piece of code that is tested and works for me, it displays a new kind of attack for my custom ranged units:
the following line was needed to avoid lua errors:
it means "if there is no displayed unit then"..
if you put the code into start event, then when it starts there is no displayed unit in the right-hand side panel.. and therefore wunit = nil.. and when we are trying to get variables out of it, it says it can not index nil value..
if you leave the code in select event then every time you click, it inserts the image and your custom text into the displayed unit.. so you will end up with 1 million images in your units right hand side panel..
to avoid that you would either need to create more if then.. or modify unit variables as they done.. and maybe it even wouldn't work. Or instead of "table.insert()", use something else.. so my solution was just to move my lua code to start event (prestart/preload should have same effect I believe).
Updated this post to say thank you so much again!!!
And here is a piece of code that is tested and works for me, it displays a new kind of attack for my custom ranged units:
Spoiler:
Code: Select all
if wunit ~= nil then
if you put the code into start event, then when it starts there is no displayed unit in the right-hand side panel.. and therefore wunit = nil.. and when we are trying to get variables out of it, it says it can not index nil value..
if you leave the code in select event then every time you click, it inserts the image and your custom text into the displayed unit.. so you will end up with 1 million images in your units right hand side panel..
to avoid that you would either need to create more if then.. or modify unit variables as they done.. and maybe it even wouldn't work. Or instead of "table.insert()", use something else.. so my solution was just to move my lua code to start event (prestart/preload should have same effect I believe).
Last edited by enclave on October 17th, 2016, 6:33 pm, edited 4 times in total.
Re: LUA Resources, Help and a tiny Beginners Guide by enclav
updated my previous post which contained an error.
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.
Re: LUA Resources, Help and a tiny Beginners Guide by enclav
This will create a new User Interface bar of resources on top of the screen..
I found that terrain is the best place for it, as it looks good and does not disturb anything.. really..
PS. you may see how it works on practice by downloading New Settlers add-on.
PPS. there may be issues with resource bar invisible for mac users. But I only have 1 such confirmation. Reasons unknown.
PPPS. I assume there may also be problems with seeing resource bar with very small resolutions.. But it's only a guess.
I found that terrain is the best place for it, as it looks good and does not disturb anything.. really..
Spoiler:
Code: Select all
[event]
name=turn refresh
first_time_only=yes
##
[lua]
code=<<
local old_display_terrain = wesnoth.theme_items.terrain
wesnoth.theme_items.terrain = function()
local oldvalue = old_display_terrain()
--
local whole_wml = wesnoth.theme_items.income()
local element_subtag = helper.get_child(whole_wml, "element")
local bcd1 = element_subtag.text
local bcd2 = string.gsub(bcd1, '<span foreground="#777777">', "")
local abc = string.gsub(bcd2, "</span>", "")
if abc ~= "0" then
local newtag1 = T.element { image="items/straw-bale1.png~SCALE(32,32)~CROP(7,7,18,18)~SCALE(18,18)",
tooltip="food" }
local newtag2 = T.element { text=wesnoth.get_variable("player["..abc.."].food").." ",
tooltip="Amount of food current side has"}
--
local newtag3 = T.element { image="terrain/forest/deciduous-summer-small.png~CROP(42,35,63,75)~SCALE(18,18)",
tooltip="wood" }
local newtag4 = T.element { text=wesnoth.get_variable("player["..abc.."].wood").." ",
tooltip="Amount of wood current side has"}
--
local newtag5 = T.element { image="scenery/rock2.png~CS(42,42,42)~CROP(12,17,53,40)~SCALE(16,16)",
tooltip="stone" }
local newtag6 = T.element { text=wesnoth.get_variable("player["..abc.."].stone").." ",
tooltip="Amount of stone current side has"}
--
local newtag7 = T.element { image="items/gold-coins-small.png~CROP(22,24,31,30)~SCALE(17,17)",
tooltip="gold" }
local newtag8 = T.element { text=wesnoth.get_variable("player["..abc.."].gold").." ",
tooltip="Amount of gold current side has"}
table.insert(oldvalue,1,newtag1)
table.insert(oldvalue,2,newtag2)
table.insert(oldvalue,3,newtag3)
table.insert(oldvalue,4,newtag4)
table.insert(oldvalue,5,newtag5)
table.insert(oldvalue,6,newtag6)
table.insert(oldvalue,7,newtag7)
table.insert(oldvalue,8,newtag8)
end
return oldvalue
end
>>
[/lua]
[/event]
Spoiler:
PPS. there may be issues with resource bar invisible for mac users. But I only have 1 such confirmation. Reasons unknown.
PPPS. I assume there may also be problems with seeing resource bar with very small resolutions.. But it's only a guess.