[solved] Weapon proxy
Moderator: Forum Moderators
- ZombieKnight
- Posts: 371
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
[solved] Weapon proxy
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?
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.
- Celtic_Minstrel
- Developer
- Posts: 2371
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Weapon proxy
I'm not sure what you're reading, but this is what the documentation says on the topic:
A weapon proxy refers to the objects in the
That implies you can add a new attack to the end with code like the following:An attack can be replaced wholesale, or appended by indexing at the list's length and assigning.
Code: Select all
unit.attacks[#unit.attacks] = { name = 'new attack', range = 'melee', damage = 4, number = 3 }
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.- ZombieKnight
- Posts: 371
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: Weapon proxy
Thanks a lot!
It wasn't sad clearly how syntax of weapon_proxy looks like when creating.
It wasn't sad clearly how syntax of weapon_proxy looks like when creating.
-
- Posts: 1456
- Joined: August 26th, 2018, 11:46 pm
- Location: A country place, far outside the Wire
Re: Weapon proxy
Wouldn't that replace the last one? I'd think for lua you'd need #unit.attacks+1Celtic_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 }
Speak softly, and carry Doombringer.
- Celtic_Minstrel
- Developer
- Posts: 2371
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Weapon proxy
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.
- ZombieKnight
- Posts: 371
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: Weapon proxy
Yup #attacks + 1.
Thanks once again ^^
Thanks once again ^^
- ZombieKnight
- Posts: 371
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: [solved] Weapon proxy
... just do I have to set it icon?
it's created just for
And it's supposed to be empty (since it doesn't have option for no_retalation)
...
Are those errors ok?
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).
Re: Weapon proxy
wesnoth.units.create_weapon is not documented.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:
That implies you can add a new attack to the end with code like the following:An attack can be replaced wholesale, or appended by indexing at the list's length and assigning.
A weapon proxy refers to the objects in theCode: Select all
unit.attacks[#unit.attacks] = { name = 'new attack', range = 'melee', damage = 4, number = 3 }
unit.attacks
pseudo-array. You can also make one usingwesnoth.units.create_weapon
if for some reason you need a weapon proxy that doesn't belong to any unit.
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 }
- ZombieKnight
- Posts: 371
- Joined: June 27th, 2022, 2:26 pm
- Location: Czech Republic
Re: Weapon proxy
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
- Celtic_Minstrel
- Developer
- Posts: 2371
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Weapon proxy
I noticed that too right after bringing it up.
Hmm, that's a valid expectation, I guess. Both ways work though. I'm not sure if there's any actual difference between them.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 }