Issue information

Issue ID
#6847
Status
Fixed
Severity
None
Started
Hercules Elf Bot
Nov 4, 2012 13:36
Last Post
Hercules Elf Bot
Nov 5, 2012 17:21
Confirmation
Yes (5)
No (0)

Hercules Elf Bot - Nov 4, 2012 13:36

Originally posted by [b]AnnieRuru[/b]
responsible topic
[url="http://rathena.org/board/topic/73574-callshop-script/"]http://rathena.org/b...allshop-script/[/url]

[codebox]prontera,159,172,5 script market#2 100,{
if ( countitem(1201) == 0 ) {
getitem2 1201, 1,1,0,0, 4001,4002,4003,0;
getitem2 1201, 1,1,0,0, 4001,4002,4003,4004;
}

callshop "market2#hidden", 2;
end;
OnSellItem:
.@size = getarraysize( @sold_nameid );
for ( .@i = 0; .@i < .@size; .@i++ ) {
dispbottom callfunc( "getitemname2", @sold_nameid[.@i], @sold_identify[.@i], @sold_refine[.@i], @sold_attribute[.@i], @sold_card1[.@i], @sold_card2[.@i], @sold_card3[.@i], @sold_card4[.@i]);
dispbottom @sold_nameid[.@i] +" "+ @sold_identify[.@i] +" "+ @sold_refine[.@i] +" "+ @sold_attribute[.@i] +" "+ @sold_card1[.@i] +" "+ @sold_card2[.@i] +" "+ @sold_card3[.@i] +" "+ @sold_card4[.@i];
}
end;
OnInit:
npcshopattach "market2#hidden";
end;
}
- shop market2#hidden -1,512:10,513:20,514:30,515:40,516:50
[/codebox]

tested with this script on latest rathena 16857
and ... ahem... my [url=http://www.eathena.ws/board/index.php?showtopic=244678]getitemname2 function[/url]

when I sell the that custom Knife that I provided with this script
1st knife return 1201 1 0 0 0 0 0 0
2nd knife return 1201 1 0 0 4004 0 0 0
it seems card1 ~ card3 value is discard and overwrite with card4 value on the card1 slot


[url="http://www.eathena.ws/board/index.php?autocom=bugtracker&showbug=4858"]http://www.eathena.w...er&showbug=4858[/url]
when I make a reference to this topic

[codebox]Index: npc.c
===================================================================
--- npc.c (revision 16857)
+++ npc.c (working copy)
@@ -1561,14 +1561,16 @@
static int npc_selllist_sub(struct map_session_data* sd, int n, unsigned short* item_list, struct npc_data* nd)
{
char npc_ev[EVENT_NAME_LENGTH];
- char card_slot[NAME_LENGTH];
- int i, j, idx;
+ int i, idx;
int key_nameid = 0;
int key_amount = 0;
int key_refine = 0;
int key_attribute = 0;
int key_identify = 0;
- int key_card = 0;
+ int key_card1 = 0;
+ int key_card2 = 0;
+ int key_card3 = 0;
+ int key_card4 = 0;

// discard old contents
script_cleararray_pc(sd, "@sold_nameid", (void*)0);
@@ -1576,12 +1578,10 @@
script_cleararray_pc(sd, "@sold_refine", (void*)0);
script_cleararray_pc(sd, "@sold_attribute", (void*)0);
script_cleararray_pc(sd, "@sold_identify", (void*)0);
-
- for( j = 0; MAX_SLOTS > j; j++ )
- {// clear each of the card slot entries
- snprintf(card_slot, sizeof(card_slot), "@sold_card%d", j + 1);
- script_cleararray_pc(sd, card_slot, (void*)0);
- }
+ script_cleararray_pc(sd, "@sold_card1", (void*)0);
+ script_cleararray_pc(sd, "@sold_card2", (void*)0);
+ script_cleararray_pc(sd, "@sold_card3", (void*)0);
+ script_cleararray_pc(sd, "@sold_card4", (void*)0);

// save list of to be sold items
for( i = 0; i < n; i++ )
@@ -1596,12 +1596,11 @@
script_setarray_pc(sd, "@sold_refine", i, (void*)(intptr_t)sd->status.inventory[idx].refine, &key_refine);
script_setarray_pc(sd, "@sold_attribute", i, (void*)(intptr_t)sd->status.inventory[idx].attribute, &key_attribute);
script_setarray_pc(sd, "@sold_identify", i, (void*)(intptr_t)sd->status.inventory[idx].identify, &key_identify);
-
- for( j = 0; MAX_SLOTS > j; j++ )
- {// store each of the cards from the equipment in the array
- snprintf(card_slot, sizeof(card_slot), "@sold_card%d", j + 1);
- script_setarray_pc(sd, card_slot, i, (void*)(intptr_t)sd->status.inventory[idx].card[j], &key_card);
- }
+ script_setarray_pc(sd, "@sold_sold", i, (void*)(intptr_t)sd->status.inventory[idx].identify, &key_identify);
+ script_setarray_pc(sd, "@sold_card1", i, (void*)(intptr)sd->status.inventory[idx].card[0], &key_card1);
+ script_setarray_pc(sd, "@sold_card2", i, (void*)(intptr)sd->status.inventory[idx].card[1], &key_card2);
+ script_setarray_pc(sd, "@sold_card3", i, (void*)(intptr)sd->status.inventory[idx].card[2], &key_card3);
+ script_setarray_pc(sd, "@sold_card4", i, (void*)(intptr)sd->status.inventory[idx].card[3], &key_card4);
}
}


