The Topic
You know those messages that many servers have, announcing when people log on or off? Well, that's what we'll be doing today. It's actually rather simple.
The Explanation
Well, first we need to find a piece of code that gets called when a user logs on. If we search for 'logon', one of the things that comes up is the function 'userLogOn' in timeoutobjects.ls. Great - from here, we can easily put in a simple message announcing the user. on userLogOn (me, movie, group, user)
set ChrName = user.name
if not ChrName contains "newchar" then
movie.SendMessage("@AllUsers","sqa","*** "&ChrName&" has logged on.")
else
--here is where you would announce a character being created
end if
movie.sendmessage("@AllUsers", "934", ChrName)
end
So we're sending the sqa message to all users, with our message as the data. Sqa is a message that makes the text appear in white in the users' text area, like something that you said would.
If a player's name contains newchar, then they are in the character creation screen, so we don't want to announce them in the same way. The if statement prevents this. The not in the if statement reverse the value of the following code, making the if statement run if ChrName dosen't contain 'newchar'.
How would we add detection for immortals, so they could be announced differently? If we search for 'immortals.txt', the file in which they are stored, we come up with some code that reads in the file and checks it. Couldn't we put that in it's own function, for easy access? Yup! on PlayerIsImmortal(TheName)
set FilName = "C:\FSOServer\DAT\SETTINGS\immortals.txt"
set IMMMs = file(FilName).read --load in the file
--setup a string that would identify the player as immortal
set CheckName = "*" & string(user.name) & "*"
if IMMMs contains CheckName then --if the player's string is in the file
return TRUE --true; they're immortal
else
return FALSE --otherwise, false; they're not
end if
end
So, we now have our own function to test if the player is immortal, which we can put in our own file or in one of the existing files, such as 'timeoutobjects.ls'. How would we use this function to give immortals their own welcome message, though? on userLogOn (me, movie, group, user)
set ChrName = user.name
if not ChrName contains "newchar" then
if PlayerIsImmortal(ChrName) = TRUE then
movie.SendMessage("@AllUsers","sqa","*** Admin "&ChrName&" has logged on.")
else
movie.SendMessage("@AllUsers","sqa","*** "&ChrName&" has logged on.")
end if
end if
movie.sendmessage("@AllUsers", "934", ChrName)
end
We simply take the value that our function returns, and if it's true, we know to broadcast the admin message. Otherwise, we broadcast the usual message. We also make sure that this isn't a character being created, as in the login script.
In order to add a log off message, you would simply have to take our if statement and put it in the 'userLogOff' function as well, changing the message to fit the new location as well.
|