[solved] Weapon proxy

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

Moderator: Forum Moderators

Post Reply
User avatar
ZombieKnight
Posts: 371
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

[solved] Weapon proxy

Post by ZombieKnight »

Hi,
I'd like to give a unit new weapon and the documentation says I need a weapon proxy for that.
However, it doesn't tell how to create a new weapon proxy...
So... do you know, how to create a new weapon proxy?
Last edited by ZombieKnight on May 29th, 2024, 1:52 pm, edited 1 time in total.
User avatar
Celtic_Minstrel
Developer
Posts: 2371
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Weapon proxy

Post by Celtic_Minstrel »

I'm not sure what you're reading, but this is what the documentation says on the topic:
An attack can be replaced wholesale, or appended by indexing at the list's length and assigning.
That implies you can add a new attack to the end with code like the following:

Code: Select all

unit.attacks[#unit.attacks] = { name = 'new attack', range = 'melee', damage = 4, number = 3 }
A weapon proxy refers to the objects in the unit.attacks pseudo-array. You can also make one using wesnoth.units.create_weapon if for some reason you need a weapon proxy that doesn't belong to any unit.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
ZombieKnight
Posts: 371
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: Weapon proxy

Post by ZombieKnight »

Thanks a lot!
It wasn't sad clearly how syntax of weapon_proxy looks like when creating.
white_haired_uncle
Posts: 1456
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

Re: Weapon proxy

Post by white_haired_uncle »

Celtic_Minstrel wrote: May 29th, 2024, 1:07 pm That implies you can add a new attack to the end with code like the following:

Code: Select all

unit.attacks[#unit.attacks] = { name = 'new attack', range = 'melee', damage = 4, number = 3 }
Wouldn't that replace the last one? I'd think for lua you'd need #unit.attacks+1
Speak softly, and carry Doombringer.
User avatar
Celtic_Minstrel
Developer
Posts: 2371
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Weapon proxy

Post by Celtic_Minstrel »

Good question. I'm not actually sure. The documentation clearly says indexing at the length, but it could be wrong. It makes sense from a Lua standpoint that you'd need to add 1 to append, but it's not a true array so I'd have to check the code (or try it out) to be certain.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
ZombieKnight
Posts: 371
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: Weapon proxy

Post by ZombieKnight »

Yup #attacks + 1.
Thanks once again ^^
User avatar
ZombieKnight
Posts: 371
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: [solved] Weapon proxy

Post by ZombieKnight »

... just do I have to set it icon?
it's created just for wesnoth.simulate_combat(attacker,attacking_weapon_index, defender, #defender.attacks)
And it's supposed to be empty (since it doesn't have option for no_retalation)
...
Are those errors ok?
20240529 15:54:02 error filesystem: Illegal path 'icons/profiles/.png' (blacklisted filename).
20240529 15:54:02 error filesystem: Illegal path 'icons/profiles/.png' (blacklisted filename).
20240529 15:54:02 error filesystem: Illegal path 'icons/profiles/.png' (blacklisted filename).
20240529 15:54:02 error filesystem: Illegal path 'icons/profiles/.png' (blacklisted filename).
20240529 15:54:02 error filesystem: Illegal path 'icons/profiles/.png' (blacklisted filename).
20240529 15:54:02 error filesystem: Illegal path 'icons/profiles/.png' (blacklisted filename).
20240529 15:54:02 error filesystem: Illegal path 'icons/profiles/.png' (blacklisted filename).
User avatar
Ravana
Forum Moderator
Posts: 3313
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Weapon proxy

Post by Ravana »

Celtic_Minstrel wrote: May 29th, 2024, 1:07 pm I'm not sure what you're reading, but this is what the documentation says on the topic:
An attack can be replaced wholesale, or appended by indexing at the list's length and assigning.
That implies you can add a new attack to the end with code like the following:

Code: Select all

unit.attacks[#unit.attacks] = { name = 'new attack', range = 'melee', damage = 4, number = 3 }
A weapon proxy refers to the objects in the unit.attacks pseudo-array. You can also make one using wesnoth.units.create_weapon if for some reason you need a weapon proxy that doesn't belong to any unit.
wesnoth.units.create_weapon is not documented.

I would expect unit.attacks[#unit.attacks] = { name = 'new attack', range = 'melee', damage = 4, number = 3 } be error, since it gives table not weapon. While valid use would be unit.attacks[#unit.attacks] = wesnoth.units.create_weapon{ name = 'new attack', range = 'melee', damage = 4, number = 3 }
User avatar
ZombieKnight
Posts: 371
Joined: June 27th, 2022, 2:26 pm
Location: Czech Republic

Re: Weapon proxy

Post by ZombieKnight »

Ravana wrote: May 29th, 2024, 2:55 pm I would expect unit.attacks[#unit.attacks] = { name = 'new attack', range = 'melee', damage = 4, number = 3 } be error, since it gives table not weapon.
As surprising as it is... it works actually
(I use empty {}, but { name = 'new attack', range = 'melee', damage = 4, number = 3 } works fine)

Code: Select all

defender.attacks[(#defender.attacks + 1)] = {}
local table1, table2, table3, table4 =wesnoth.simulate_combat(attacker,attacking_weapon_index, defender, #defender.attacks)
defender.attacks[#defender.attacks] = nil
User avatar
Celtic_Minstrel
Developer
Posts: 2371
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Weapon proxy

Post by Celtic_Minstrel »

Ravana wrote: May 29th, 2024, 2:55 pm wesnoth.units.create_weapon is not documented.
I noticed that too right after bringing it up.
Ravana wrote: May 29th, 2024, 2:55 pm I would expect unit.attacks[#unit.attacks] = { name = 'new attack', range = 'melee', damage = 4, number = 3 } be error, since it gives table not weapon. While valid use would be unit.attacks[#unit.attacks] = wesnoth.units.create_weapon{ name = 'new attack', range = 'melee', damage = 4, number = 3 }
Hmm, that's a valid expectation, I guess. Both ways work though. I'm not sure if there's any actual difference between them.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Post Reply