hide ability in unit icon for enemies

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

Moderators: Forum Moderators, Developers

Post Reply
User avatar
Gwledig
Posts: 509
Joined: March 30th, 2009, 5:10 pm
Location: UK

hide ability in unit icon for enemies

Post by Gwledig » August 3rd, 2019, 8:54 pm

Hi I'm showing an ability on a unit and want this to display under the unit icon for the player who owns that unit only, i.e. I want enemies to be unable to see that ability on the unit's map icon, the ability is added/removed over the course of the game... I've tried filtering of various sorts but realised of course that the ability is set on recruit/loading the unit, I can add/modify unit to remove the ability but there doesn't seem any way of filtering within the [ability] itself to mask/hide the name/description for all players apart from the one who owns the unit...
Maintainer of Conquest (Original Gameplay), Conquest+, Conquest+ Space/Ranged, Chaoz Battle of the Wizards, Lazersquad (squad game), WesCraft (building MP game)

User avatar
Ravana
Moderator
Posts: 2156
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: hide ability in unit icon for enemies

Post by Ravana » August 3rd, 2019, 9:02 pm

You can use unsynced code to only add visuals to specific client.

First set up event which adds visuals you want, then I will help with filter like https://github.com/ProditorMagnus/Agele ... ad.lua#L34

User avatar
Gwledig
Posts: 509
Joined: March 30th, 2009, 5:10 pm
Location: UK

Re: hide ability in unit icon for enemies

Post by Gwledig » August 4th, 2019, 11:12 am

thanks Ravena, it happens that enclave was doing something similar, with some help from enclave I have been looking at this function (lua) https://wiki.wesnoth.org/LuaWML/Display ... heme_items

My unit is a boat which is either loaded or unloaded with a saved variable (unit), there is an [ability] set (or removed) when the unit is loaded/unloaded using [modify_unit], what I am trying to do is show only the 'Loaded' status ([ability] under unit icon) to only the player who owns the boat (so others can't see this when the boat is approaching...)

Another neat idea Enclave thinks possible, would be to show the actual unit 'name' (not type as enclave is doing - as I use overlays & modified units) held in the boat's variable ie I'd like to refer to their 'name' such as "loaded: gunner"...
At the moment this idea is working with image overlays which enclave has done (loaded unit type's image as small overlay on the boat's own icon). I am trying to adapt this to check all boats using either 'role=score_navy' as he has done or hopefully units with the trait {TRAIT_TRANSPORT_BOAT} instead (because I use 'role' for other things and this will cause conflicts, as u can only have 1 role for a unit), but just for now I've been testing with role= as shown below.
Enclave made some suggestions yesterday in the MP lobby to use text vs overlays, but he assumed my loaded status was a trait, this is not, it's an ability which is added or removed as the unit is loaded/unloaded...

The following tries to get the current unit (boat)'s abilities and tag on the 'name' of the loaded unit to the ability description "Loaded" shown under the unit, so it would say simply "Loaded: gunner", another concern is that I also use other abilities especially in conquest+/space, so these transports may have other abilities such as ranged weapons, and I want to avoid loosing these other abilities shown in the unit...

At the moment I can't quite seem to master the lua below and get an error ingame/log
error scripting/lua: [string "..."]:16: attempt to index a nil value (field '?')

Code: Select all

[event]
name=preload
first_time_only=no
## SHIPS UNITS INSIDE IMAGE
[lua]
code=<<
local old_image = wesnoth.theme_items.unit_abilities
wesnoth.theme_items.unit_abilities = function()
local oldvalue = old_image()
if oldvalue then
	local unit_abilities = ""
	local u = wesnoth.get_displayed_unit()
	if u then
	 if tostring(u.side) == tostring(wesnoth.get_viewing_side()) then
		if u.variables.role=="score_navy" then
			if u.variables.unit then
				unit_abilities="Loaded:(tostring(u.variables.unit_name))"
			end
		end
	 end
	oldvalue[1][2]["text"] = unit_abilities
	end
end
return oldvalue
end
>>
[/lua]
[/event]
Maintainer of Conquest (Original Gameplay), Conquest+, Conquest+ Space/Ranged, Chaoz Battle of the Wizards, Lazersquad (squad game), WesCraft (building MP game)

User avatar
Ravana
Moderator
Posts: 2156
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: hide ability in unit icon for enemies

Post by Ravana » August 4th, 2019, 11:20 am

Means one of oldvalue[1][2] and oldvalue[1] is null.

It is helpful to have way to view content of Lua variables at runtime, I have used https://github.com/ProditorMagnus/Oroci ... ctions.lua

Post Reply