Jump to content
  • 0

getinventorylist


Pneuma

Question


  • Group:  Members
  • Topic Count:  82
  • Topics Per Day:  0.02
  • Content Count:  846
  • Reputation:   137
  • Joined:  02/26/14
  • Last Seen:  

Okay I need help NOW with this command;

I want to know how to invoke the checking of specific ID and the amount of that item in their inventory

* getinventorylist;

This command sets a bunch of arrays with a complete list of whatever the
invoking character has in their inventory, including all the data needed to
recreate these items perfectly if they are destroyed. Here's what you get:
@inventorylist_id[] - array of item ids.
@inventorylist_amount[] - their corresponding item amounts.
@inventorylist_equip[] - whether the item is equipped or not.
@inventorylist_refine[] - for how much it is refined.
@inventorylist_identify[] - whether it's refined.
@inventorylist_attribute[] - whether it is broken.
@inventorylist_card1[] - These four arrays contain card data for the items.
@inventorylist_card2[] These data slots are also used to store names
@inventorylist_card3[] inscribed on the items, so you can explicitly check
@inventorylist_card4[] if the character owns an item made by a specific
craftsman.
@inventorylist_count - the number of items in these lists.

inbetween the sleep2 1000; command and the next; command, I would like to have it check how much of the item 6096 and then it removes that amount and sends a query_sql to a table and adds +1*each item deleted

bFish:
next;
 mes "Checking inventory...";
 sleep2 1000;

 next;

If possible; also make me a sql command for when turning in the fish for the first time it adds their name to the ladder;

Table: fishladder

Columns: char_id, name, score

Edited by Skyrim
Link to comment
Share on other sites

Recommended Posts


  • Group:  Members
  • Topic Count:  12
  • Topics Per Day:  0.00
  • Content Count:  626
  • Reputation:   188
  • Joined:  11/19/11
  • Last Seen:  

After the removal of the items, put this

query_sql "UPDATE table SET points = points + 1 WHERE char_id = "+getcharid(0);

Just edit the names of these:

table > the table to edit,

points > field where the points are saved

Regards,

Chris

  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  75
  • Topics Per Day:  0.02
  • Content Count:  2223
  • Reputation:   593
  • Joined:  10/26/11
  • Last Seen:  

Would countitem(6096) work?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  82
  • Topics Per Day:  0.02
  • Content Count:  846
  • Reputation:   137
  • Joined:  02/26/14
  • Last Seen:  

Would countitem(6096) work?

probably...but how would I delete the amount they have?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  69
  • Topics Per Day:  0.02
  • Content Count:  1315
  • Reputation:   372
  • Joined:  12/10/11
  • Last Seen:  

set @noitem,countitem(6096);
delitem 6096,@noitem;

  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  82
  • Topics Per Day:  0.02
  • Content Count:  846
  • Reputation:   137
  • Joined:  02/26/14
  • Last Seen:  

Okay I got that...but what about the sql commands? Thats what I mainly need help with...

like everytime a player turns in fish; it gives them the score and adds their name to the list

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  82
  • Topics Per Day:  0.02
  • Content Count:  846
  • Reputation:   137
  • Joined:  02/26/14
  • Last Seen:  

Thank you chris xD I needed that so much; I really suck with sql commands

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  12
  • Topics Per Day:  0.00
  • Content Count:  626
  • Reputation:   188
  • Joined:  11/19/11
  • Last Seen:  

Thank you chris xD I needed that so much; I really suck with sql commands

No problem, I still do sux with it, well didn't test other commands yet like "JOIN" and so on.

Tried it once, but since I have 2 login databases it didn't work. I tested something and it used the login db of the 2nd server instead of the 1st where the accounts are saved -.-.

Btw I wrote the post before with my iPhone4, cuz I afterwards realized that you posted that table & field names >_<. So I didn't know how to edit :D.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  82
  • Topics Per Day:  0.02
  • Content Count:  846
  • Reputation:   137
  • Joined:  02/26/14
  • Last Seen:  

Well how to edit the command to allow it to +1*amount of fish deleted?

Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

try this

query_sql "UPDATE table SET points = points + countitem(FISHID) WHERE char_id = "+getcharid(0);

