Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #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 (
03i++) {
      
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_0temp.character_1temp.character_2);
  }
  
  elseif (
params[0] == "delete") {
    (
"-SystemCharacter").deleteChar(player.accountparams[1]);
  }
}

//#CLIENTSIDE

function onActionClientside() {
  if (
params[0] == "returnStats") {
    
    for (
03i++) {
      (
"character" i).destroy();
      
this.(@ "character_" i) = new TStaticVar(@ "character" i);
      (
"character" i).loadvarsfromarray(params[1]);
      
    }
    
  }  
}

function 
onPlayerChats() {
  if (
player.chat=="/selectchar") {
    
showGUI();
  }
}

function 
onCreated() {
  
guiCharacterSelect.destroy();
  
triggerserver("gui"this.name"getStats"player.account);
}

public function 
showGUI() {
  if (
guiCharacterSelect != NULLguiCharacterSelect.destroy();

  
triggerserver("gui"this.name"getStats"player.account);
 
  new 
GuiControlProfile("guiTextProfile") {
    
this.fontcolor = {000};
    
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.= (screenwidth 2) - (this.width 2);
    
this.= (screenheight 2) - (this.height 2);
    
    
temp.distance 120;
    
    for (
03i++) {
      
      if ((
"character" i).firstname != NULL) {
        new 
GuiTextCtrl("guiCharacterSelect_nametext" i) {
          
this.70 + (temp.distance);
          
this.= -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.70 + (temp.distance);
          
this.50;
          
          
this.width 100;
          
this.height 100;
          
          
this.ani "idle";
        }
        
        new 
GuiButtonCtrl("guiCharacterSelect_buttonload" i) {
          
this.45 + (temp.distance);
          
this.98;
          
          
this.width 100;
          
this.height 20;
          
          
this.text "Load";
          
          
//thiso.catchevent(
        
}
        
        new 
GuiButtonCtrl("guiCharacterSelect_buttondelete" i) {
          
this.45 + (temp.distance);
          
this.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.45 + (temp.distance);
          
this.= -10;
          
this.width 100;
          
this.height 100;
          
          
this.text "Empty Slot";
          
          
this.useownprofile true;
          
this.profile "guiTextProfile";
        }
        
        new 
GuiButtonCtrl("guiCharacterSelect_buttoncreate" i) {
          
this.40 + (temp.distance);
          
this.60;
          
          
this.width 100;
          
this.height 20;
          
          
this.slot i;
          
          
this.text "Create";
          
          
thiso.catchevent(name"onAction""onCreateChar");
          
        }
        
      }
      
    }
  }
}

function 
onDeleteChar(objmodmousexmouseyclickcount) {
    
triggerserver("gui"this.name"delete"obj.slot);
    
showGUI();
}

function 
onCreateChar(objmodmousexmouseyclickcount) {
    (
"-GUICharacterCreation").showGUI(obj.slot);
    
guiCharacterSelect.destroy();

Reply With Quote
  #2  
Old 12-22-2008, 08:15 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
I fixed it, by placing a sleep() after the triggerserver() in the showGUI() function. I think the problem was that the triggers didn't have enough time to grab the data I needed before the GUI was drawn.

Last edited by Codein; 12-22-2008 at 08:28 PM..
Reply With Quote
  #3  
Old 12-23-2008, 05:14 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Yes, that was the problem.
__________________
Reply With Quote
Reply


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 07:37 PM.


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