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 05-11-2008, 04:58 AM
Stryke Stryke is offline
Scripter
Join Date: Apr 2008
Posts: 157
Stryke is an unknown quantity at this point
Problem with Custom Inventory

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

function 
onKeyPressedcodekey )
{
  if (
key == "q")
  {
    
client.qo client.qo;
  }
}

function 
onTimeout()
{
  if (
client.qo NULL)
    
hideMenu();
  else 
showMenu();
  
    if(
client.qo 1)
    {
      
mx intmousescreenx thiso.qx 620);
      
my intmousescreeny thiso.qy 225);
      for(
temp.j=0;temp.j<player.weapons.size();temp.j++;) {
      
temp.findimg(201 temp.j);
      if ( 
mx in temp.i.xtemp.i.16 | && my in temp.i.ytemp.i.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 180;
  
thiso.qy screenheight 100;  
  
with (findimg(200))
  {
    
image "cyn_inventory_gui.gif";
    
thiso.qx;
    
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.iplayer.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=0thiso.i<5thiso.i++;)
  {
    for(
thiso.j=0thiso.j<4thiso.j++;)
    {
      
with(findimg(201 thiso.item_count))
      {
        
image thiso.item_image[thiso.item_count];
        
thiso.qx 76 + (thiso.45);
        
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?
Reply With Quote
  #2  
Old 05-11-2008, 05:03 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
I would use GuiShowImg and add a hint = "" to it.
__________________
Reply With Quote
  #3  
Old 05-11-2008, 05:10 AM
Stryke Stryke is offline
Scripter
Join Date: Apr 2008
Posts: 157
Stryke is an unknown quantity at this point
Can you show me an example I have never used it before. =/
Reply With Quote
  #4  
Old 05-11-2008, 05:13 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
PHP Code:
new GuiShowImgCtrl"Inventory_Window" )
{
  
0;
  
0;
  
width 200;
  
height 200;
  
image "inventory.png";
  new 
GuiShowImgCtrl"Inventory_Item" )
  {
    
width 32;
    
height 32;
    
20;
    
20;
    
image player.weapon.image;
  }

__________________
Reply With Quote
  #5  
Old 05-11-2008, 05:33 AM
Stryke Stryke is offline
Scripter
Join Date: Apr 2008
Posts: 157
Stryke is an unknown quantity at this point
PHP Code:
//#CLIENTSIDE
function onCreated(){ setTimer(0.05); disableselectweapons(); }

function 
onKeyPressedcodekey )
{
  if (
key == "q")
  {
    
client.qo client.qo;
  }
}

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

function 
showMenu()
{
  
thiso.qx screenwidth 100;
  
thiso.qy screenheight 100;
  
thiso.item_name NULL;
  
thiso.item_image NULL;
  
thiso.item_pos NULL;
  
thiso.item_list NULL;
  
thiso.item_count 0;
  
  for (
temp.iplayer.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")
  {
    
thiso.qx;
    
thiso.qy;
    
width 411;
    
height 280;
    
image "cyn_inventory_gui.gif";
  
    for(
thiso.i=0thiso.i<5thiso.i++;)
    {
      for(
thiso.j=0thiso.j<4thiso.j++;)
      {
        new 
GuiShowImgCtrl("InvItem_"@thiso.item_count)
        {
          
width 32;
          
height 32;
          
thiso.qx 76 + (thiso.45);
          
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.
Reply With Quote
  #6  
Old 05-11-2008, 05:44 AM
Stryke Stryke is offline
Scripter
Join Date: Apr 2008
Posts: 157
Stryke is an unknown quantity at this point
Is there a way to make the Hint overlap the mouse..?

and why doesnt this work?

PHP Code:
function InvItem_0.onMouseDragged() {
  
InvItem_0.mousex;
  
InvItem_0.mousey;


Last edited by Stryke; 05-11-2008 at 05:57 AM..
Reply With Quote
  #7  
Old 05-11-2008, 05:59 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
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.
__________________
Reply With Quote
  #8  
Old 05-11-2008, 03:14 PM
Stryke Stryke is offline
Scripter
Join Date: Apr 2008
Posts: 157
Stryke is an unknown quantity at this point
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.
Reply With Quote
  #9  
Old 05-11-2008, 04:05 PM
Robin Robin is offline
The secret of NIMH
Robin's Avatar
Join Date: Apr 2005
Location: Wales, UK
Posts: 515
Robin will become famous soon enough
Send a message via AIM to Robin
Lookup catchevent on the wiki if you're working with GUI's

And what do you mean by equip?
__________________

Reply With Quote
  #10  
Old 05-11-2008, 04:22 PM
Stryke Stryke is offline
Scripter
Join Date: Apr 2008
Posts: 157
Stryke is an unknown quantity at this point
By equip i mean selectedweapon = index of weapon i want equipped.
Reply With Quote
  #11  
Old 05-11-2008, 04:27 PM
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
Quote:
Originally Posted by Stryke View Post
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;
  
10;
  
10;
  
  
this.itemName "Guns/KABOOM!!!111!!";

'name' is reserved by default.
__________________
Reply With Quote
  #12  
Old 05-11-2008, 04:57 PM
Stryke Stryke is offline
Scripter
Join Date: Apr 2008
Posts: 157
Stryke is an unknown quantity at this point
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?
Reply With Quote
  #13  
Old 05-11-2008, 05:13 PM
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
PHP Code:
new GuiShowImgCtrl"InvItem_0" )
{
  
image "x.png";
  
width 32;
  
height 32;
  
10;
  
10;
  
  
this.itemName "Guns/KABOOM!!!111!!";
  
thiso.catcheventname"onMouseDown""onItemSelected" );

and later something like this:

PHP Code:
function onItemSelectedobj )
{
    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.
__________________
Reply With Quote
  #14  
Old 05-12-2008, 11:26 AM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
Quote:
Originally Posted by cbkbud View Post
PHP Code:
new GuiShowImgCtrl"InvItem_0" )
{
  
image "x.png";
  
width 32;
  
height 32;
  
10;
  
10;
  
  
this.itemName "Guns/KABOOM!!!111!!";
  
thiso.catcheventname"onMouseDown""onItemSelected" );

and later something like this:

PHP Code:
function onItemSelectedobj )
{
    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;
    
10;
    
10;
    
this.itemName "Guns/KABOOM!!!111!!";
  }
}

function 
onItemSelected(obj) {
  for(
temp.i=0player.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 .
__________________
Do it with a DON!
Reply With Quote
  #15  
Old 05-12-2008, 11:26 PM
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
Quote:
Originally Posted by zokemon View Post
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;
    
10;
    
10;
    
this.itemName "Guns/KABOOM!!!111!!";
  }
}

function 
onItemSelected(obj) {
  for(
temp.i=0player.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.
__________________
Reply With Quote
  #16  
Old 05-13-2008, 05:15 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
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.
__________________
Reply With Quote
  #17  
Old 05-13-2008, 05:28 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
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?
__________________
Reply With Quote
  #18  
Old 05-16-2008, 04:42 AM
Stryke Stryke is offline
Scripter
Join Date: Apr 2008
Posts: 157
Stryke is an unknown quantity at this point
Thanks. It worked like a charm.

New Q:

Is there anyway to make the hint variable appear faster?
Reply With Quote
  #19  
Old 05-16-2008, 05:02 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by Stryke View Post
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; )
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
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 09:23 PM.


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