Author Topic: [Script] tool_id does not work with "inspection tool"  (Read 1638 times)

0 Members and 1 Guest are viewing this topic.

Offline Yona-TYT

[Script] tool_id does not work with "inspection tool"
« on: September 05, 2016, 02:49:27 PM »





I can not restrict the use of the "inspection tool" (tool_id = 4,096) for customers in online games.

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4247
  • Total likes: 175
  • Helpful: 149
  • Languages: EN, DE, AT
Re: [Script] tool_id does not work with "inspection tool"
« Reply #1 on: September 05, 2016, 04:50:33 PM »
You need to use the methods of the rules class. Something like this
Code: [Select]
rules.forbid_way_tool_rect(0, 4096, wt_all, {x=22, y=46}, {x=23, y=46}, "Nix da!")
works for me, also in online games.
Parsley, sage, rosemary, and maggikraut.

Offline Yona-TYT

Re: [Script] tool_id does not work with "inspection tool"
« Reply #2 on: September 05, 2016, 08:07:39 PM »
You need to use the methods of the rules class. Something like this
Code: [Select]
   rules.forbid_way_tool_rect(0, 4096, wt_all, {x=22, y=46}, {x=23, y=46}, "Nix da!")
works for me, also in online games.
If it is, but does not help me because it is static.


I am creating a script that allows players to share their region with others, but "rules.forbid_way_tool_rect" can not change.


However the rest of the tools if they work with tool_id.

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4247
  • Total likes: 175
  • Helpful: 149
  • Languages: EN, DE, AT
Re: [Script] tool_id does not work with "inspection tool"
« Reply #3 on: September 05, 2016, 08:26:18 PM »
I am not sure, whether I understand you correctly.
I am creating a script that allows players to share their region with others, but "rules.forbid_way_tool_rect" can not change.
You want to be able to change these rules after they have been set?
Quote
However the rest of the tools if they work with tool_id.
I do not get this.
Parsley, sage, rosemary, and maggikraut.

Offline Yona-TYT

Re: [Script] tool_id does not work with "inspection tool"
« Reply #4 on: September 05, 2016, 08:57:21 PM »
I do not get this.
I mean that "tool inspection" is the only tool that does not send a "tool_id" with customers in an online game, the rest of the tools if they do.

Offline zhaop

Re: [Script] tool_id does not work with "inspection tool"
« Reply #5 on: September 05, 2016, 09:21:07 PM »
I mentally substitute the word "if" with the word "yes" and I find I'm able to understand this better. I guess the ambiguity stems from the Spanish "si"/"sí" which mean "if"/"yes"?

Back to the point, I think your (Yona's) question is about being able to redefine the forbidden areas during a game, which currently works for most tools but not the inspect tool.
I'm working on an AI for Simutrans that can make lots of money, and I'm currently learning the squirrel API for AI players.
https://github.com/zhaop/simutrans/tree/marmot

Offline Yona-TYT

Re: [Script] tool_id does not work with "inspection tool"
« Reply #6 on: September 06, 2016, 07:15:52 AM »

@Dwachs Have you been able confirm this?
What I need is to restrict "tool inspection" in a specific point of the map.


example:


Code: [Select]
if (pos.x == 1 &&  pos.y == 1 && tool_id == 4096 )


{


result = translate("The changes have been accepted.")


}

Offline Yona-TYT


Offline jameskuyper

Re: [Script] tool_id does not work with "inspection tool"
« Reply #8 on: September 07, 2016, 09:12:25 PM »
If it is, but does not help me because it is static.

I am creating a script that allows players to share their region with others, but "rules.forbid_way_tool_rect" can not change.

I'm not sure I understand you; or perhaps I misunderstand how those functions work - I've never gotten around to testing them. I was under the impression that your script can call rules.forbid_way_tool_rect() at any point during the game to forbid using the specified tool on the specified way type within the specified rectangle, and that it can call rules.allow_way_tool_rect() at any point in the game to remove that prohibition. That's not something I would consider static.

The non-trivial issue is giving the players control over the use of those functions. I couldn't figure out a way to use the squirrel-simutrans API to directly collect input from the players. An idea I've thought about, but haven't tested yet, is to let the players know in advance that use of a particular tool in a particular location will be treated by your script as indicating that it should do some specific thing, and then defining is_work_allowed_here() to to implement that functionality. Ideally, it would be a tool and a location with some reasonable connection to the intended functionality. Otherwise, it should either be an unimportant tool and an unimportant location, or is_work_allowed_here() should forbid use of that tool in that location (in addition to implementing the promised functionality).

In particular, arbitrary text from the user could be obtained by checking for use of the set_marker tool, and calling get_text() on the label that it creates. I don't think that the text will be available until after the is_work_allowed_here() gets called, so you'll have to set a variable somewhere to indicate that some other part of your script (new_month() seems the most reasonable choice) will know that it should call label::get_text(), parse the text, and then take appropriate action.

Offline TurfIt

Re: [Script] tool_id does not work with "inspection tool"
« Reply #9 on: September 08, 2016, 08:50:15 PM »
Assuming you mean the query tool, as there is no inspection tool, since this tool does not change the game state, it is executed immediately on the client and not sent to the server for processing. Hence a server side script cannot prevent use of this tool. Changing this would result in a horrible laggy experience trying to play the game - should not be done.

Offline Yona-TYT

Re: [Script] tool_id does not work with "inspection tool"
« Reply #10 on: September 08, 2016, 09:39:56 PM »
You're right, but my scenario needs to restrict in a specific point.