Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 12-22-2008, 07:59 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Needing to call the function twice

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();
} 
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:54 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.