f
s
o

s
c
r
i
p
t
i
n
g

index tutorials scripts links closetpacifist

The Topic

So, you want to write a bit of script that'll run when a user tells it to? Well, we can't create our own /kick type commands, but we can hijack the broadcast script. That way, when someone broadcasts the command that we're looking for, we'll be able to act on this.

In this example, we'll make it so that when a player broadcasts 'hello', the scripts will greet him.




The Explanation

First, we need to hijack the part of the server scripts that deal with broadcasting, right? So, if we search for 'broadcast' in, say, GlobalScripts.ls, we soon find a line of code which looks like Broadcast:. After that it does some stuff and then broadcasts the actual message.

Looks useful, eh? Well, if you look at it, it seems that the variable TheBCast contains the message that the user broadcasted, and TheName the name of the user. So, from there, it's easy to write the following after the first few lines after "Broadcast":

   if TheBCast = "hello" then
      --hmm
   end if

But... how do we get it to broadcast the hello message? What should we put in place of the --hmm line? Well, if you look a little fruther down, you'll see that it broadcasts the actual message with a line of code like this:

movie.sendmessage("@AllUsers", "Broadcast", BCastDat)

Nifty! We see that, a little earlier, it set BCastDat to the full broadcasted message string that you see in the game. So, from there, we can change our code above to:

   if TheBCast = "hello" then
      movie.sendmessage("@AllUsers", "Broadcast", "*** Hello there "&TheName&". ***")
   end if

Alright... So, we're just subbing in our greeting string in place of the broadcast data, right? But what's that TheName bit doing there? Well, in Lingo, &s let you add bits of strings together. So, we're taking our strings and stiching TheName - the user's name - into it.

So it should display "*** Hello there YourName.***" to everyone on the server, right? Yup!