Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-13-2009, 06:30 AM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
Finding the type of variable

Im trying to use this code to decide if params[1] is a number, string, or array. This is the only way I saw to do it. Its deciding if params[1] is an array or number. The params[1] is a this.variabe that could be either a string or array, and am trying to seperate the two in the actionserverside. help.

PHP Code:
  if (params[0] == "getReply")
  {
    
temp.idtype = params[1];
    if (
idtype.type() == 1)
      
triggerClient("weapon", this.name, "getReply", this.db.(@params[2]).info, params[1]);
    if (
idtype.type() == 3)
    {
      if (!(
params[3]) && !(params[4]))
        
triggerClient("weapon", this.name, "getReply2", this.db.(@params[2][0]).info, params[1]);
      if (!(
params[3]) && params[4])
        
triggerClient("weapon", this.name, "getReply3", this.db.(@params[2][1]).info, params[1]);
    }
  } 
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #2  
Old 12-13-2009, 06:49 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
I usually just use array.size() to check if it's an array but type works too.

PHP Code:
function onCreated() {
  
// Values
  
temp.arr = {1, 2, 3};
  
temp.obj = new TStaticVar();
  
temp.str = "abc";
  
temp.val = 1;
  
  
// Type  
  
echo(temp.arr.type()); // 3
  
echo(temp.obj.type()); // 2
  
echo(temp.str.type()); // 1
  
echo(temp.val.type()); // 0
} 
lol, misread the question.. Why not use two different params[0] like getReplySingle (when you're sending just a string) and getReplyMultiple (when you're sending an array)?
__________________
Quote:
Reply With Quote
  #3  
Old 12-13-2009, 07:28 AM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
Only because I don't know how to make it tell the difference on this part where it sends the server trigger, and as I see it the only other place to tell it what to do. Its clientside obviously, checking to see which row they picked, ect ect, sending the this.vars for reply2 or reply3 being false or true, and the npcid set on the level npc (which btw is working fine xD).

PHP Code:
function Npc_Chat_ItemList.onDblClick(entryid,entrytext,entryindex) {
  if (
entryid == 0)
  {
    if (
entrytext != "")
    {
      
triggerServer("weapon", this.name, "getReply", entryid, this.mynpcid, this.replyarray, this.replyarray2);
    }
  }
  if (
entryid == 1)
  {
    if (
entrytext != "")
    {
      
triggerServer("weapon", this.name, "getReply", entryid, this.mynpcid, this.replyarray, this.replyarray2);
    }
  }
  if (
entryid == 2)
  {
    if (
entrytext != "")
    {
      
triggerServer("weapon", this.name, "getReply", entryid, this.mynpcid, this.replyarray, this.replyarray2);
    }
  }
  if (
entryid == 3)
  {
    if (
entrytext != "")
    {
      
triggerServer("weapon", this.name, "getReply", entryid, this.mynpcid, this.replyarray, this.replyarray2);
    }
  }
} 
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #4  
Old 12-13-2009, 06:15 PM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
Ok, nm on that, I got it. Was just mixing stuff up the wrong way. Instead of having what I posted before. You can see the difference in the code posted below.

Having different problems now. I used a GuiMLTextCtrl in a GuiScrollCtrl to show up the chat. Now if you touch ANY npc that uses this, it will not work if you touched on already. Not sure why this happens. Also, if you hit right scroll button, you cant go back left. kinda weird. Here's the entire thing.

