Script to remove all signs

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
Sławek
Engineer
Engineer
Posts: 6
Joined: 02 Dec 2023 20:51

Script to remove all signs

Post by Sławek »

Hi,
I have a problem that I described here:
viewtopic.php?p=1266013#p1266013
I would like to remove all signs from the list.
List of signs.png
List of signs.png (13.9 KiB) Viewed 3468 times
I found this class:
https://docs.openttd.org/gs-api/classGSSignList#details
this class has the Clear() function
https://docs.openttd.org/gs-api/classGS ... f69e9443f5
but I don't know how to use it.
I think it's easy to create a script using this function, but I've never done it. Can I ask for help on how to do this? Maybe someone could write me such a script?
Thank you and best regards
HGus
Engineer
Engineer
Posts: 121
Joined: 12 May 2013 22:28
Location: Argentina

Re: Script to remove all signs

Post by HGus »

Code: Select all

local sign_list = AISignList();
	sgn_list.Clear;
From SuperLib:

Code: Select all

function _SuperLib_Helper::ClearAllSigns(except_tile = -1)
{
	local sign_list = AISignList();
	foreach(i, _ in sign_list)
	{
		if (except_tile != -1 && AISign.GetLocation(i) == except_tile) continue;
		AISign.RemoveSign(i);
	}
}
AIAI uses this function from user request:

Code: Select all

function AIAI::SignMenagement() {
	if (AIAI.GetSetting("clear_signs")) {
		Helper.ClearAllSigns();
	}
}
Sławek
Engineer
Engineer
Posts: 6
Joined: 02 Dec 2023 20:51

Re: Script to remove all signs

Post by Sławek »

Thank you HGus for this code.
But I don't know how to use it.
Where should I enter this code?
Unfortunately, I've never scripted for OpenTTD.
HGus
Engineer
Engineer
Posts: 121
Joined: 12 May 2013 22:28
Location: Argentina

Re: Script to remove all signs

Post by HGus »

Sorry. I thought you are an AI developer.

Find CPU-1.4.tar in your OpenTTD\ai or OpenTTD\content_download\ai folder.

Extract and edit main.nut

At line 448, insert this:

Code: Select all

local sign_list = AISignList();
	foreach(i, _ in sign_list)
	{
		AISign.RemoveSign(i);
	}
Repack main.nut into the tar file.

Rerun the game. The signs should be deleted in a few ticks. You can then exit and restore the original code.
Sławek
Engineer
Engineer
Posts: 6
Joined: 02 Dec 2023 20:51

Re: Script to remove all signs

Post by Sławek »

Thank you.
Unfortunately, I'm not an AI programmer. I do some programming in various programming languages, but I've never programmed anything in OpenTTD before. I'm using Fedora 39.
I found the CPU-1.4.tar file in ~/.openttd/content_download/ai
I inserted this piece of code and it looks like this:

Code: Select all

{...]
    function CPU::Start() {
        AILog.Info("TestAI Started.");
        SetCompanyName();
        AICompany.SetAutoRenewStatus(true);
        //set a legal railtype. 
        local types = AIRailTypeList();
        AIRail.SetCurrentRailType(types.Begin());
        local towns = AITownList();
        //Keep running. If Start() exits, the AI dies.
        local step=-2;
        while (true) {
            this.Sleep(100);
local sign_list = AISignList();
	foreach(i, _ in sign_list)
	{
		AISign.RemoveSign(i);
	}            
            step+=1;
            while (AIEventController.IsEventWaiting()) {
{...]
I repackaged it into CPU-1.4.tar
I started the game, but I don't know what to click to make the signs disappear :(
HGus
Engineer
Engineer
Posts: 121
Joined: 12 May 2013 22:28
Location: Argentina

Re: Script to remove all signs

Post by HGus »

It only works if the AI is running. If it died then all signs become un-owned and the only way to delete them is including the GS version in a Game Script if your game already included one. After modifying the script, reload a savegame with the AI still running.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 16 guests