'User Action 1' not working

Contribute, display and discuss rulesets and modpacks for use in Freeciv here.
leo.priori
Posts: 15
Joined: Mon Jan 01, 2024 3:22 am

'User Action 1' not working

Post by leo.priori »

Straight to the point: 'User Action 1' not showing in dialog box

I would like to create a unit with a specific action. I have already done it with Bombard 1,2 and 3, but not with 'User Action 1'.
In the 'sandbox' rule, 'Disrupt Supply Lines' is already configured, but it does not appear in the list of actions.
Has anyone managed to make this action (Disrupt Supply Lines) work?
I believe you only have to take a unit with the flag "SupplyLines", press the key 'D' and click in other unit (enemy in range).
So the action 'Disrupt Supply Lines' will show in a dialog box with others options (maybe 'disband unit', 'wait', 'do nothing', etc)
Is that right?

My idea is to create a unit that reduces corruption in the city, even if it is only for one turn, and after that the unit is lost.
I also have other actions in mind, such as making an artist that increases luxury, among others.

BUT THE ACTION NEVER APPEARS IN THE LIST OF ACTIONS, (after pressing the 'D' key or entering the city).
Not even in Menu Multiplayer/Defaul action for city
Im using 3.1 beta4 now. (yeah released yesterday) But I tested in beta3 too

And just for remind. 4 actions is not enough. Can anyone tell to the developers to Pleeease make it 10 at least ..

I have so many ideas to play with my friends, so many other custom actions

Well, here what i have so far:

Flag 'Lawman' created in file units.ruleset

Code: Select all

[control]
flags =
  { "name", "helptxt"
...
    _("Lawman")
...
}
A unit called 'Marshall' and it has only this flag 'Lawman'

Code: Select all

[unit_marshall]
name = _("Marshall")
flags = "Lawman"
Now where the fun begins:
File: game.ruleset

Code: Select all

; /* TRANS: _Reduce Crime (100% chance of success). */
ui_name_user_action_1                = _("%sReduce Crime%s")
user_action_1_target_kind            = "City"
user_action_1_min_range              = 1
user_action_1_max_range              = 1
user_action_1_actor_consuming_always = TRUE
Here is the problem... The action is not showing in the dialog box, only these 3 options (Disband, Wait and Do nothing )
I tried to remove the 'target_reqs' attribute, and other things

Code: Select all

[actionenabler_marshall]
action = "User Action 1"
actor_reqs    =
    { "type",         "name",          "range", "present"
      "UnitFlag",     "Lawman",        "Local", TRUE
      "MinMoveFrags", "1",             "Local", TRUE
    }
target_reqs  =
    { "type",         "name",       "range", "present"
      "CityTile",    "Center",        "Local", TRUE
    }

File: effects.ruleset

Code: Select all

[effect_reduce_crime]
type    = "Output_Waste_Pct"
value   = -50
reqs    =
    { "type",       "name",            "range"
      "Action",     "User Action 1",   "Local"
      "OutputType", "Shield",          "Local"
    }

PLEASE HELP
What Am i doing wrong folks?
Thanks
Ignatus
Elite
Posts: 644
Joined: Mon Nov 06, 2017 12:05 pm
Location: St.Petersburg, Russia
Contact:

Re: 'User Action 1' not working

Post by Ignatus »

Hmm. I can't see why does not the action show in the dialog, but the effect just does not work this way. You have to put some extra or building with the action (using a Lua callback) to actually influence the city outputs, and make requirements of the effects towards that thing.
leo.priori
Posts: 15
Joined: Mon Jan 01, 2024 3:22 am

Re: 'User Action 1' not working

Post by leo.priori »

Hi Ignatus. thanks for reply.

Can you show me how the 'Disrupt Supply Lines' works? It never showed this option for me!

