Jump to content
  • 0

Random/Variable Mes


Azura Skyy

Question


  • Group:  Members
  • Topic Count:  49
  • Topics Per Day:  0.01
  • Content Count:  545
  • Reputation:   220
  • Joined:  03/01/13
  • Last Seen:  

I'm want to know if it is possible to have an NPC greet the player with a random message (of some 5-10 message for example), and how I would do that. Sorry if it's a stupid question, I usually have someone else doing my scripting.

 

I've been looking through the rAthena wiki at various scripting commands (var/rand/array) and I can't seem to find the solution to my question.

This is taken from the rAthena Wiki article on Variables

If you are using the mes command, or another text displaying command, it works a bit differently:

mes #var; // Will display a line with only the value of #var.
mes "You have killed " + dead_porings + " Porings.";  // Will display this: 
						      // "You have killed <value of dead_porings>
						      // Porings."
mes @name$; // If @name$ contains "[Kafra]", it will display "[Kafra]"
mes "My name is "+@name$; // If @name$ contains "Trevor", it will display: "My name is Trevor"

 

Any help is appreciated. If possible, please provide an example script.

Thanks in advance,
~Azura Skyy

 

 

Link to comment
Share on other sites

4 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  14
  • Topics Per Day:  0.00
  • Content Count:  104
  • Reputation:   27
  • Joined:  12/05/13
  • Last Seen:  

You can use the F_Rand function in /npc/other/Global_Functions.txt

.

mes callfunc("F_Rand","Mes 1","Mes 2");
  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  660
  • Reputation:   668
  • Joined:  11/12/12
  • Last Seen:  

I'm not a big scripter, but you could try the following : 

setarray .@greetingMessages$[0], "have a nice day", "message2", "message3";
.@greetingId = rand(0,getarraysize(.@greetingMessages$) - 1);
mes "Hello player, " + .@greetingMessages$[.@greetingId] + ".";
Edited by Tokei
  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  49
  • Topics Per Day:  0.01
  • Content Count:  545
  • Reputation:   220
  • Joined:  03/01/13
  • Last Seen:  

 

I'm not a big scripter, but you could try the following : 

setarray .@greetingMessages$[0], "have a nice day", "message2", "message3";
.@greetingId = rand(0,getarraysize(.@greetingMessages$) - 1);
mes "Hello player, " + .@greetingMessages$[.@greetingId] + ".";

 

Looks promising. I'm having difficulties with VNC at the moment, so I'm unable to test this, but I'm sure I'll get an opportunity to sort things out tomorrow night.

Thanks in advance,

~Azura Skyy

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  49
  • Topics Per Day:  0.01
  • Content Count:  545
  • Reputation:   220
  • Joined:  03/01/13
  • Last Seen:  

I'd like to thank both of you, as both of these solutions work perfectly, of course, Nerfwood's is a much cleaner solution to my particular problem.

 

 

 

I'm not a big scripter, but you could try the following : 

setarray .@greetingMessages$[0], "have a nice day", "message2", "message3";
.@greetingId = rand(0,getarraysize(.@greetingMessages$) - 1);
mes "Hello player, " + .@greetingMessages$[.@greetingId] + ".";

 

 

Tokei, your solution will still be used for the NPC I originally intended this for, and to make it work as a 'random message' I just changed the text.

mes "Hello player, " + .@greetingMessages$[.@greetingId] + ".";

Changed to

mes "" + .@greetingMessages$[.@greetingId] + "";

With that, it functions purely as a 'random message.' Thanks for your reply. Much appreciated!

 

 

 

You can use the F_Rand function in /npc/other/Global_Functions.txt

.

mes callfunc("F_Rand","Mes 1","Mes 2");

 

Nerfwood, as I said before, your solution is definitely a lot simpler and cleaner. I'm using your solution for an NPC as well. Always nice to see multiple ways of going about a solution and it's taught me a bit more about scripting.

Thank you both,
~Azura Skyy

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...