Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   Problem with Custom Inventory (https://forums.graalonline.com/forums/showthread.php?t=79691)

Stryke 05-11-2008 04:58 AM

Problem with Custom Inventory
 
PHP Code:

//#CLIENTSIDE
function onCreated(){ setTimer(0.05); disableselectweapons(); }

function 
onKeyPressed( code, key )
{
  if (
key == "q")
  {
    
client.qo = 1 - client.qo;
  }
}

function 
onTimeout()
{
  if (
client.qo = NULL)
    
hideMenu();
  else 
showMenu();
  
    if(
client.qo = 1)
    {
      
mx = int( mousescreenx - thiso.qx + 620);
      
my = int( mousescreeny - thiso.qy + 225);
      for(
temp.j=0;temp.j<player.weapons.size();temp.j++;) {
      
temp.i = findimg(201 + temp.j);
      if ( 
mx in | temp.i.x, temp.i.x + 16 | && my in | temp.i.y, temp.i.y + 16 | )
      {
        
showtext(301,temp.i.x+16,temp.i.y+36,"Arial","bc",thiso.item_name[this.temp_count]);
        
changeimgvis(301,6);
        
changeimgzoom(301,0.5);
      }
      else 
hideimg(301);
      }
    }
  
  
setTimer(0.05);
}

function 
showMenu()
{
  
thiso.qx = screenwidth / 2 + 180;
  
thiso.qy = screenheight / 2 - 100;  
  
with (findimg(200))
  {
    
image = "cyn_inventory_gui.gif";
    
x = thiso.qx;
    
y = thiso.qy;
    
layer = 4;
  }
  
thiso.item_name = NULL;
  
thiso.item_image = NULL;
  
thiso.item_pos = NULL;
  
thiso.item_list = NULL;
  
thiso.item_count = 0;
  
hideimgs(201,221);
  for (
temp.i: player.weapons)
  {
    if (
temp.i.name.starts("-")==0) {
      
thiso.item_name.add(temp.i.name);
      
thiso.item_image.add(temp.i.image);
      
thiso.item_pos.add(temp.i);
    }
  }
  for(
thiso.i=0; thiso.i<5; thiso.i++;)
  {
    for(
thiso.j=0; thiso.j<4; thiso.j++;)
    {
      
with(findimg(201 + thiso.item_count))
      {
        
image = thiso.item_image[thiso.item_count];
        
x = thiso.qx + 76 + (thiso.j * 45);
        
y = thiso.qy + 52 + (45*thiso.i);
        
layer = 5;
        
thiso.item_list[item_count] = findimg(201 + thiso.item_count);
        
thiso.item_count += 1;
      }
    }
  }
}

function 
hideMenu()
{
  
hideimgs(200,250);
  
hideimgs(300,350);
} 

When i put my mouse on the items I have, the text don't appear. Anyone know why?

cbk1994 05-11-2008 05:03 AM

I would use GuiShowImg and add a hint = "" to it.

Stryke 05-11-2008 05:10 AM

Can you show me an example I have never used it before. =/

cbk1994 05-11-2008 05:13 AM

PHP Code:

new GuiShowImgCtrl( "Inventory_Window" )
{
  
x = 0;
  
y = 0;
  
width = 200;
  
height = 200;
  
image = "inventory.png";
  new 
GuiShowImgCtrl( "Inventory_Item" )
  {
    
width = 32;
    
height = 32;
    
x = 20;
    
y = 20;
    
image = player.weapon.image;
  }
} 


Stryke 05-11-2008 05:33 AM

PHP Code:

//#CLIENTSIDE
function onCreated(){ setTimer(0.05); disableselectweapons(); }

function 
onKeyPressed( code, key )
{
  if (
key == "q")
  {
    
client.qo = 1 - client.qo;
  }
}

function 
onTimeout()
{
  if (
client.qo = NULL)
    
hideMenu();
  else 
showMenu();
  
setTimer(0.05);
}

function 
showMenu()
{
  
thiso.qx = screenwidth / 2 + 100;
  
thiso.qy = screenheight / 2 - 100;
  
thiso.item_name = NULL;
  
thiso.item_image = NULL;
  
thiso.item_pos = NULL;
  
thiso.item_list = NULL;
  
thiso.item_count = 0;
  
  for (
temp.i: player.weapons)
  {
    if (
temp.i.name.starts("-")==0) {
      
thiso.item_name.add(temp.i.name);
      
thiso.item_image.add(temp.i.image);
      
thiso.item_pos.add(temp.i);
    }
  }
  
  new 
GuiShowImgCtrl("Inv_Window")
  {
    
x = thiso.qx;
    
y = thiso.qy;
    
width = 411;
    
height = 280;
    
image = "cyn_inventory_gui.gif";
  
    for(
thiso.i=0; thiso.i<5; thiso.i++;)
    {
      for(
thiso.j=0; thiso.j<4; thiso.j++;)
      {
        new 
GuiShowImgCtrl("InvItem_"@thiso.item_count)
        {
          
width = 32;
          
height = 32;
          
x = thiso.qx + 76 + (thiso.j * 45);
          
y = thiso.qy + 52 + (45*thiso.i);
          
image = thiso.item_image[thiso.item_count];
          
thiso.item_list[thiso.item_count] = "InvItem_"@thiso.item_count;
          
thiso.item_count += 1;
        }
      }
    }
  }
}

function 
hideMenu()
{
  
Inv_Window.destroy();
} 

Well, I just tried and my items won't even show up? =/

EDIT: NVM WORKS FINE. I just had to delete gx, and gy.

Stryke 05-11-2008 05:44 AM

Is there a way to make the Hint overlap the mouse..?

and why doesnt this work?

PHP Code:

function InvItem_0.onMouseDragged() {
  
InvItem_0.x = mousex;
  
InvItem_0.y = mousey;
} 


Inverness 05-11-2008 05:59 AM

mousex and mousey are in tiles which show where the mouse is in the level. Gui controls use pixels because they're not in a level. You should use mousescreenx and mousescreeny which are also in pixels and represent where the mouse is on the screen not the level.

If that doesn't fix it then you should be more specific about the problem.

Stryke 05-11-2008 03:14 PM

PHP Code:

function InvItem_0.onMouseDown() {
  for(
temp.i=0;temp.i<player.weapons.size();temp.i++;)
  {
    if(
player.weapons[temp.i].name == InvItem_0)
    {
      
temp.var == temp.i;
      break;
    }
  }
  
selectedweapon = temp.var;
} 

How would I make it so that if you click an item, it will equip it?
This won't work.. Also is it possible to put a function in a for statement because I don't want to make 20 function InvItem_x.onMouseDown's.

Robin 05-11-2008 04:05 PM

Lookup catchevent on the wiki if you're working with GUI's

And what do you mean by equip?

Stryke 05-11-2008 04:22 PM

By equip i mean selectedweapon = index of weapon i want equipped.

cbk1994 05-11-2008 04:27 PM

Quote:

Originally Posted by Stryke (Post 1390220)
PHP Code:

function InvItem_0.onMouseDown() {
  for(
temp.i=0;temp.i<player.weapons.size();temp.i++;)
  {
    if(
player.weapons[temp.i].name == InvItem_0)
    {
      
temp.var == temp.i;
      break;
    }
  }
  
selectedweapon = temp.var;
} 

How would I make it so that if you click an item, it will equip it?
This won't work.. Also is it possible to put a function in a for statement because I don't want to make 20 function InvItem_x.onMouseDown's.

PHP Code:

function InvItem_0.onMouseDown() {
  for(
temp.i=0;temp.i<player.weapons.size();temp.i++;)
  {
    if(
player.weapons[temp.i].itemName == InvItem_0)
    {
      
player.selectedweapon = temp.i;
      return;
    }
  }
} 

and then in your items

PHP Code:

new GuiShowImgCtrl( "InvItem_0" )
{
  
image = "x.png";
  
width = 32;
  
height = 32;
  
x = 10;
  
y = 10;
  
  
this.itemName = "Guns/KABOOM!!!111!!";
} 

'name' is reserved by default.

Stryke 05-11-2008 04:57 PM

Thanks how about my other question:
Also is it possible to put a function in a for statement because I don't want to make 20 function InvItem_x.onMouseDown's.

I don't really understand how the catchevent works?

cbk1994 05-11-2008 05:13 PM

PHP Code:

new GuiShowImgCtrl( "InvItem_0" )
{
  
image = "x.png";
  
width = 32;
  
height = 32;
  
x = 10;
  
y = 10;
  
  
this.itemName = "Guns/KABOOM!!!111!!";
  
thiso.catchevent( name, "onMouseDown", "onItemSelected" );
} 

and later something like this:

PHP Code:

function onItemSelected( obj )
{
    for(
temp.i=0;temp.i<player.weapons.size();temp.i++;)
    {
      if(
player.weapons[temp.i].name == obj.itemName)
      {
        
player.selectedweapon = temp.i;
        return;
      }
    }
} 

I believe that will work.

zokemon 05-12-2008 11:26 AM

Quote:

Originally Posted by cbkbud (Post 1390249)
PHP Code:

new GuiShowImgCtrl( "InvItem_0" )
{
  
image = "x.png";
  
width = 32;
  
height = 32;
  
x = 10;
  
y = 10;
  
  
this.itemName = "Guns/KABOOM!!!111!!";
  
thiso.catchevent( name, "onMouseDown", "onItemSelected" );
} 

and later something like this:

PHP Code:

function onItemSelected( obj )
{
    for(
temp.i=0;temp.i<player.weapons.size();temp.i++;)
    {
      if(
player.weapons[temp.i].name == obj.itemName)
      {
        
player.selectedweapon = temp.i;
        return;
      }
    }
} 

I believe that will work.

Another way to do that would be like:

PHP Code:

function onCreated() {
  
catchevent(InvItem_0, "onMouseDown", "onItemSelected");

  new 
GuiShowImgCtrl( "InvItem_0" ) {
    
image = "x.png";
    
width = 32;
    
height = 32;
    
x = 10;
    
y = 10;
    
this.itemName = "Guns/KABOOM!!!111!!";
  }
}

function 
onItemSelected(obj) {
  for(
temp.i=0; i < player.weapons.size(); ++i) {
    if (
player.weapons[i].name == obj.itemName) {
      
player.selectedweapon = i;
      break;
    }
  }
} 

Basically, catchevent can be called outside of the object (the object that actually gets the "catchevent" call is most likely going to be the WNPC that you are in which is why Chris used thiso.), the first parameter is the object that you are catching and it can be called before the object is even created :).