About LUA:
In the example (sandbox.ruleset) LUA is used only for notifications.
If you check the script, it says that "Only notifications needs Lua" (line 450)
(File script.lua in the sandbox ruleset)
I dont know if I need LUA to make this work
If so, the function 'User action 1' HAS to show in the dialog BOX before call LUA ..... is that right?
Why is not showing?
Not showing any of them (you can test 'Disrupt Supply Lines' in sandbox, not showing either)

Do a Test in sandbox:
1) take a spy (any unit that has a 'SupplyLines' flag)
2) Press the D key
3) Click in enemy in range (2 tiles away)
The dialog box is showing only 2 options (Do nothing and Wait)

Anyway I believe i have to change something in FILE effects. I dont know!
Can you tell me what do i have to change or adjust to make this work?
And how to make 'Disrupt Supply works?

Thanks again and a happy new year!
cazfi
Elite
Posts: 3111
Joined: Tue Jan 29, 2013 6:54 pm

Re: 'User Action 1' not working

Post by cazfi »

General advice about checking possible problems on your own ruleset definitions is to 1) run on separate server 2) start the server with commandline parameter --warnings

But this user action not showing in "Do..." seems like a freeciv bug at first glance. I'll debug it a bit more.

Ignatus is right that there's no hope to get effect to work like that. First of all, an action is immediate, while that Output_Waste_Pct effect is checked at turn change when calculating the waste. Further, that effect check does not care about properties of units in the city. The best (still imperfect) documentation about this is https://www.freeciv.org/wiki/Editing_Effects
cazfi
Elite
Posts: 3111
Joined: Tue Jan 29, 2013 6:54 pm

Re: 'User Action 1' not working

Post by cazfi »

cazfi wrote: Mon Jan 01, 2024 11:36 pmBut this user action not showing in "Do..." seems like a freeciv bug at first glance. I'll debug it a bit more.
Oh, the problem is that "min range" of 1. You cannot be inside the city (range 0), but if you are adjacent to the city, and d)o action against the city, the action gets listed.

Also, that target requirement about tile having a city on it is redundant (or maybe even counterproductive), as you already have the action as "City" targeted.
cazfi
Elite
Posts: 3111
Joined: Tue Jan 29, 2013 6:54 pm

Re: 'User Action 1' not working

Post by cazfi »

cazfi wrote: Mon Jan 01, 2024 11:36 pmFirst of all, an action is immediate, while that Output_Waste_Pct effect is checked at turn change when calculating the waste.
This brings an idea about user-defined activities, that would be launched by user-defined actions. Same way as e.g. irrigate action (immediate) just starts irrigation activity (lasts turns)
Ignatus
Elite
Posts: 644
Joined: Mon Nov 06, 2017 12:05 pm
Location: St.Petersburg, Russia
Contact:

Re: 'User Action 1' not working

Post by Ignatus »

leo.priori wrote: Mon Jan 01, 2024 11:08 pm Can you show me how the 'Disrupt Supply Lines' works? It never showed this option for me!
That function in sandbox works by "Action_Success_Target_Move_Cost" effect. That one is an action-based effect that subtracts movement fragments from the target, so Lua does only notification. You can look at the Ancient Transportation related code to see a more Lua-based action.
Anyway I believe i have to change something in FILE effects. I dont know!
Yes, you need to put an "Output_Waste_Pct" effect there, just you need some different trigger for it that you most probably will need Lua to put. Since we don't have city flags or counters settable yet, you probably will have to put an extra on city center that will mark reduced crime in that city (maybe you also want to remove that extra in "city_destroyed" callback). List that extra in the effect's reqs.

Actually, I did not test if user actions go into D menu. Have you tried forcing one with /lua cmd find.unit(...):perform_action(...) ?

Happy New Year!
cazfi
Elite
Posts: 3111
Joined: Tue Jan 29, 2013 6:54 pm

Re: 'User Action 1' not working

Post by cazfi »

