'User Action 1' not working

Contribute, display and discuss rulesets and modpacks for use in Freeciv here.
cazfi
Elite
Posts: 3384
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: 23
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: 3384
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)
Ignatus
Elite
Posts: 662
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: Tue Jan 02, 2024 4:14 am but of course this is not the correct way:

Code: Select all

/lua cmd find.unit("Marshall"):perform_action("User Action 1") 
I meant, use chat window to test if the action works at all even if not shown in the interface. Place a marshall next to a city, record ids of the marshall unit (say, 1234) and the city (say, 1357) and type in the chat

Code: Select all

/lua cmd find.unit(nil, 1234):perform_action(find.action("User Action 1"), find.city(nil, 1357)) 
Likely, you can find out the ids by midclick, or in edit mode.
leo.priori
Posts: 23
Joined: Mon Jan 01, 2024 3:22 am

Re: 'User Action 1' not working

Post by leo.priori »

cazfi wrote: Tue Jan 02, 2024 9:42 am 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)
Just like a explorer, a diplomatic, a caravan or others when they are adjacent to a city and will enter to the center. The message pops up with the options (Establish Trade Route or Investigate city, etc).
Thats exactly what i want. I want the action 'User Action 1' in this list.
Ignatus wrote: Tue Jan 02, 2024 10:32 am Likely, you can find out the ids by midclick, or in edit mode.
Dear Lord i will take at least a decade to find out this command.
But i am not so lucky.
Im using 3.1 beta4 Qt-client and my midclick not showing the id. :cry: :cry: :cry:
The X,Y helps?
I could try to show the id using script.lua. Something like this inside the function action_mashall

Code: Select all

function action_marshall(action, actor, target)
   local id_unit = actor.getId()
   local id_city = target.getId()
   local msg = string.format("Unit: %d  City: %d", id_unit, id_city) 
   notify.event_msg(nil,nil,2,msg)
end
Ignatus
Elite
Posts: 662
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: Tue Jan 02, 2024 12:03 pm

Code: Select all

   local id_unit = actor.getId()
That's from some other API, ours has actor.id
And that won't work if you need ids before you run the action. Likely, you can get ids with something like (sorry, didn't test )

Code: Select all

for p in players_iterate() do
  notify.all("%s's units:", p.name)
  for u in p:units_iterate() do
    notify.all("  %4d %s\t%d,%d", u.id, u.utype:rule_name(), u.tile.x, u.tile.y)
  end
  notify.all("%s's cities:", p.name)
  for c in p:cities_iterate() do
    notify.all("  %4d %s\t%d,%d", c.id, c.name, c.tile.x, c.tile.y)
  end
end
Ignatus
Elite
Posts: 662
Joined: Mon Nov 06, 2017 12:05 pm
Location: St.Petersburg, Russia
Contact:

Re: 'User Action 1' not working

Post by Ignatus »

cazfi wrote: Tue Jan 02, 2024 12:32 am Maybe a building that is not otherwise buildable. That would better show up in the city dialog.
Yes. Like, we could put a requirement

Code: Select all

{"type", "name", "range", "present"
"None", "", "Local", FALSE}
into "Reduced Crime" building reqs and still place the building with

Code: Select all

target:create_building(find.building"Reduced Crime")
?
cazfi
Elite
Posts: 3384
Joined: Tue Jan 29, 2013 6:54 pm

Re: 'User Action 1' not working

Post by cazfi »

leo.priori wrote: Tue Jan 02, 2024 12:03 pm
cazfi wrote: Tue Jan 02, 2024 9:42 am 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)
Just like a explorer, a diplomatic, a caravan or others when they are adjacent to a city and will enter to the center. The message pops up with the options (Establish Trade Route or Investigate city, etc).
Thats exactly what i want. I want the action 'User Action 1' in this list.
Try setting min range to zero, so the action is legal in the very city tile too.
cazfi
Elite
Posts: 3384
Joined: Tue Jan 29, 2013 6:54 pm

Re: 'User Action 1' not working

Post by cazfi »

cazfi wrote: Tue Jan 02, 2024 12:32 amMaybe a building that is not otherwise buildable.
Except that current ruleset format does not support that. Opened a ticket: RM #116
cazfi
Elite
Posts: 3384
Joined: Tue Jan 29, 2013 6:54 pm

Re: 'User Action 1' not working

Post by cazfi »

leo.priori wrote: Mon Jan 01, 2024 4:05 am

Code: Select all

[effect_reduce_crime]
type    = "Output_Waste_Pct"
value   = -50
README.effects documents Output_Waste_Pct as:
Output_Waste_Pct
Reduce waste by amount percent.
So I think you mean "50", not "-50"
Post Reply