[/codebox]somehow this code fix the bug /hmm
and I feel this kind of modification looks noob
I also fail to detect why the official code doesn't work
I'm still noob in source modification anyways

maybe you core developers can find out why current rathena code doesn't work, while this noob coding works

This post has been edited by AnnieRuru on Nov 4, 2012 15:36

Hercules Elf Bot - Nov 4, 2012 18:48

Originally posted by [b]nanakiwurtz[/b]
The code to blame is in
[code]if( refcache )
{
refcache[0] = key;
}[/code]
Do you know why? /meh

To fix it, just comment the code into something like this (or just delete the whole lines)
[code]if( refcache )
{
//refcache[0] = key;
}[/code]
And now your '@sold_card' array will hold all 4 cards /pat
[code]
1st knife return 1201 1 0 0 4001 4002 4003 0
2nd knife return 1201 1 0 0 4001 4002 4003 4004[/code]

This post has been edited by nanakiwurtz on Nov 4, 2012 18:53

Hercules Elf Bot - Nov 4, 2012 23:00

Originally posted by [b]AnnieRuru[/b]
[quote name='script.c (getinventorylist)']
[code] if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount > 0){
pc_setreg(sd,reference_uid(add_str("@inventorylist_id"), j),sd->status.inventory[i].nameid);
pc_setreg(sd,reference_uid(add_str("@inventorylist_amount"), j),sd->status.inventory[i].amount);
pc_setreg(sd,reference_uid(add_str("@inventorylist_equip"), j),sd->status.inventory[i].equip);
pc_setreg(sd,reference_uid(add_str("@inventorylist_refine"), j),sd->status.inventory[i].refine);
pc_setreg(sd,reference_uid(add_str("@inventorylist_identify"), j),sd->status.inventory[i].identify);
pc_setreg(sd,reference_uid(add_str("@inventorylist_attribute"), j),sd->status.inventory[i].attribute);
for (k = 0; k < MAX_SLOTS; k++)
{
sprintf(card_var, "@inventorylist_card%d",k+1);
pc_setreg(sd,reference_uid(add_str(card_var), j),sd->status.inventory[i].card[k]);
}[/code][/quote]when I made compare to the *getinventorylist script command
this one use pc_setreg
and inside npc.c use script_setarray_pc

so weird ...
maybe its time to clean up some duplicated code ?

that function script_setarray_pc is inside script.c ...
I'm not sure your fix is correct one

This post has been edited by AnnieRuru on Nov 4, 2012 23:01

Hercules Elf Bot - Nov 5, 2012 1:33

Originally posted by [b]mkbu95[/b]
I could fix with the following changes:
[CODEBOX]Index: npc.c
===================================================================
--- npc.c (revision 16857)
+++ npc.c (working copy)
@@ -1568,7 +1568,7 @@
int key_refine = 0;
int key_attribute = 0;
int key_identify = 0;
- int key_card = 0;
+ int key_card[MAX_SLOTS];

// discard old contents
script_cleararray_pc(sd, "@sold_nameid", (void*)0);
@@ -1579,6 +1579,7 @@

for( j = 0; MAX_SLOTS > j; j++ )
{// clear each of the card slot entries
+ key_card[j] = 0;
snprintf(card_slot, sizeof(card_slot), "@sold_card%d", j + 1);
script_cleararray_pc(sd, card_slot, (void*)0);
}
@@ -1600,7 +1601,7 @@
for( j = 0; MAX_SLOTS > j; j++ )
{// store each of the cards from the equipment in the array
snprintf(card_slot, sizeof(card_slot), "@sold_card%d", j + 1);
- script_setarray_pc(sd, card_slot, i, (void*)(intptr_t)sd->status.inventory[idx].card[j], &key_card);
+ script_setarray_pc(sd, card_slot, i, (void*)(intptr_t)sd->status.inventory[idx].card[j], &key_card[j]);
}
}
}
[/CODEBOX]
This was *possibly* happening because it was only one variable used to hold the key for all slots.
I don't think the fix nanaki provided is a good practic `@_@´

This post has been edited by mkbu95 on Nov 5, 2012 1:35

Hercules Elf Bot - Nov 5, 2012 4:36

Originally posted by [b]AnnieRuru[/b]
yaya ...
mkbu95's fix looks more practical

Hercules Elf Bot - Nov 5, 2012 7:13

Originally posted by [b]Brian[/b]
Thanks mkbu95!

Updating status to: [b]Fixed[/b] in [rev=16860].

This post has been edited by Brian on Nov 5, 2012 7:13

Hercules Elf Bot - Nov 5, 2012 17:13

Originally posted by [b]nanakiwurtz[/b]
Thanks for the correction
I'm sorry but I'm just an ordinary user :P

Hercules Elf Bot - Nov 5, 2012 17:21

Originally posted by [b]mkbu95[/b]
It is fine. I can't get right all the times. I don't know if this fix broke another thing -jk.
Keep trying, that's the spirit. :)