What this script is meant to do is:
Show the characters the player currently has, and if there's an empty character slot, display Empty Character.
The problem is, I have to update the NPC or call showGUI() twice for changes to be made. For example, if I create a character and go back to the this GUI, it doesn't update the information until I call showGUI again.
Another example: I have to click the "Delete" button twice to show the changes.
I'm not very good with explanations, so it might be a little hard to understand.
PHP Code:
function onActionServerside() {
if (params[0] == "getStats") {
for (i = 0; i < 3; i++) {
temp.info = new TStaticVar();
temp.info.loadvars("mud/characters/" @ params[1] @ "_" @ i);
temp.(@ "character_" @ i) = temp.info.savevarstoarray(0);
}
findPlayer(params[1]).triggerclient("gui", name, "returnStats", temp.character_0, temp.character_1, temp.character_2);
}
elseif (params[0] == "delete") {
("-SystemCharacter").deleteChar(player.account, params[1]);
}
}
//#CLIENTSIDE
function onActionClientside() {
if (params[0] == "returnStats") {
for (i = 0; i < 3; i++) {
("character" @ i).destroy();
this.(@ "character_" @ i) = new TStaticVar(@ "character" @ i);
("character" @ i).loadvarsfromarray(params[i + 1]);
}
}
}
function onPlayerChats() {
if (player.chat=="/selectchar") {
showGUI();
}
}
function onCreated() {
guiCharacterSelect.destroy();
triggerserver("gui", this.name, "getStats", player.account);
}
public function showGUI() {
if (guiCharacterSelect != NULL) guiCharacterSelect.destroy();
triggerserver("gui", this.name, "getStats", player.account);
new GuiControlProfile("guiTextProfile") {
this.fontcolor = {0, 0, 0};
this.fontsize = 20;
this.fontstyle = "bc";
}
new GuiWindowCtrl("guiCharacterSelect") {
destroyonhide = true;
this.width = 420;
this.height = 200;
canresize = false;
canmaximize = false;
canminimize = false;
canclose = false;
this.x = (screenwidth / 2) - (this.width / 2);
this.y = (screenheight / 2) - (this.height / 2);
temp.distance = 120;
for (i = 0; i < 3; i++) {
if (("character" @ i).firstname != NULL) {
new GuiTextCtrl("guiCharacterSelect_nametext" @ i) {
this.x = 70 + (i * temp.distance);
this.y = -10;
this.useownprofile = true;
this.profile = "guiTextProfile";
this.width = 120;
this.height = 100;
this.text = "Slot" SPC i + 1;
}
new GuiShowImgCtrl("guiCharacterSelect_charimg" @ i) {
this.x = 70 + (i * temp.distance);
this.y = 50;
this.width = 100;
this.height = 100;
this.ani = "idle";
}
new GuiButtonCtrl("guiCharacterSelect_buttonload" @ i) {
this.x = 45 + (i * temp.distance);
this.y = 98;
this.width = 100;
this.height = 20;
this.text = "Load";
//thiso.catchevent(
}
new GuiButtonCtrl("guiCharacterSelect_buttondelete" @ i) {
this.x = 45 + (i * temp.distance);
this.y = 128;
this.width = 100;
this.height = 20;
this.text = "Delete";
this.slot = i;
thiso.catchevent(name, "onAction", "onDeleteChar");
}
}
else {
new GuiTextCtrl("guiCharacterSelect_emptytext" @ i) {
this.x = 45 + (i * temp.distance);
this.y = -10;
this.width = 100;
this.height = 100;
this.text = "Empty Slot";
this.useownprofile = true;
this.profile = "guiTextProfile";
}
new GuiButtonCtrl("guiCharacterSelect_buttoncreate" @ i) {
this.x = 40 + (i * temp.distance);
this.y = 60;
this.width = 100;
this.height = 20;
this.slot = i;
this.text = "Create";
thiso.catchevent(name, "onAction", "onCreateChar");
}
}
}
}
}
function onDeleteChar(obj, mod, mousex, mousey, clickcount) {
triggerserver("gui", this.name, "delete", obj.slot);
showGUI();
}
function onCreateChar(obj, mod, mousex, mousey, clickcount) {
("-GUICharacterCreation").showGUI(obj.slot);
guiCharacterSelect.destroy();
}