News:

Do you need help?
Simutrans Wiki Manual can help you to play and extend Simutrans. In 9 languages.

[Chat Windows] Send basic data to use in scripts

Started by Yona-TYT, November 20, 2024, 05:20:40 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Yona-TYT


I'm thinking of a new scenario for online games, but currently there are certain limitations regarding the clients, and that is that there is no easy way to send data to the script.

My idea is to use the chat window to send variable data that can be read from the script.

As seen in the image for example: {var = 1}

Captura de pantalla -2024-11-20 13-02-13.png

I would also like to implement a simple chatbot style controlled via script, something like this would be great!.
Captura de pantalla -2024-11-20 13-53-58.png

prissi

I see no issues adding an interface of a script AI recieving messages.

However, I am not sure what you want to achieve. What is your idea exactly?

Yona-TYT

Quote from: prissi on November 21, 2024, 07:15:04 AMHowever, I am not sure what you want to achieve. What is your idea exactly?
Basically, these are requests that the player makes to the game administrator to have specific privileges and that must be approved.

Clients may request road/train connections, public stops/terminals, new venues/factories/chains, etc.

For this, clients would send something like {request_x} from the chat to activate an automatic response in which the option required can be chosen (by sending a number).

Edit.
In fact, even the braces {} are not needed, since text strings can be processed using scripts.

Another important point is that players carry out small votes to decide who administers the public service for a time, so for this the administrator can send an automated message to all players so that they can choose, sending a number that corresponds to the option they want.

This, in my opinion, is a very fun way for clients to interact with each other and take even more advantage of the chat window. I know that there must be more interesting things that can be done with this.  8)



One way I can think of to do that is to implement something like a trigger if a player sends a message using the chat:
is_send_chat_message(chat_x)
The chat_x class would contain data like:
message/text
player number of the sending player.
player number of the receiving player.
date and time.
coordinates/pos (if any).

A command is also needed so that the script can respond to the chat.

To some extent I can try to create a patch for this, but the communication between clients and server (network) is a bit difficult for me.

Yona-TYT

I did an experiment to create a mini bot from the API, what do you think about this?.

0001-Listen-and-Send-message-chat.patch

The script worked as expected.

pl_list <- {}
tag <- "request"
pl_bot <- 0

ask_a <- "Enter an option: \n 1 option one \n 2 option two \n 3 option three"
ask_b <- "Enter an option: \n A option one \n B option two \n C option three"

function is_message_chat(text, sender_pl, chan, sender_nick, recipient, pos, pl)
{
if(chan != -1){
if(text == tag &&  sender_pl != pl_bot){
pl_list[sender_pl] <- {val = text, chanel = chan, max = 2, start = true}
}

if(sender_pl == pl_bot){
return true
}

foreach(key, r in pl_list){
if(key == sender_pl){
//Genera las preguntas
gui.add_message("key: "+key+" req: "+pl_list.len())
if(r.start){
//Primer cuestionario
gui.add_chat_message(ask_a, pl_bot, chan, "", "", pos)
r.start = false
break
}
else if(r.val == tag){
if(r.max==2){
//Se leen las respuestas del cliente
local res = get_options_a(text)
gui.add_chat_message(res.ans, pl_bot, r.chanel, "", "", pos)

//Segundo cuestionario
gui.add_chat_message(ask_b, pl_bot, r.chanel, "", "", pos)
}
else if(r.max==1){
//Se leen las respuestas del cliente
local res = get_options_b(text)
gui.add_chat_message(res.ans, pl_bot, r.chanel, "", "", pos)
}
//Para contar las veces que se ejecuta
r.max--
if(r.max==0)
r.val = ""
}
}
}
}
}

function get_options_a(text){
local answer = "You entered an invalid option!."
local action = 0
if(text == "1"){
answer = "option one"
action = 1
}
else if(text == "2"){
answer = "option two"
action = 2
}
else if(text == "3"){
answer = "option three"
action = 3
}

return {ans = answer, act = action}
}

function get_options_b(text){
local answer = "You entered an invalid option!."
local action = 0
if(text == "A"){
answer = "option A"
action = 1
}
else if(text == "B"){
answer = "option B"
action = 2
}
else if(text == "C"){
answer = "option C"
action = 3
}

return {ans = answer, act = action}
}

Yona-TYT

Another interesting use that comes to mind is to give a welcome message to new clients and briefly explain the rules of the server.

Although a function is required to obtain the list of active clients.

Andarix

Quote from: Yona-TYT on November 26, 2024, 04:30:48 PMAnother interesting use that comes to mind is to give a welcome message to new clients and briefly explain the rules of the server.

...

is exists

wiki - simuconf.tab - network - server_motd_filename


example my server file

<title>Server Info</title>
<h1>Welcome</h1>
<p>
This is a server game with pak64.german.
</p>
<p>
The pak64.german is a graphic set with only one height.
</p>
<p>
Even if there is no speed bonus, speed is important. Since stations set the function in case of overcrowding,
it is important to choose the vehicles so that the speed and capacity are sufficient to avoid overcrowding
stations.
</p>
<p><strong>
For public stations, the maximum waiting time (recommendation 1 day) is set when a minimum load is set.
I reserve the right to remove vehicles with a minimum load but without a maximum waiting time.
</strong></p>
<p>
The server is still set to pause the game when no client is connected.<br>
Passwords are reset after 120 months of play after the last entry.
</p>


Yona-TYT

#7
Thanks to prissi's work with the rules, I've been able to make some progress on the scenario, enough to show a preview.

I'll post an executable later, since it uses this patch: 0001-Listen-and-Send-message-chat.patch

With this I made a rudimentary chat bot.
Captura de pantalla -2024-12-09 04-00-10.png


The-Land-of-Utopia.zip

Edit:

Test executables:

https://github.com/Yona-TYT/simutrans/releases/download/Nightly-test/simuwin64-SDL2-nightly.zip
https://github.com/Yona-TYT/simutrans/releases/download/Nightly-test/simulinux-x64-nightly.zip