Edited by Emistry
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  75
  • Topics Per Day:  0.02
  • Content Count:  2223
  • Reputation:   593
  • Joined:  10/26/11
  • Last Seen:  

set .@amt, countitem(6096);
delitem 6096, .@amt;

if ( query_sql("SELECT `score` FROM `fishladder` WHERE `char_id`="+getcharid(0), .@score) ) {
	// row exists, update it
	query_sql "UPDATE `fishladder` SET `score` = `score` + "+.@amt+" WHERE char_id="+getcharid(0);
} else {
	// else, insert new row
	query_sql "INSERT INTO fishladder (char_id,`name`,score) VALUES ("+getcharid(0)+",'"+strcharinfo(0)+"',"+.@amt+")";
}

query_sql "UPDATE table SET points = points + countitem(FISHID) WHERE char_id = "+getcharid(0);

^ the 'countitem' needs to be outside the string and concatenated in.

Or else your query will just be:

UPDATE table SET points = points + countitem(FISHID) WHERE ...

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  23
  • Reputation:   3
  • Joined:  12/10/11
  • Last Seen:  

 set .@amt, countitem(6096); delitem 6096, .@amt; if ( query_sql("SELECT `score` FROM `fishladder` WHERE `char_id`="+getcharid(0), .@score) ) { // row exists, update it query_sql "UPDATE `fishladder` SET `score` = `score` + "+.@amt+" WHERE char_id="+getcharid(0); } else { // else, insert new row query_sql "INSERT INTO fishladder (char_id,`name`,score) VALUES ("+getcharid(0)+",'"+strcharinfo(0)+"',"+.@amt+")"; } 

query_sql "UPDATE table SET points = points + countitem(FISHID) WHERE char_id = "+getcharid(0);

^ the 'countitem' needs to be outside the string and concatenated in. Or else your query will just be:
UPDATE table SET points = points + countitem(FISHID) WHERE ...

I Suggest to use "Replace" instead of checking row exsit and Update or Insert it. (If you have an primary key like char_id in this case.)

 query_sql "REPLACE INTO `fishladder` SET `score` = `score` + "+.@amt+",`char_id` = "+getcharid(0)+"";

Edited by Magic-Maker
  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  82
  • Topics Per Day:  0.02
  • Content Count:  846
  • Reputation:   137
  • Joined:  02/26/14
  • Last Seen:  

Magic, Your command doesnt do what I need it to...that replaces the whole score with how much you have...I need it to update it not replace

query_sql "UPDATE `fishladder` SET `score` = `score` + "+@noitem+",`char_id` = "+getcharid(0)+"";

This code worked too.

Now theres just 1 more portion of code edit i need for the above command ^_^

How to make it +2 score for every 1 fish turned it /meh

Brian:

bFish:
next;
 mes "Checking inventory...";
 sleep2 3000;
if(countitem(6096)){
set @noitem,countitem(6096);

if ( query_sql("SELECT `score` FROM `fishladder` WHERE `char_id`="+getcharid(0), .@score) ) {
 // row exists, update it
 query_sql "UPDATE `fishladder` SET `score` = `score` + "+@noitem+",`char_id` = "+getcharid(0)+""; 
} else {
 // else, insert new row
 query_sql "INSERT INTO fishladder (char_id,`name`,score) VALUES ("+getcharid(0)+",'"+strcharinfo(0)+"',"+@noitem+")";
}
delitem 6096,@noitem;
next;
 mes "[Fishing Board]";
 mes "Fish have been retreived and score updated.";
 close;} else
{  mes "[Fishing Board]";
mes "You have no fish to turn in.";
close;}

Is this how the code would be put?

Edited by Skyrim
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  75
  • Topics Per Day:  0.02
  • Content Count:  2223
  • Reputation:   593
  • Joined:  10/26/11
  • Last Seen:  

Yes something like that. Make sure your variable name (@noitem or .@amt ?) is the same in all places. To give them 2x the points, just do @noitem * 2

bFish:
next;
mes "Checking inventory...";
set .@amt,countitem(6096);
if (.@amt) {
	if ( query_sql("SELECT `score` FROM `fishladder` WHERE `char_id`="+getcharid(0), .@score) ) {
		// row exists, update it
		query_sql "UPDATE `fishladder` SET `score` = `score` + "+ .@amt*2 +",`char_id` = "+getcharid(0); 
	} else {
		// else, insert new row
		query_sql "INSERT INTO fishladder (char_id,`name`,score) VALUES ("+getcharid(0)+",'"+escape_sql(strcharinfo(0))+"',"+ .@amt*2 +")";
	}
	delitem 6096,.@amt;
	next;
	mes "[Fishing Board]";
	mes "Fish have been retreived and score updated.";
} else {
	mes "[Fishing Board]";
	mes "You have no fish to turn in.";
}
close;

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  9
  • Topics Per Day:  0.00
  • Content Count:  379
  • Reputation:   304
  • Joined:  11/10/11
  • Last Seen:  

Just a note, "," should be "WHERE":

query_sql "UPDATE `fishladder` SET `score` = `score` + "+ .@amt*2 +",`char_id` = "+getcharid(0); 

I think you can optimize the sql request:

query_sql("INSERT INTO `fishladder` (char_id,`name`,score) VALUES ("+getcharid(0)+",'"+escape_sql(strcharinfo(0))+"',"+ .@amt*2 +") ON DUPLICATE KEY UPDATE `score`=`score` + "+ .@amt*2 );

  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  75
  • Topics Per Day:  0.02
  • Content Count:  2223
  • Reputation:   593
  • Joined:  10/26/11
  • Last Seen:  

oops, thanks KeyWorld!

hmm somewhere after post #11 we lost WHERE xD

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  23
  • Reputation:   3
  • Joined:  12/10/11
  • Last Seen:  

So Sorry , I fogot to use subquery before "Replace" . think it will be work.


bFish:
next;
mes "Checking inventory...";
sleep2 3000;
if(countitem(6096)){
set .@noitem,countitem(6096);

query_sql "SELECT `score` FROM `fishladder` WHERE `char_id`="+getcharid(0), .@score;
query_sql "REPLACE INTO `fishladder` SET `score` = "+.@score+(.@noitem*2)+",`char_id` = "+getcharid(0)+"";
delitem 6096,.@noitem;
next;
mes "[Fishing Board]";
mes "Fish have been retreived and score updated.";
close;
}
else {
mes "[Fishing Board]";
mes "You have no fish to turn in.";
close;
}
[/codeBOX]

Edited by Magic-Maker
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  82
  • Topics Per Day:  0.02
  • Content Count:  846
  • Reputation:   137
  • Joined:  02/26/14
  • Last Seen:  

Hey guys, I was wondering if you could debug my script... :/ Its changing all the char_ids in the table to the same thing and updating them all...

brasilis.gat,265,74,5 script Fishing Board 857,{
mes "[Fishing Board]";
mes "Welcome to the Fishing board!";
next;
mes "[Fishing Board]";
mes "What would you like to do?";
 menu "View Fishing Ranks",Ranks,"Turn in some fish",Fish;
Ranks:
query_sql "select name, score from fishladder order by score desc limit "+ getvariableofnpc(.showpage,"FISHCONF"), .@name$, .@score;
   if ( !getarraysize(.@name$) ) {
   next;
 mes "[Fishing Board]";
 mes "The ladder currently is empty";
 close;
   }
   for ( set .@j,0; .@j < getarraysize(.@name$); set .@j, .@j + getvariableofnpc(.showpage,"FISHCONF") ) {
   next;
 mes "[Fishing Board]";
 for ( set .@i, .@j; .@i < (getvariableofnpc(.showpage,"FISHCONF") + .@j) && .@i < getarraysize(.@name$); set .@i, .@i + 1 ) {
  mes "^996600"+ (.@i+1) +": ^006699"+ .@name$[.@i] +" ^00AA00["+ .@score[.@i] +"]";
 }
close;
}
Fish:
next;
 mes "[Fishing Board]";
 mes "What fish would you like to turn in?";
  menu "Blue Fish",bFish;

bFish:
next;
 mes "Checking inventory...";
 sleep2 3000;
if(countitem(6096)){
set .@noitem,countitem(6096);

if ( query_sql("SELECT `score` FROM `fishladder` WHERE `char_id`="+getcharid(0), .@score) ) {
 // row exists, update it
 query_sql "UPDATE `fishladder` SET `score` = `score` + "+.@noitem+",`char_id` = "+getcharid(0)+""; 
} else {
 // else, insert new row
 query_sql "INSERT INTO fishladder (char_id,`name`,score) VALUES ("+getcharid(0)+",'"+strcharinfo(0)+"',"+.@noitem+")";
}
delitem 6096,.@noitem;
next;
 mes "[Fishing Board]";
 mes "Fish have been retreived and score updated.";
 close;} else
{  mes "[Fishing Board]";
mes "You have no fish to turn in.";
close;} 

}

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  23
  • Reputation:   3
  • Joined:  12/10/11
  • Last Seen:  

I also suguest to use "Replace". It can use in this case but have to select old score first (if it exist) and then plus the item amount to be a new score or if it isn't exist it will insert new row with score equal item amount. and one more thing is have to set a char_id field as index key

  
brasilis.gat,265,74,5 script Fishing Board 857,{
mes "[Fishing Board]";
mes "Welcome to the Fishing board!";
next;
mes "[Fishing Board]";
mes "What would you like to do?";
menu "View Fishing Ranks",Ranks,"Turn in some fish",Fish;
Ranks:
query_sql "select name, score from fishladder order by score desc limit "+ getvariableofnpc(.showpage,"FISHCONF"), .@name$, .@score;
if ( !getarraysize(.@name$) ) {
next;
mes "[Fishing Board]";
mes "The ladder currently is empty";
close;
}
for ( set .@j,0; .@j < getarraysize(.@name$); set .@j, .@j + getvariableofnpc(.showpage,"FISHCONF") ) {
next;
mes "[Fishing Board]";
for ( set .@i, .@j; .@i < (getvariableofnpc(.showpage,"FISHCONF") + .@j) && .@i < getarraysize(.@name$); set .@i, .@i + 1 ) {
mes "^996600"+ (.@i+1) +": ^006699"+ .@name$[.@i] +" ^00AA00["+ .@score[.@i] +"]";
}
close;
}
Fish:
next;
mes "[Fishing Board]";
mes "What fish would you like to turn in?";
menu "Blue Fish",bFish;

bFish:
next;
mes "Checking inventory...";
sleep2 3000;
if(countitem(6096)){
set .@noitem,countitem(6096);
query_sql "SELECT `score` FROM `fishladder` WHERE `char_id`="+getcharid(0), .@score;
query_sql "REPLACE INTO `fishladder` SET `score` = "+.@score+(.@noitem*2)+",`char_id` = "+getcharid(0)+"";
delitem 6096,.@noitem;
next;
mes "[Fishing Board]";
mes "Fish have been retreived and score updated.";
close;} else
{ mes "[Fishing Board]";
mes "You have no fish to turn in.";
close;}

}
[/codeBOX]

But if you really don't want to use it. Change

[code]query_sql "UPDATE `fishladder` SET `score` = `score` + "+.@noitem+",`char_id` = "+getcharid(0)+"";[/code]

to

[code]query_sql "UPDATE `fishladder` SET `score` = `score` + +.@noitem+ WHERE `char_id` = "+getcharid(0)+"";[/code]

Edited by Magic-Maker
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  82
  • Topics Per Day:  0.02
  • Content Count:  846
  • Reputation:   137
  • Joined:  02/26/14
  • Last Seen:  

Hmm...Well I fixed it for the most part...but it still has 1 problem..It wont change the scores anymore :/

After you turn in the fish for the first time your score wont go up anymore and with your code Magic I get a sql error on my mapserver

Edited by Skyrim
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  23
  • Reputation:   3
  • Joined:  12/10/11
  • Last Seen:  

OK. I have run and try it and it work properly. But please tell if have any problem.


brasilis.gat,265,74,5 script Fishing Board 857,{
mes "[Fishing Board]";
mes "Welcome to the Fishing board!";
next;
mes "[Fishing Board]";
mes "What would you like to do?";
menu "View Fishing Ranks",Ranks,"Turn in some fish",Fish;
Ranks:
query_sql "select name, score from fishladder order by score desc limit "+ getvariableofnpc(.showpage,"FISHCONF"), .@name$, .@score;
if ( !getarraysize(.@name$) ) {
next;
mes "[Fishing Board]";
mes "The ladder currently is empty";
close;
}
for ( set .@j,0; .@j < getarraysize(.@name$); set .@j, .@j + getvariableofnpc(.showpage,"FISHCONF") ) {
next;
mes "[Fishing Board]";
for ( set .@i, .@j; .@i < (getvariableofnpc(.showpage,"FISHCONF") + .@j) && .@i < getarraysize(.@name$); set .@i, .@i + 1 ) {
mes "^996600"+ (.@i+1) +": ^006699"+ .@name$[.@i] +" ^00AA00["+ .@score[.@i] +"]";
}
close;
}
Fish:
next;
mes "[Fishing Board]";
mes "What fish would you like to turn in?";
menu "Blue Fish",bFish;

bFish:
next;
mes "Checking inventory...";
sleep2 3000;
if(countitem(6096)){
set .@noitem,countitem(6096);
if ( query_sql("SELECT `score` FROM `fishladder` WHERE `char_id`="+getcharid(0), .@score) ) {
// row exists, update it
query_sql "UPDATE `fishladder` SET `score` = `score` + "+.@noitem+" WHERE `char_id` = "+getcharid(0)+"";
} else {
// else, insert new row
query_sql "INSERT INTO fishladder (`char_id`,`name`,`score`) VALUES ("+getcharid(0)+",'"+strcharinfo(0)+"',"+.@noitem+")";
}

delitem 6096,.@noitem;
next;
mes "[Fishing Board]";
mes "Fish have been retreived and score updated.";
close;
}
else {
mes "[Fishing Board]";
mes "You have no fish to turn in.";
close;
}

}
[/codeBOX]

Edited by Magic-Maker
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  75
  • Topics Per Day:  0.02
  • Content Count:  2223
  • Reputation:   593
  • Joined:  10/26/11
  • Last Seen:  

query_sql "REPLACE INTO `fishladder` SET `score` = "+.@score+(.@noitem*2)+",`char_id` = "+getcharid(0)+"";

The REPLACE INTO syntax looks more like INSERT (not like Update):

REPLACE INTO `fishladder` (char_id,`name`,score) VALUES ("+getcharid(0)+",'"+strcharinfo(0)+"',"+.@score+")";

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  23
  • Reputation:   3
  • Joined:  12/10/11
  • Last Seen:  

query_sql "REPLACE INTO `fishladder` SET `score` = "+.@score+(.@noitem*2)+",`char_id` = "+getcharid(0)+"";

The REPLACE INTO syntax looks more like INSERT (not like Update):
REPLACE INTO `fishladder` (char_id,`name`,score) VALUES ("+getcharid(0)+",'"+strcharinfo(0)+"',"+.@score+")";

I have try it and it can use either like "UPDATE" and like "INSERT" but my REPLACE has some mistake and have to change to

query_sql "REPLACE INTO `fishladder` SET `score` = "+(.@score+(.@noitem*2))+",`char_id` = "+getcharid(0)+",`name` = '"+strcharinfo(0)+"'";

Refer from you link. It has 3 form of replace. and it's one of that

REPLACE [LOW_PRIORITY | DELAYED]
[iNTO] tbl_name
SET col_name={expr | DEFAULT}, ...

Delete Because of Some Bug for subquery.

Edited by Magic-Maker
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  82
  • Topics Per Day:  0.02
  • Content Count:  846
  • Reputation:   137
  • Joined:  02/26/14
  • Last Seen:  

Magic, Yours fixed it but now It wont add new scores... Like if their name isnt on the board it will not add them when they turn in fish...

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  0
  • Topics Per Day:  0
  • Content Count:  23
  • Reputation:   3
  • Joined:  12/10/11
  • Last Seen:  

Magic, Yours fixed it but now It wont add new scores... Like if their name isnt on the board it will not add them when they turn in fish...

which script you use script on comment 21 or 23 ?

I suggest to use script on comment 21 because I have try it already. but on comment 23 I still have some bug.

and the script on comment 21 will work no matter you set the primary key or not.

Edited by Magic-Maker
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  82
  • Topics Per Day:  0.02
  • Content Count:  846
  • Reputation:   137
  • Joined:  02/26/14
  • Last Seen:  

#23; It is set to primary key but no new name/id would show up in the DB because there was no Insert command...or update..it was only replace so that only replaces current data, it doesnt add in new data

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...