PHP Code:
function onCreated()
{
  
this.db = findnpc("NpcChat");
}
function 
onActionServerSide(){
  if (
params[0] == "getText")
  {
    
//3 is for array. 1 is for strings and 0 is for numbers.
    
if (params[1].type() == 1)
    {
        
triggerClient("weapon", this.name, "getText", this.db.(@params[1]).info);
    }
    if (
params[1].type() == 3)
    {
      if (!(
params[2]))
        
triggerClient("weapon", this.name, "getText2", this.db.(@params[1][0]).info);
      if (
params[2])
        
triggerClient("weapon", this.name, "getText2", this.db.(@params[1][1]).info);
    }
  }
  if (
params[0] == "getReply")
  {
    
temp.idtype = params[2];
    if (
idtype.type() == 1)
      
triggerClient("weapon", this.name, "getReply", this.db.(@params[2]).info, params[1]);
    if (
idtype.type() == 3)
    {
      if (!(
params[3]) && !(params[4]))
        
triggerClient("weapon", this.name, "getReply2", this.db.(@params[2][0]).info, params[1]);
      if (
params[3] && !(params[4]))
        
triggerClient("weapon", this.name, "getReply3", this.db.(@params[2][1]).info, params[1]);
    }
  }

}
//#CLIENTSIDE
function onActionClientSide(){
  if (
params[0] == "getText")
  {
    
temp.setup = params[1];
    
Npc_Chat_Window1.setText(temp.setup[0]);
    
Npc_Chat_MultiLine1.setText(temp.setup[1]);
    
Npc_Chat_ItemList.clearrows();
    
Npc_Chat_ItemList.addrow(0, temp.setup[2]);
    
Npc_Chat_ItemList.addrow(1, temp.setup[3]);
    
Npc_Chat_ItemList.addrow(2, temp.setup[4]);
    
Npc_Chat_ItemList.addrow(3, temp.setup[5]);
    
temp.img = temp.setup[6];
    
Npc_Chat_Image1.image = temp.img;
  }
  if (
params[0] == "getText2")
  {
    
temp.setup = params[1];
    
Npc_Chat_Window1.setText(temp.setup[0]);
    
Npc_Chat_MultiLine1.setText(temp.setup[1]);
    
Npc_Chat_ItemList.clearrows();
    
Npc_Chat_ItemList.addrow(0, temp.setup[2]);
    
Npc_Chat_ItemList.addrow(1, temp.setup[3]);
    
Npc_Chat_ItemList.addrow(2, temp.setup[4]);
    
Npc_Chat_ItemList.addrow(3, temp.setup[5]);
    
temp.img = temp.setup[6];
    
Npc_Chat_Image1.image = temp.img;
    
this.textarray = true;
  }
  if (
params[0] == "getReply")
  {
    
temp.setup = params[1];
    
Npc_Chat_Window1.setText(temp.setup[0]);
    if (
params[2] == 0)
    {
      
Npc_Chat_MultiLine1.setText(temp.setup[7]);
    }
    if (
params[2] == 1)
    {
      
Npc_Chat_MultiLine1.setText(temp.setup[8]);
    }
    if (
params[2] == 2)
    {
      
Npc_Chat_MultiLine1.setText(temp.setup[9]);
    }
    if (
params[2] == 3)
    {
      
Npc_Chat_MultiLine1.setText(temp.setup[10]);
    }
    
Npc_Chat_ItemList.clearrows();
    
temp.img = temp.setup[6];
    
Npc_Chat_Image1.image = temp.img;
  }
  if (
params[0] == "getReply2")
  {
    if (!(
this.replyarray))
    {
      
temp.setup = params[1];
      
Npc_Chat_Window1.setText(temp.setup[0]);
      if (
params[2] == 0)
      {
        
Npc_Chat_MultiLine1.setText(temp.setup[7]);
      }
      if (
params[2] == 1)
      {
        
Npc_Chat_MultiLine1.setText(temp.setup[8]);
      }
      if (
params[2] == 2)
      {
        
Npc_Chat_MultiLine1.setText(temp.setup[9]);
      }
      if (
params[2] == 3)
      {
        
Npc_Chat_MultiLine1.setText(temp.setup[10]);
      }
      
Npc_Chat_ItemList.clearrows();
      
temp.img = temp.setup[6];
      
Npc_Chat_Image1.image = temp.img; 
      
this.replyarray = true;
      
this.replyarray2 = false;
      
scheduleEvent(4, "onReadAgain", null);
    }
  }
  if (
params[0] == "getReply3")
  {
    if (!(
this.replyarray2))
    {
      
temp.setup = params[1];
      
Npc_Chat_Window1.setText(temp.setup[0]);
      if (
params[2] == 0)
      {
        
Npc_Chat_MultiLine1.setText(temp.setup[7]);
      }
      if (
params[2] == 1)
      {
        
Npc_Chat_MultiLine1.setText(temp.setup[8]);
      }
      if (
params[2] == 2)
      {
        
Npc_Chat_MultiLine1.setText(temp.setup[9]);
      }
      if (
params[2] == 3)
      {
        
Npc_Chat_MultiLine1.setText(temp.setup[10]);
      }
      
Npc_Chat_ItemList.clearrows();
      
temp.img = temp.setup[6];
      
Npc_Chat_Image1.image = temp.img;
      
this.replyarray2 = false;
      
this.replyarray = false;
      
this.textarray = false;
    }
  }

}
function 
onReadAgain()
{
  
triggerServer("weapon", this.name, "getText", this.mynpcid, this.textarray);
}
public function 
OpenWindow( data ){
  
this.mynpcid = temp.data;
  if (
Npc_Chat_Text1 != NULL)
  {
    
Npc_Chat_Window1.destroy();
  }
  
this.textarray = false;
  
triggerServer("weapon", this.name, "getText", this.mynpcid, this.textarray);
  new 
GuiWindowCtrl("Npc_Chat_Window1") {
    
profile = GuiBlueWindowProfile;
    
clientrelative = true;
    
clientextent = "211,231";
    
useOwnProfile = true;
    
profile.bitmap = "guiarm_window.png";
    
canmove = true;
    
canresize = true;
    
closequery = false;
    
destroyonhide = false;
    
text = "Loading...";
    
x = 309;
    
y = 88;
    
    new 
GuiScrollCtrl("Npc_Chat_MultiLine1_Scroll") {
       
profile = GuiBlueScrollProfile;
       
useOwnProfile = true; 
       
profile.bitmap = "guiarm_scroll.png"; 
       
height = 130;
       
hscrollbar = "dynamic";
       
vscrollbar = "dynamic";
       
width = 150;
       
x = 46;
       
//y = 143;

       
new GuiMLTextCtrl("Npc_Chat_MultiLine1") {
         
profile = GuiBlueMLTextProfile;
         
height = 130;
         
//horizsizing = "width";
         
text = "Loading...";
         
width = 150;
       }
    }
    new 
GuiScrollCtrl( "Npc_Chat_Scroll" ) {
      
this.width = 176;
      
this.height = 75;
      
profile.bitmap = "guiarm_scroll.png";
      
this.x = 19;
      
this.y = 143;

      
this.hScrollBar = "alwaysOff";
      
this.vScrollBar = "dynamic";

      new 
GuiTextListCtrl( "Npc_Chat_ItemList" ) {
        
profile.bitmap = "guiarm_window.png";
        
this.width = 25;
        
this.height = 33;
      }
    }
    new 
GuiShowImgCtrl("Npc_Chat_Image1") {
      
x = 9;
      
partx = 0;
      
party = 60;
      
partw = 50;
      
parth = 36;
      
width = 150;
      
height = 150;
      
image = "block.png";
    }
  }
}
function 
Npc_Chat_ItemList.onDblClick(entryid,entrytext,entryindex) {
  if (
entryid == 0)
  {
    if (
entrytext != "")
    {
      
triggerServer("weapon", this.name, "getReply", entryid, this.mynpcid, this.replyarray, this.replyarray2);
    }
  }
  if (
entryid == 1)
  {
    if (
entrytext != "")
    {
      
triggerServer("weapon", this.name, "getReply", entryid, this.mynpcid, this.replyarray, this.replyarray2);
    }
  }
  if (
entryid == 2)
  {
    if (
entrytext != "")
    {
      
triggerServer("weapon", this.name, "getReply", entryid, this.mynpcid, this.replyarray, this.replyarray2);
    }
  }
  if (
entryid == 3)
  {
    if (
entrytext != "")
    {
      
triggerServer("weapon", this.name, "getReply", entryid, this.mynpcid, this.replyarray, this.replyarray2);
    }
  }
} 
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...



