Script Hierarchy

mredge73

Member
For me Mafia has served as a OS for ash scripting. Mafia can run multiple scripts at one time. I can run scripts like a chatbot, a clanbot, auto adventuring, counter script, recovery script, buy script, log in, log out, between battle, ccs consult, custom moods, etc, all at the same time. Since I don't completely understand the hierarchy for script control that mafia uses I defined one myself. I have a control script that runs in a constant loop that calls all the others and has worked for me uninterrupted for some time now.

From what I discovered running all of these scripts at one time is that the chatbot script has priority over all others, it acts as an interrupt. (correct me if I am wrong) In order for me to keep my control script in charge of things I simplified my chatbot script to just log incoming chat messages to a file that can be read by the control script whenever it is ready. This does not hit the server so it has fixed most of my scripting conflicts.

Now to my question, since I don't completely understand the script hierarchy I don't really know how to solve this problem. If one of the many scripts that I have running hangs up for whatever reason how would I go about restarting my control script? I would have to do it with the chatbot since it will still operate even if the others hang. But if I have the chat script issue an abort, it aborts itself as well, and for whatever reason it doesn't come back with another instance of itself when the next chat command is issued. This could be due to mafia not refreshing chat or does something else have to happen before the chat script can be called again? When/If it does come back alive, if you have the chat script issue a cli_execute(call script.ash) command then the chat bot script is now stuck and will no longer operate because I guess only one instance of a chat script is allowed at one time. I think I am confusing myself, anyone have any ideas?

In summary, how would you go about restarting a script remotely without using a remote desktop application? Is there a way to write a watchdog script or restart a script through chat without loosing chat functionality? Is the "do this on abort" idea proposed by the devs (I don't remember who) still on the table or has it been scrapped?

Thanks
 
Last edited:

Grotfang

Developer
Chatbot scripts have given me trouble in the past. As far as I'm aware, an aborting makes the script unresponsive until you perform an action.

The other problem I've had before is that there exists a conflict between incoming chat commands and currently performing chat commands. This (I think) is what you have solved via removing chatbot actions and instead simply logging commands that are sent. However, that seems (while effective at solving this issue) only a partial solution, as wile that approach would seem to be the most commonly needed functionality, it sacrifices another useful functionality of immediate response. The time it would not be useful is if you have included an abort command in your script that you could use to halt actions early.

The simplest example of this is a modification of my "afk.ash" PM logger script:

Code:
void main( string sender , string message )
{
	print( sender + ": " + message , "green" );
	wait( 3 );
	print( "Done" );
}

Usefully for this, sending a PM to yourself is logged (I think incorrectly) as two PMs by mafia. Therefore we can see the effect of two PMs appearing in quick succession:

Grotfang: Check script
Countdown: 3 seconds...
Grotfang: Check script
Countdown: 3 seconds...
Countdown: 2 seconds...
Countdown: 2 seconds...
Countdown: 1 second...
Countdown: 1 second...
Waiting completed.
Done
Waiting completed.
Done

What's odd about this is the operations seem to be carried out simultaneously. Maybe that's a throwback from the "wait" function, and other functions would have that, but clarification would be useful. What I think would be ideal is to have the abort command optionally activated, while mafia's internal processes queue commands in the way MrEdge currently does by "hand". Maybe that would have other issues I'm missing though.

Sorry for not really responding to the original question, and just asking more myself, but while it seems like you have found a fix for this ("I simplified my chatbot script to just log incoming chat messages to a file") it would be nice to know whether the behaviour posted above is intended. Because we currently have to compromise between being able to have an emergency abort command and a script that will function as expected when other messages arrive before the previous one has been finished with.
 
Last edited:

mredge73

Member
In my experience in this, when mafia responds like you described above (creating two instances of the same script at the same time) if they both try to hit the server at the same time they create major conflicts. It is even worse if it happens in the middle of another script like an turn burning script. It would even often crash. Since I figured that I was trying to do things with mafia that mafia is not intended to do like trying to use one character to preform the actions of many different types of bots at the same time I didn't bug the devs with bug reports. But, by logging the chat messages and having another script read them and execute their commands sequentially you can avoid these conflicts.

My bot had run without me even checking on it for almost 2 month before my CCS hung up fighting feast of boris monsters. I am looking for a way to restart it remotely when the unexpected happens like this. I am curious if it can even be done.
 
Last edited:
Top