News:

Simutrans Tools
Know our tools that can help you to create add-ons, install and customize Simutrans.

[Script] tool_id does not work with "inspection tool"

Started by Yona-TYT, September 05, 2016, 02:49:27 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Yona-TYT






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

Dwachs

You need to use the methods of the rules class. Something like this

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.

Yona-TYT

Quote from: Dwachs on September 05, 2016, 04:50:33 PM
You need to use the methods of the rules class. Something like this

   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.

Dwachs

I am not sure, whether I understand you correctly.
Quote from: Yona-TYT on September 05, 2016, 08:07:39 PM
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.

Yona-TYT

Quote from: Dwachs on September 05, 2016, 08:26:18 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.

zhaop

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

Yona-TYT


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


example:



if (pos.x == 1 &&  pos.y == 1 && tool_id == 4096 )


{


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


}


jameskuyper

Quote from: Yona-TYT on September 05, 2016, 08:07:39 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.

TurfIt

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.

Yona-TYT

You're right, but my scenario needs to restrict in a specific point.