Author Topic: Checking clients invent.  (Read 2154 times)

How would you check a clients invent for an item, say you typed /invent gun it'd go through your invent and try to find gunItem.

Code: [Select]
while(%i<=4){
if(%this.inventory[%i] = gunItem){
//stuffhere
}
%i++;
}

Code: [Select]
function servercmdCheck(%this)
{
 if(!isObject(%this.player)){return;}
 while(%i<=4){
 if(%this.player.tool[%i] = gunItem){
 //stuffhere
 }
 %i++;
 }
}

.inventory is bricks, not items.


Code: [Select]
function servercmdcheck(%this, %t1)
{
if(!isObject(%this.player)){return;}
%item = %t1 @ "Item";
echo(%item);
while(%i<=4){
if(%this.player.tool[%i] = %item){
echo("You have this item");
}
%i++;
}
}

It dosen't seem to find that you have the item, It knows what item to look for but dosent find it.

%this.player.tool[%i]

Would return a number. I can't remember which command returns the actual name, just dump it and look

function servercmdcheck(%this, %item)
{
if(!isObject(%this.player)){return;}
while(%i<=4){
if(firstWord(%this.player.tool[%i].uiName) $= %item){
echo("You have this item");
}
%i++;
}
}

There. Slightly easier to use, put in "/check Gun" and it checks whether you have a gun, etc. "/check Rocket L." will actually only look for "Rocket" but will still work - first word is being checked.

Terror, it's %this.player.tool[%i].getName();.

Okay, That works but it's not checking for the first item?

function servercmdcheck(%this, %item)
{
if(!isObject(%this.player)){return;}
%i = 0;
while(%i<=4){
if(firstWord(%this.player.tool[%i].uiName) $= %item){
echo("You have this item");
}
%i++;
}
}

It was checking %this.player.tool, .tool[1], .tool[2] instead of .tool[0], etc.

perhaps use strLwr just to make it look better?

I'm an idiot, i could of worked that out myself, i need to get back on form.

needs moar for loop

But for loops are complicated D:

Code: [Select]
%i=0;
 while(%i<=4){
 //stuff
 %i++;
}

turns into

Code: [Select]
for(%i=0;%i<=4;%i++){
 //stuff
}

Which way's more efficient, they both do the same but the for loop takes less lines.