StoryPage Tile/Vehicle Buttons

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

Post Reply
alc
Engineer
Engineer
Posts: 9
Joined: 04 Sep 2019 18:42

StoryPage Tile/Vehicle Buttons

Post by alc »

Hi,
I am writing my first GS. It is usefull for seasonal industries productions like Fruit Plantations (at least with ECS that is what I use).
What the GS does is to look between October and June if there are vehicles that can transport fruits and/or Oil Seeds on station with full load/Full Load Any orders. If the station is empty, and the vehicle has above a percentage loaded, it is informing on the StaryPage what vehicles are in this condition. Up to here, is working,

I can't understand how the StoryPAge Buttons work. When I create a vehicle buttonn, in the parameters, I have to say the vehicle type, not the vehicle ID. Or for tile button, nothing refered to a tile is passed.
How does the event handler knows the vehicle_id in the GSEventStoryPageVehicleSelect.GetVehicleID()?

Is there any working example to have a look how it is implemented?

Instead of given the vehicle type, should be passed the vehicle ID? I try it but crushed the entire OTTD game.

static StoryPageButtonFormatting MakeTileButtonReference (StoryPageButtonColour colour, StoryPageButtonFlags flags, StoryPageButtonCursor cursor)

static StoryPageButtonFormatting MakeVehicleButtonReference (StoryPageButtonColour colour, StoryPageButtonFlags flags, StoryPageButtonCursor cursor, GSVehicle::VehicleType vehtype)

Thanks in advance, :bow:
Alberto
User avatar
jfs
Tycoon
Tycoon
Posts: 1261
Joined: 08 Jan 2003 23:09
Location: Denmark

Re: StoryPage Tile/Vehicle Buttons

Post by jfs »

What are you trying to do?
The Vehicle button is to let the player click on a vehicle, and you get a VehicleID in return (in the fired event) after the player has selected the vehicle.


This call creates a button to select a water vehicle (ship), the mouse cursor will show the "build station" icon:

Code: Select all

this._select_vehicle_button = GSStoryPage.NewElement(
    this._pageid,
    GSStoryPage.SPET_BUTTON_VEHICLE,
    GSStoryPage.MakeVehicleButtonReference(
        GSStoryPage.SPBC_GREEN,
        GSStoryPage.SPBF_NONE,
        GSStoryPage.SPBC_PICKSTATION,
        GSVehicle.VT_WATER
        ),
    "Find a vehicle");
When the player then clicks that button, and then clicks a vehicle, the game sends a GSEvent.ET_STORYPAGE_VEHICLE_SELECT event to your script.

You can then get the ID of the actual vehicle the player clicked by examining the event object.

Code: Select all

local vehicle_select_event = GSEventStoryPageVehicleSelect.Convert(event_object);
if (vehicle_select_event.GetElementID() == this._select_vehicle_button) {
    GSController.Print(false, "Player clicked vehicle, button=" + vehicle_select_event.GetElementID());
    GSController.Print(false, "Player clicked vehicle, vehicle name=" + GSVehicle.GetName(vehicle_select_event.GetVehicleID()));
}

Edit: Also, I'm very interested in seeing the code you had that caused the game to crash. That should not be possible, if you find any way of crashing the game (as in, OpenTTD closes completely) please report it.
alc
Engineer
Engineer
Posts: 9
Joined: 04 Sep 2019 18:42

Re: StoryPage Tile/Vehicle Buttons

Post by alc »

Thanks, I make it work but that behavior is not what I am needing.
What I am trying to do?
On a StoryPage create a button for each vehicle that fullfil the conditions. That button was suppose to, by clicking, open the vehicle's window, to avoid needing to look at the different vehicles list. I don't see on GSWindows an open function so, as an alternative, after cliking, to position the viewport on that vehicle.

I will try to recreate the OTTD fail tomorrow or during the weekend.

Regards,
Alberto
User avatar
jfs
Tycoon
Tycoon
Posts: 1261
Joined: 08 Jan 2003 23:09
Location: Denmark

Re: StoryPage Tile/Vehicle Buttons

Post by jfs »

You can create a plain button that calls the GSViewport::ScrollClientTo() function to center the player on a vehicle. There isn't any way to open a vehicle window or to make the viewport follow a vehicle, but you can at least center the player's view on the vehicle's current tile.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 13 guests