Author Topic: Require a small code snippet.  (Read 1007 times)

I need a bit of simple code that will do the following:
I say a word in chat such as blue, then the console will say a response such as: red

Ok, Thankies in advance.

Because giving the console a massive brain allowing it to respond to anything (seeing how you only gave an example) will only be in a small code snippet.

Look at other mods and sources for anything similar ("enter things in chat" comes in various mods with special commands, "console talk" can be found by searching) before coming here.

Post any code you've found and how you've attempted to modify it, don't just ask people to spoon-feed you the answers.

I found this in Ibans City RPG:

Code: [Select]
function serverCmdmessageSent(%client, %text)
{
if(getSubStr(%text, 0, 1) $= "Blue")
talk("Red");
      parent::serverCmdmessageSent(%client, %text);
}
Unfortunately I cannot get it to work.

getSubStr(%text, 0, 1) will return the first character of the text, so will return "B". Use a 4 instead of 1.

It needs to be in a package if it isn't already. Most mods use these now.

Ok here is my attempt:
Code: [Select]
package blue
{
function serverCmdmessageSent(%client, %text)
{
if(getSubStr(%text, 0, 4) $= "Blue")
talk("Red");
      parent::serverCmdmessageSent(%client, %text);
}
};
activatePackage(blue);

« Last Edit: March 20, 2010, 06:19:51 AM by Fluff-is-back »

Looks all right. Does it work in-game?

No, I say blue and nothing happens in chat or in the console.

Run the game with only default mods and your thing enabled, say "blue" once into the chat, close it and post the console.log file in your Blockland folder here.

Make sure you capitalize "Blue".

Or use a strlwr() on it.

Ok, here is log for executing; no problems

Loading Add-On: server_blue (CRC:-1833578020)
Executing Add-Ons/server_blue/server.cs.
0 datablocks added.


Here is after game loads and my attempt at triggering it:

*** LOADING MISSION: Add-Ons/Map_Alpines/Alpines.mis
*** Stage 1 load
Mission Name: Alpines
Mission SaveName: Alpines
Mission Description:
*** Stage 2 load
Executing Add-Ons/Map_Alpines/Alpines.mis.
*** Mission loaded
Posting to master server
Got connect request from IPX:00000000:000000000000:0
  net name = Fluff-is-back
Connection established
Connected successfully, killing other pending connections
AUTHCHECK: Fluff-is-back = LAN client -> internet server, auth with server ip
Auth Init Successfull: Fluff-is-back
CADD: 13474 local
 +- bl_id = 12297
 +- AUTO SUPER ADMIN (ID same as host)
*** Sending mission load to client: Add-Ons/Map_Alpines/Alpines.mis
Posting to master server
Posting to rtb server
*** New Mission: Add-Ons/Map_Alpines/Alpines.mis
*** Phase 1: Download Datablocks & Targets
Fluff-is-back: Blue
Fluff-is-back: blue
Destroying NET Server
*** ENDING MISSION

Replace your code with this and get the same log parts: (it should put a line in the console "Test" every time you say something and then "Respond" if it's "Blue")
Code: [Select]
package blue
{
function serverCmdmessageSent(%client, %text)
{
echo("Test - " @ getSubStr(%text, 0, 4));
if(getSubStr(%text, 0, 4) $= "Blue")
{
echo("Respond");
talk("Red");
}
parent::serverCmdmessageSent(%client, %text);
}
};
activatePackage(blue);

Still nothing

console log:
Posting to master server
Posting to rtb server
*** New Mission: Add-Ons/Map_Alpines/Alpines.mis
*** Phase 1: Download Datablocks & Targets
Fluff-is-back: meh
Fluff-is-back: Blue
*** Phase 2: Download Ghost Objects
*** Phase 3: Mission Lighting
  Successfully loaded mission lighting file: 'Add-Ons/Map_Alpines/Alpines_3ba01c77.ml'
Mission lighting done
Fluff-is-back spawned.
Fluff-is-back: Blue
Destroying NET Server
*** ENDING MISSION
CDROP: 9417 IPX:00000000:000000000000:0
Exporting server prefs...
De-activating package: TankPackage
De-activating package: PirateCannonPackage
De-activating package: RTBS_Authentication
De-activating package: RTBS_GUITransfer
De-activating package: RTBS_ServerControl


Wait, from your last console log it never seems to activate the package.

Blockland takes things in zip files to have a higher priority than ones in normal folders so make sure one isn't overwriting your server.cs file. You may also need to check that your computer is displaying file extensions right. (e.g. "server.cs" not "server.cs.txt" with the last part hidden)