Last edited by sssssssssss; 12-13-2009 at 06:49 PM..
Reply With Quote
  #5  
Old 12-13-2009, 07:02 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Well it looks like you're trying to destroy the GUI and re-create it in the same function, which can cause Exception errors. To get around that I do:

PHP Code:
//#CLIENTSIDE
// Assumed Code Above
public function OpenWindow( data ){ 
  if (
isObject("Npc_Chat_Window1")) {
    
Npc_Chat_Window1.destroy();
  }
  
this.mynpcid = temp.data; 
  
this.textarray = false; 
  
triggerServer("weapon", this.name, "getText", this.mynpcid, this.textarray);
  
// Have the GUI re-created a frame later.
  
this.scheduleevent(0.05, "CreateGUI", "");
}

function 
onCreateGUI() {
  new 
GuiWindowCtrl("Npc_Chat_Window1") { 
    
profile = GuiBlueWindowProfile; 
    
clientrelative = true; 
    
clientextent = "211,231"; 
    
useOwnProfile = true; 
    
profile.bitmap = "guiarm_window.png"; 
    
canmove = true; 
    
canresize = true; 
    
closequery = false; 
    
destroyonhide = true; // Will destroy the window when it's closed.
    
visible = true; // Will make sure the window is visible. 
    
text = "Loading..."; 
    
x = 309; 
    
y = 88; 
     
    new 
GuiScrollCtrl("Npc_Chat_MultiLine1_Scroll") { 
       
profile = GuiBlueScrollProfile; 
       
useOwnProfile = true;  
       
profile.bitmap = "guiarm_scroll.png";  
       
height = 130; 
       
hscrollbar = "dynamic"; 
       
vscrollbar = "dynamic"; 
       
width = 150; 
       
x = 46; 
       
//y = 143; 

       
new GuiMLTextCtrl("Npc_Chat_MultiLine1") { 
         
profile = GuiBlueMLTextProfile; 
         
height = 130; 
         
//horizsizing = "width"; 
         
text = "Loading..."; 
         
width = 150; 
       } 
    } 
    new 
GuiScrollCtrl( "Npc_Chat_Scroll" ) { 
      
this.width = 176; 
      
this.height = 75; 
      
profile.bitmap = "guiarm_scroll.png"; 
      
this.x = 19; 
      
this.y = 143; 

      
this.hScrollBar = "alwaysOff"; 
      
this.vScrollBar = "dynamic"; 

      new 
GuiTextListCtrl( "Npc_Chat_ItemList" ) { 
        
profile.bitmap = "guiarm_window.png"; 
        
this.width = 25; 
        
this.height = 33; 
      } 
    } 
    new 
GuiShowImgCtrl("Npc_Chat_Image1") { 
      
x = 9; 
      
partx = 0; 
      
party = 60; 
      
partw = 50; 
      
parth = 36; 
      
width = 150; 
      
height = 150; 
      
image = "block.png"; 
    } 
  } 
} 
I also set the booleans in destroyonhide to true and visible to true, as it may be related to your problem, but we'll see.
__________________
Quote:
Reply With Quote
  #6  
Old 12-13-2009, 07:36 PM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
There are some Close (X) in the ItemList, besides that, it fixed the problem of only opening once, but it still doesnt move the scroll on the horizontal except once.
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #7  
Old 12-13-2009, 07:53 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
It's because your MLTextCtrl is the same size as your ScrollCtrl, make your MLTextCtrl thinner. I changed it to 150, and hid the scrollbar because it does word-wrap automatically based on your MLTextCtrl's width.
__________________
Quote:
Reply With Quote
  #8  
Old 12-13-2009, 08:05 PM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
Ahh, yes that fixed it.

thanks for the helpers. Racked my head doin this one.
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


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 05:39 PM.


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