cbk1994 05-12-2008 11:26 PM

Quote:

Originally Posted by zokemon (Post 1390385)
Another way to do that would be like:

PHP Code:

function onCreated() {
  
catchevent(InvItem_0, "onMouseDown", "onItemSelected");

  new 
GuiShowImgCtrl( "InvItem_0" ) {
    
image = "x.png";
    
width = 32;
    
height = 32;
    
x = 10;
    
y = 10;
    
this.itemName = "Guns/KABOOM!!!111!!";
  }
}

function 
onItemSelected(obj) {
  for(
temp.i=0; i < player.weapons.size(); ++i) {
    if (
player.weapons[i].name == obj.itemName) {
      
player.selectedweapon = i;
      break;
    }
  }
} 

Basically, catchevent can be called outside of the object (the object that actually gets the "catchevent" call is most likely going to be the WNPC that you are in which is why Chris used thiso.), the first parameter is the object that you are catching and it can be called before the object is even created :).

I didn't know you could do that, thanks for the tip :) I never used catchevent much except for tabs (easy to detect which tab without many functions since they more or less do the same thing) and where there are dynamic buttons.

Inverness 05-13-2008 05:15 AM

The first parameter of catchevent should be a string (the object's name) not an object variable.

catchevent("InvItem_0", "onMouseDown", "onItemSelected"); or
catchevent(InvItem_0.name, "onMouseDown", "onItemSelected");

If it works with the variable it would be because it takes the object name from the variable.

cbk1994 05-13-2008 05:28 AM

Well, it's nice to pretend that Graal works on objects for this, not strings, I suppose.

Only way I can see strings being an advantage is if the object isn't yet defined?

Stryke 05-16-2008 04:42 AM

Thanks. It worked like a charm.

New Q:

Is there anyway to make the hint variable appear faster?

Tigairius 05-16-2008 05:02 AM

Quote:

Originally Posted by Stryke (Post 1390997)
Thanks. It worked like a charm.

New Q:

Is there anyway to make the hint variable appear faster?

GuiControl.hinttime (so just do hinttime = 0; )


All times are GMT +2. The time now is 12:33 AM.

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