enclave's WML Macros questions Thread
Moderator: Forum Moderators
Forum rules
- Please use [code] BBCode tags in your posts for embedding WML snippets.
- To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Re: enclave's WML Macros questions Thread
I have shortened it into 2 sections: (Can't tell if it is 100% bug free yet, need to run tests..)Ravana wrote: for 1.12 I did it, but it is a bit bothersome. You can see it in any ageless era game, when you quickly click and rightclick unit of 1) your side if you are player, 2) active side if you are observer; then it shows menu. Currently I use it mostly for changelogs, you can see how I have it done in https://github.com/ProditorMagnus/Agele ... g#L70-L102. Yes, it is quite complicated
Whoever likes to experiment with it can do following steps:
1) Add this event into your event list..
Spoiler:
Code: Select all
[event]
name=show_unsynced_menu ## put your own name here.. rename it..
first_time_only=no
[message]
speaker=narrator
caption= _ "Unsynced Menu" ## put your own info here.. rename it..
message= _ "Hello I am your unsynced menu" ## put your own info here.. rename it..
[option]
message="Do nothing and close this menu" ## put your own data here.. rename it
[command]
## put your command here..
[/command]
[/option]
## add more options..
[/message]
[/event]
Code: Select all
[lua]
code=<<
wesnoth.wml_actions.foreach_side = function(cfg)
local side_var = cfg.variable or "i"
for i, v in ipairs(wesnoth.sides) do
wesnoth.set_variable(side_var, v.side)
wesnoth.wml_actions.command(cfg)
end
end
function AE_condition_use_beta_features() --- possibly can remove this function (no idea yet)
return AE_use_beta_features == "use_beta_features"
end
local last_mouse_over_time
local mouseover_counter = 0
function wesnoth.game_events.on_event()
if wesnoth.current.event_context.name == "select" then
local time = wesnoth.get_time_stamp()
if last_mouse_over_time and ((time - last_mouse_over_time) > 2000) then
mouseover_counter = 0
unit1_moused_over_x = nil; unit1_moused_over_y = nil
unit2_moused_over_x = nil; unit2_moused_over_y = nil
end
last_mouse_over_time = time
local du = wesnoth.get_displayed_unit()
if du then
if (du.x == unit2_moused_over_x) and (du.y == unit2_moused_over_y) then
mouseover_counter = mouseover_counter + 1
unit1_moused_over_x = unit2_moused_over_x
unit1_moused_over_y = unit2_moused_over_y
unit2_moused_over_x = du.x
unit2_moused_over_y = du.y
if mouseover_counter > 2 then
mouseover_counter = 0
wesnoth.fire_event("AE_show_unsynced_menu") -- can rename this, but it should match event name
end
else
-- think here, mouseover_counter = 0
unit2_moused_over_x = du.x
unit2_moused_over_y = du.y
end
end
end
end
>>
[/lua]
I think I liked it more when you move your mouse in and out like in EoHS, but it doesn't matter.. at least this way it works!
SOoooooo..... I will post here what bugs or problems I will come across while using it.. what you need to be aware of..
or if I find ways to open this menu different way or with keyboard shortcuts or anything else.. or If I find anything else to add to this..
Thank you very much Ravana, it works for me and it is something to begin with!!!
I think this huge thing deserves a separate topic.. but who is looking I'm sure one will find..!
Re: enclave's WML Macros questions Thread
This part
deals with the beta feature(http://vgy.me/J1rK5Z.png) and version check(no more ageless era version conflicts in same game). Basically everyone who either modifies their persist file, or is directly given access(with [set_global_variable]) in game I host, can see the menu.
So there is no need to define foreach_side just for menu, and same for AE_condition_use_beta_features - that relies on unsynced local lua variables.
Edit: I wanted to have it work by hovering indeed, but didnt manage to figure out how. Though clicking has the bonus of also being available when side has only 1 unit.
Code: Select all
wesnoth.wml_actions.foreach_side = function(cfg)
local side_var = cfg.variable or "i"
for i, v in ipairs(wesnoth.sides) do
wesnoth.set_variable(side_var, v.side)
wesnoth.wml_actions.command(cfg)
end
end
function AE_condition_use_beta_features()
return AE_use_beta_features == "use_beta_features"
end
So there is no need to define foreach_side just for menu, and same for AE_condition_use_beta_features - that relies on unsynced local lua variables.
Edit: I wanted to have it work by hovering indeed, but didnt manage to figure out how. Though clicking has the bonus of also being available when side has only 1 unit.
Re: enclave's WML Macros questions Thread
Hello! version 1.12
1) ASAP: I'm trying to figure out if there is a way to access variables of this tag ingame..?
id or name?
like $multiplayer_side[1].name would give "Humans" as a result..?
any ideas? lua or wml.. doesnt matter..
2) not ASAP:
way to change name of leader as it appear in list? for example I change leader="Sergeant lol" but it won't let me do it.. because it will be unknown unit type.. is there workaround? lua.. or wml..
Thank you very much!
1) ASAP: I'm trying to figure out if there is a way to access variables of this tag ingame..?
Code: Select all
[multiplayer_side]
id=ns_humans
name={MENU_IMG_TXT "units/human-peasants/peasant.png" _"Humans"}
type=Sergeant
leader=Sergeant
[/multiplayer_side]
like $multiplayer_side[1].name would give "Humans" as a result..?
any ideas? lua or wml.. doesnt matter..
2) not ASAP:
way to change name of leader as it appear in list? for example I change leader="Sergeant lol" but it won't let me do it.. because it will be unknown unit type.. is there workaround? lua.. or wml..
Thank you very much!
Re: enclave's WML Macros questions Thread
Thanks Ravana! but I'm not sure how it works and if it works for what I need it to work..
I tried it like this:
but it returned error with bad argument to get_era "string expected got nil"
And if this is the way it should work it won't work for my purpose, because I need to find out for example side[3].name and not just name of id..
but i'm really confused.. because I dont understand how it works neither why it didn't work.
I tried it like this:
Code: Select all
[lua]
code = <<
wesnoth.set_variable("OGRES_NOOBS_NAME",wesnoth.get_era(nss_ogres_noobs).name)
>>
[/lua]
[message]
message="$OGRES_NOOBS_NAME"
[/message]
And if this is the way it should work it won't work for my purpose, because I need to find out for example side[3].name and not just name of id..
but i'm really confused.. because I dont understand how it works neither why it didn't work.
Re: enclave's WML Macros questions Thread
Tried like this also: wesnoth.set_variable("OGRES_NOOBS_NAME",wesnoth.get_era(New_Settlers_Mod).multiplayer_side[2].name)
same error..
same error..
Re: enclave's WML Macros questions Thread
You did not have the variable
Saying it simply, use quotes.
nss_ogres_noobs
or New_Settlers_Mod
defined, and in 1.12 Lua trying to evaluate undefined variable just fails silently, with 1.13 it says that variable not found.Saying it simply, use quotes.
Re: enclave's WML Macros questions Thread
Sorry, im.. tried like this:
same error..
what do i do wrong..?
sorry, lied.. different error - attempt to index multiplayer_side a nil value
Code: Select all
[lua]
code = <<
local hj="New_Settlers_Mod"
wesnoth.set_variable("ogres_noobs_name",wesnoth.get_era(hj).multiplayer_side[2].name)
>>
[/lua]
[message]
message="$ogres_noobs_name - multiplayer_side[2].name"
[/message]
what do i do wrong..?
sorry, lied.. different error - attempt to index multiplayer_side a nil value
Re: enclave's WML Macros questions Thread
See example from core file,
I do not know exactly how or why, but you might need to use helper.child_range.
Debug what result get_era gives, might be just different format.
Code: Select all
<<
local factions = wesnoth.get_variable("factions")
local function detect_faction(side_number)
local helper = wesnoth.require("lua/helper.lua")
for multiplayer_side in helper.child_range(factions, "multiplayer_side") do
local function recruits_match()
local count = 0
for searched in string.gmatch(multiplayer_side.recruit, "[^%s,][^,]*") do
count = count + 1
local found = false
for i, actual in ipairs(wesnoth.sides[side_number].recruit) do
if searched == actual then
found = true
break
end
end
if not found then return false end
end
return count == #wesnoth.sides[side_number].recruit
end
local function leader_matches()
local actual = wesnoth.get_units({ canrecruit = true, side = side_number })[1]
for searched in string.gmatch(multiplayer_side.leader, "[^%s,][^,]*") do
if searched == actual.type then return true end
end
end
if recruits_match() and leader_matches() then
wesnoth.set_variable("p" .. tostring(side_number) .. "_faction", multiplayer_side.id)
return
end
end
end
detect_faction(1)
detect_faction(2)
>>
Debug what result get_era gives, might be just different format.
Re: enclave's WML Macros questions Thread
Thanks Ravana!
If I ever need to use this thing, I will study it.. looks like there is variable "factions" because 1st string lua is getting something from $factions variable..
its too complicated.. I mean. i guess I don't need to understand how it works, just copy it.. but I don't like not to understand things.. and it will take time to understand this..
so I found workaround for my particular problem.. but if I ever need to use what I tried here, you gave me enough things to study, thank you very much for your time!
If I ever need to use this thing, I will study it.. looks like there is variable "factions" because 1st string lua is getting something from $factions variable..
its too complicated.. I mean. i guess I don't need to understand how it works, just copy it.. but I don't like not to understand things.. and it will take time to understand this..
so I found workaround for my particular problem.. but if I ever need to use what I tried here, you gave me enough things to study, thank you very much for your time!
Re: enclave's WML Macros questions Thread
Could somebody please have a look...
is there anything wrong with this code???
Thank you very much in advance..
PS. I mean not my own code.. with crop and things.. but the sequence of tags.. where im trying to change original animation to my own
is there anything wrong with this code???
Code: Select all
[effect]
apply_to=new_animation
[attack_anim]
## [filter_attack]
[attack_filter]
name = "cleaver"
[/attack_filter]
start_time=-325
[frame]
image="units/ogres/ogre-attack[1~5].png~CROP(17,12,48,48)~RC(magenta>$player[{SIDE}].color)~SCALE($SCALE_OGRE,$SCALE_OGRE):[75,100,75,175,100]"
[/frame]
{SOUND:HIT_AND_MISS axe.ogg {SOUND_LIST:MISS} -75}
[/attack_anim]
[/effect]
PS. I mean not my own code.. with crop and things.. but the sequence of tags.. where im trying to change original animation to my own
Code: Select all
[effect]
apply_to=new_animation
[attack_anim]
[attack_filter]
name = ...
[/attack_filter]
start_time=...
[frame]
image="..."
[/frame]
{SOUND:HIT_AND_MISS ... {SOUND_LIST:MISS} ...}
[/attack_anim]
[/effect]
Re: enclave's WML Macros questions Thread
attack_filter -> filter_attack, but no idea if it is the only problem.
Re: enclave's WML Macros questions Thread
tried changing that, didnt help..
its not a big deal that i cant make animation.. but i really would like to make one..
so if anyone could help me figure out why my unit can't have animation.. or how to make it have one, please help me..
i have used an effect before.. maybe it's the problem?
there is sound.. i think..but no picture..
Y.. I just tested without
and it seems to work.. even with blits and crops..
Any ideas what could make animation work? without excluding: [effect]apply_to=image_mod replace="O(0)"[/effect]
Or maybe other ways to replace image of units instead of replace="0(0)"?
Maybe layering? But i dont understand how to use it..
its not a big deal that i cant make animation.. but i really would like to make one..
so if anyone could help me figure out why my unit can't have animation.. or how to make it have one, please help me..
i have used an effect before.. maybe it's the problem?
Code: Select all
[unit]
...
[effect]
apply_to=image_mod
replace="O(0)"
[/effect]
...
[modifications]
[object]
silent=yes
[effect]
apply_to=new_animation
[attack_anim]
[filter_attack]
name=cleaver
[/filter_attack]
start_time=-325
[frame]
image="units/ogres/ogre-attack1.png:175"
## image_mod="~CROP(17,12,48,48)~RC(magenta>$player[{SIDE}].color)~SCALE($SCALE_OGRE,$SCALE_OGRE)"
[/frame]
[frame]
image="units/ogres/ogre-attack3.png:100"
image_mod="~CROP(17,12,48,48)~RC(magenta>$player[{SIDE}].color)~SCALE($SCALE_OGRE,$SCALE_OGRE)"
[/frame]
{SOUND:HIT_AND_MISS axe.ogg {SOUND_LIST:MISS} -75}
[/attack_anim]
[/effect]
...
[/unit]
Y.. I just tested without
Code: Select all
[effect]
apply_to=image_mod
replace="O(0)"
[/effect]
Any ideas what could make animation work? without excluding: [effect]apply_to=image_mod replace="O(0)"[/effect]
Or maybe other ways to replace image of units instead of replace="0(0)"?
Maybe layering? But i dont understand how to use it..
Re: enclave's WML Macros questions Thread
Does anyone know how to use it?
https://wiki.wesnoth.org/AnimationWML#Layering
Please just 1 simple example if you could...?
Thank you
https://wiki.wesnoth.org/AnimationWML#Layering
Please just 1 simple example if you could...?
Thank you
- beetlenaut
- Developer
- Posts: 2825
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: enclave's WML Macros questions Thread
From Bat_Blood.cfg:
Because layer is progressive, you can do something like
Code: Select all
[standing_anim]
layer=60
direction=s,se,sw
start_time=0
[frame]
image="units/undead/bloodbat-se-[3~1,2~5,4].png:[50,60,80,60,50,60,80,60]"
[/frame]
[/standing_anim]
layer=10~80
too.Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide