PDA

View Full Version : Custom Inventory


xXziroXx
09-13-2006, 07:03 PM
Custom Inventory
v1.0

This inventory works pretty much as the default Graal inventory does. It displays NPCs that doesnt start with "-", and by doubleclicking on a weapon you select it. 'Sub-Folders' will be implemented in the next version, if requested.


Theres only ONE thing that doesnt work properly in it, selected a weapon. For some reason, it doesnt always selected the proper weapon.

Example:

Player doubleclicks on the weapon "Staff/Boots" and it gets equipped properly.
Player then tries to doubleclick the weapon "Tailor", and that too works.
Finally, player tries to equip the weapon "Skateboard", but "Tailor" gets equiped instead!

Id be so-so happy if someone would be able to solve that bug, I havent been able too.


But other then that, its all good to go!



Installing

When adding the NPC, it can be named pretty much anything you want BUT it HAVE to start with a "-"! If it doesnt, it wont work properly.


function onActionServerSide()
{
if (params[0] == "playerweaps") {
for (i = 0; i < player.weapons.size(); i ++) temp.imgs.add(findWeaponNPC(player.weapons[i]).image);
triggerClient("gui", name, "openinv", player.weapons, temp.imgs);
}
}

//#CLIENTSIDE
function onCreated()
{
enablefeatures(allfeatures - 4);
this.gName = "Inventory_";
(this.gName @ "Window0").destroy();
setTimer(.05);
}

function onTimeOut()
{
this.plWeapon = player.weapon.name;
showText(200, 6, 100, "System", "b", "Selected Weapon:" SPC this.plWeapon SPC "[" @ selectedweapon @ "]");
changeImgVis(200, 4);

setTimer(.05);
}

function onKeyPressed(keynr, keyname)
{
if (keyname == "q") {
if ((this.gName @ "Window0").visible == false) triggerServer("gui", name, "playerweaps");
else (this.gName @ "Window0").destroy();
}
}

function onActionClientSide("",weaps,imgs)
{
if (params[0] == "openinv") OpenInventory(weaps, imgs);
}

function OpenInventory(invWeapons, invImages)
{
if ((this.gName @ "Window0").visible == false) {
new GuiWindowCtrl(this.gName @ "Window0") {
width = 196, height = 177;
x = screenwidth/2 - width/2, y = screenheight/2 - height/2;

canMinimize = false;
canMaximize = false;
canResize = false;
canMove = false;
destroyOnHide = true;

xmod = NULL;
ymod = NULL;
rowcount = NULL;

invItems = NULL;
// Removes old buttons
for (i = 0; i < invItems.size(); i ++) (this.gName @ "Button" @ i).destroy();

// Checks for items to display in inventory
for (i = 0; i < invWeapons.size(); i ++) {
if (!invWeapons[i].starts("-")) invItems.add({invWeapons[i], invImages[i]});
}

// Displays the items
new GuiScrollCtrl(this.gName @ "Scroll0") {
width = 187, height = 150;
x = 5, y = 23;

hScrollBar = "alwaysOff";
vScrollBar = "dynamic";

for (i = 0; i < invItems.size(); i ++) {
temp.var = i / 5;
if (temp.var.length() == 1 && i > 0) {
xmod = NULL;
ymod += 36;
rowcount ++;
}

new GuiBitmapButtonCtrl(this.gName @ "Button" @ i) {
width = 32, height = 32;
x = 5 + xmod, y = 5 + ymod;

this.itemname = invItems[i][0];
this.itemimage = invItems[i][1];

normalbitmap = this.itemimage;
mouseoverbitmap = this.itemimage;
pressedbitmap = this.itemimage;

thiso.catchevent(this, "onMouseDown", "onSlotPressed");
thiso.catchevent(this, "onMouseEnter", "onMouseOverSlot");
thiso.catchevent(this, "onMouseLeave", "onMouseExitSlot");
}
xmod += 32 + 4;
}
}
}
(this.gName @ "Window0").makefirstresponder("false");
} else (this.gName @ "Window0").destroy();
}

function onSlotPressed(obj, keymodifier, mousescreenx, mousescreeny, clickcount)
{
if (clickcount == 2) {
player.chat = "Selected Weapon:" SPC obj.itemname;
selectedweapon = player.weapons.index(findWeapon(obj.itemname));
(this.gName @ "Window0").destroy();
} else if (clickcount == 1) (this.gName @ "Window0").text = obj.itemname;
}

function onMouseOverSlot(obj) (this.gName @ "Window0").text = obj.itemname;
function onMouseExitSlot(obj) (this.gName @ "Window0").text = "";



Enjoy!

GULTHEX
04-20-2009, 09:59 PM
error: unexpected symbol "" at line 35: function onActionClientSide("",weaps,imgs)

okay i tried making it
("",weaps,imgs)

so i think the problem is that actionclientside isint a real function

Chompy
04-20-2009, 10:10 PM
function onActionClientSide()
{
if (params[0] == "openinv") OpenInventory(params[1], params[2]);
}


Try that instead :]

Inverness
04-20-2009, 10:27 PM
error: unexpected symbol "" at line 35: function onActionClientSide("",weaps,imgs)

okay i tried making it
("",weaps,imgs)

so i think the problem is that actionclientside isint a real functionI think the problem is in the error message. :noob:

Clearly just do:

function onActionClientSide(unused,weaps,imgs)
{
if (params[0] == "openinv") OpenInventory(weaps, imgs);
}

Chompy, I'm astonished that you're avoiding the problem rather than fixing it. The problem is clearly in the error message.

Chompy
04-20-2009, 10:37 PM
I think the problem is in the error message. :noob:

Clearly just do:

function onActionClientSide(unused,weaps,imgs)
{
if (params[0] == "openinv") OpenInventory(weaps, imgs);
}

Chompy, I'm astonished that you're avoiding the problem rather than fixing it. The problem is clearly in the error message.

Fixing it by adding a placeholder? :p I'd say you either stick with using the params[] array or use predefined parameters instead. (Instead of a mix, as it can become confusing when working with larger codes)

Inverness
04-20-2009, 10:43 PM
Fixing it by adding a placeholder? :p I'd say you either stick with using the params[] array or use predefined parameters instead. (Instead of a mix, as it can become confusing when working with larger codes)I would use predefined parameters too, but I'm simply fixing what caused the error message, not redoing the script for him.

xXziroXx
04-21-2009, 12:03 AM
Oh my god, did I make this piece of junk? :noob:

Damix2
04-21-2009, 04:02 AM
Oh my god, did I make this piece of junk? :noob:

Reminds me of that bash.org quote

<@Logan> I spent a minute looking at my own code by accident.
<@Logan> I was thinking "What the hell is this guy doing?"

:D

GULTHEX
04-22-2009, 04:45 AM
but when i add iether one of those i get

Script: Function enablefeatures not found at line 12 in script of -inv
<b>Script: Function Inventory_Window0.destroy not found at line 14 in script of -inv

just trying to help the people that dont know what to do

Twinny
04-22-2009, 05:00 AM
but when i add iether one of those i get

Script: Function enablefeatures not found at line 12 in script of -inv
<b>Script: Function Inventory_Window0.destroy not found at line 14 in script of -inv

just trying to help the people that dont know what to do

haha running back to the forums probably isn't the right thing to do as such ^^

cbk1994
04-22-2009, 05:48 AM
but when i add iether one of those i get

Script: Function enablefeatures not found at line 12 in script of -inv
<b>Script: Function Inventory_Window0.destroy not found at line 14 in script of -inv

just trying to help the people that dont know what to do
You messed up the clientside somehow.

Add //#CLIENTSIDE to the top after the serverside stuff if it's missing. Also check that it's capitalized and doesn't have a space or something after it.

Deas_Voice
04-22-2009, 05:03 PM
Oh my god, did I make this piece of junk? :noob:

Reminds me of that bash.org quote

<@Logan> I spent a minute looking at my own code by accident.
<@Logan> I was thinking "What the hell is this guy doing?"

:D


sig'd :D

jkldogg
02-27-2010, 01:58 AM
will someone please send me the whole script in forum pm? this is extremely useful and its not working for me

got it

xXziroXx
02-27-2010, 03:30 AM
will someone please send me the whole script in forum pm?

What? :oo:

12171217
02-27-2010, 05:44 AM
Vega United's lookin' good!

WhiteDragon
02-27-2010, 05:50 AM
Vega United's lookin' good!
Although this guy is lacking initiative to the point that he won't even look at the thread again, you can't really blame people who don't know how to script and want to create a server. There aren't many decent scripters out there these days.

Switch
02-27-2010, 05:57 AM
Although this guy is lacking initiative to the point that he won't even look at the thread again, you can't really blame people who don't know how to script and want to create a server. There aren't many decent scripters out there these days.

But it doesn't give them the right to be completely ignorant about scripts, especially when everything is given to you on a silver platter. Actually, I don't know if I'd call it being ignorant or something I'd probably get an infraction for.

WhiteDragon
02-27-2010, 06:11 AM
But it doesn't give them the right to be completely ignorant about scripts, especially when everything is given to you on a silver platter. Actually, I don't know if I'd call it being ignorant or something I'd probably get an infraction for.
I wasn't really talking about this particular case.

Inverness
02-27-2010, 06:46 AM
Screenshots.

jkldogg
02-27-2010, 08:34 AM
Vega United's lookin' good!

Thanks!

The script works now btw.

Switch
02-27-2010, 12:17 PM
I wasn't really talking about this particular case.

Nor was I, but all of this guy's posts in the scripting section seem to be asking for someone to do something for him, even searching the forum. I've also been asked by some other people to do things for them or they can't follow my simple directions ("Change _____ to _____").

firefighter
02-27-2010, 05:04 PM
Screenshots.
http://img412.imageshack.us/img412/5669/zenox1.png
Interacts with SQLite database (over database NPC), uses binary search for faster access in large item lists, categorizing, item cache through weapon script (I don't think there is another possibility to realize better item cache on the clientside). No permanent TimeOut needed at all.

Its a shame that we cannot continue developing at the moment because of missing development staff :(

jkldogg
03-05-2010, 02:18 PM
this doesn't work for adding images to the inventory, is there a way to edit this script to add your own image?