Clientside to Serverside Interaction
Note that the trigger name needs to be lowercase, for example "clicked" or "actionmusic".
// Clientside script
function onPlayerTouchsMe(pl) {
var popup = GUI.showpopup({
title: "Welcome to " + Server.getconfig().gamename + "!",
width: 400,
height: 300
});
popup.innerHTML = '<br><center>Hmmm cool!</center>' +
'<img src="../files/icons/corleone_icon_spar.png">' +
'<input id="actionbutton1" type="submit" class="button" style="left:100px;top:160px;width:200px;height:40px;" value="Button 1!"></input>' +
'<input id="actionbutton2" type="submit" class="button" style="left:100px;top:220px;width:200px;height:40px;" value="Button 2!"></input>';
var self = this;
GUI.onclick("actionbutton1", function(event) {
GUI.hidepopup();
self.triggerserver("clicked", "button1");
});
GUI.onclick("actionbutton2", function(event) {
GUI.hidepopup();
self.triggerserver("clicked", "button2");
});
}
// Serverside script
function onClientClicked(pl, buttonname) {
this.say(pl.name + " clicked on " + buttonname);
}
Serverside to Clientside Interaction
// Serverside script
function onPlayerTouchsMe(pl) {
this.say("Triggered stop music!");
this.triggerclient(pl, "actionmusic", "stopsong" );
}
// Clientside script
function onServerActionMusic(pl, action) {
if (action == "stopsong") {
this.stopmusic();
this.say(pl.name + " stopped the music");
}
}