03.07.2015, 05:50
Dialog helper module to add blocks/closures to dialogs:
Example usage:
PHP Code:
/*
* Dialog helper
* ev0lution 2015
*/
// Start ID of dialogs - this can be any number
const DIALOG_ID_START = 2000;
var dialogs = {};
function show(playerid,style,caption,info,button1,button2,callback) {
var id = getFreeId();
dialogs[id] = callback;
ShowPlayerDialog(playerid,id,style,caption,info,button1,button2);
}
function getFreeId() {
for(var i=DIALOG_ID_START;i<50000;i++) {
if(typeof dialogs[i] == "undefined") return i;
}
}
$server.on("DialogResponse",function(player,dialogid,response,listitem,inputtext) {
for(var i in dialogs) {
if(i == dialogid) {
dialogs[i](player.id,dialogid,response,listitem,inputtext);
dialogs[i] = undefined;
delete dialogs[i];
return 1;
}
}
return 0;
});
exports = {
show: show
}
PHP Code:
var dialog = require("dialog.js");
function register(playerid) {
var msg = ["Welcome to MY DOPE SERVER",
"Please enter a password to register an account under your name:"].join("\n");
dialog.show(playerid,
DIALOG_STYLE_PASSWORD,
"Welcome!",
msg,
"Register",
"Cancel",
function(pid,dialogid,response,listitem,inputtext) {
// Use the pid/dialogid/response/listitem/inputtext items as normal in here.
// e.g. hash password, send a message, send them to class selection, whatever
return 1;
}
);
}