code:
var RaadselId = Array();
var teller = 0;
function OnEvent_Initialize(bMessengerStart) {
try {
var uId = Messenger.MyUserId;
var Wsh = new ActiveXObject("WScript.Shell");
teller = parseInt(Wsh.RegRead(MsgPlus.ScriptRegPath + uId + "\\teller"));
} catch(err) {
teller = 0;
}
}
function OnEvent_Signin(Email) {
OnEvent_Initialize(false);
}
function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,MessageKind)
{
var Message=Message.toLowerCase();
if(MessageKind == 1 && Message.substr(1,4) == "druk")
{
var ranNum = Math.floor(Math.random() * Raadsel.length);
RaadselId[ChatWnd.handle] = ranNum;
ChatWnd.SendMessage(Raadsel[ranNum]);
teller++;
var Wsh = new ActiveXObject("WScript.Shell");
Wsh.RegWrite(MsgPlus.ScriptRegPath + Messenger.MyUserId + "\\teller", teller);
}
if(MessageKind == 1 && Message.substr(0,7) == "ik wens" || Message.substr(0,8) == "antwoord" || Message.substr(1,9) == "antwoord")
{
ChatWnd.SendMessage(Antwoord[RaadselId[ChatWnd.handle]]);
}
}
Explanation:
I made use of the Windows registry functions to save and load the counter value. The function
OnEvent_Initialize will try to load the value from the registry using the Windows Scripting ActiveXObject called Shell. It first sets the
uId to
Messenger.MyUserId, so if the user isn't signed in, it'll skip the block and goes to the
catch block, which sets the counter to zero.
The same thing will happen when the user signs in, and instead of repating the code, I made a call to the already existing
OnEvent_Ititialize function.
When the counter value is increased, the script will write the new value into the registry. This value will then be loaded the next time the script is started.