Ignatus wrote: Tue Jan 02, 2024 12:02 amYes, you need to put an "Output_Waste_Pct" effect there, just you need some different trigger for it that you most probably will need Lua to put. Since we don't have city flags or counters settable yet, you probably will have to put an extra on city center that will mark reduced crime in that city (maybe you also want to remove that extra in "city_destroyed" callback). List that extra in the effect's reqs.
Maybe a building that is not otherwise buildable. That would better show up in the city dialog.
leo.priori
Posts: 15
Joined: Mon Jan 01, 2024 3:22 am

Re: 'User Action 1' not working

Post by leo.priori »

GUYS Thank you so much for your replies.

Still not working, but before get in the codes, let me get this right!

If I move my marshal to the city, the window automatically pops up, without pressing the D key on the keyboard.
But the action still not showing! (edit: the city has 2 corruption)
I was talking about the D letter because of the "Bombard" actions (1,2 and 3). They have a range of 2,3 and 4 respectively.
And it is working properly. My friends and I are having a lot of fun (despite the fights with our wives).
But if there is another way to trigger these actions, please tell me! Pleeeease!!!

So, to make this right, I started over again, copied the entire civ2civ3 ruleset, and made only the following changes:

units.ruleset (added the flag "Lawman" and copy and paste the Dragoons unit,
changed to Marshall and associate with only ONE Flag, the Lawman)

Code: Select all


flags =
  { "name", "helptxt"
    ...
    _("OneAttack")
    _("Lawman")
  }
  
; copied from Dragoons
[unit_marshall]
name  = _("Marshall")
...
flags = "Lawman"

game.ruleset (removed the target_regs attribute)

Code: Select all


ui_name_user_action_1                = _("%sReduce Crime%s")
user_action_1_target_kind            = "City"
user_action_1_min_range              = 1
user_action_1_max_range              = 1
user_action_1_actor_consuming_always = FALSE

[actionenabler_marshall]
action = "User Action 1"
actor_reqs    =
    { "type",         "name",          "range", "present"
      "UnitFlag",     "Lawman",        "Local", TRUE
      "MinMoveFrags", "1",             "Local", TRUE
    }

effects.ruleset (added the Action_Success_Actor_Move_Cost with value 65535)

Code: Select all


[effect_action_success_move_cost_marshall]
type    = "Action_Success_Actor_Move_Cost"
value   = 65535
reqs    =
    { "type", "name", "range", "present"
      "Action", "User Action 1", "Local", TRUE
    }

[effect_action_marshall]
type    = "Output_Waste_Pct"
value   = -50
reqs    =
    { "type",       "name",            "range"
      "Action",     "User Action 1",   "Local"
      "OutputType", "Shield",          "Local"
    }

script.lua (calling the 'action_started_unit_city' because the action is at a city) (copied from sandbox, of course)
The message "Got here" only reveals when i disband the marshall, but since i dont have a User action 1, the YEAHHHH message is never read))

Code: Select all

function action_marshall(action, actor, target)

   notify.event_msg(nil,nil,2,"Got here")
   
   if action:rule_name() == "User Action 1" then
      notify.event_msg(nil,nil,2,"YEAHHHHHH")
   end
end

signal.connect("action_started_unit_city", "action_marshall")

Ignatus wrote: Tue Jan 02, 2024 12:02 am Have you tried forcing one with /lua cmd find.unit(...):perform_action(...) ?
Sorry but I am very noob in LUA, I tried type this in the chat box, playing the ruleset civ2civ3 and the marshall was on a tile adjacent to a city,
but of course this is not the correct way:

Code: Select all

/lua cmd find.unit("Marshall"):perform_action("User Action 1") 
What am i doing wrong? What am I missing?
Thanks in advance guys, you all are amazing in this project
cazfi
Elite
Posts: 3111
Joined: Tue Jan 29, 2013 6:54 pm

Re: 'User Action 1' not working

Post by cazfi »

leo.priori wrote: Tue Jan 02, 2024 4:14 am user_action_1_min_range = 1
user_action_1_max_range = 1
With both min and max range 1, the action works only when the unit is adjacent to the city, not when inside the city (including when entering the city tile)
Post Reply