rathena/doc/sample/npc_dynamic_shop.txt
ai4rei 8643992d0b * Fixes to the dynamic shop sample script (first part of dynamic shop fixes).
- Fixed wrong check in ::OnSellItem, causing not-enough-items condition not getting detected (since r11829).
- Fixed an exploit in ::OnSellItem, causing Zeny to be given to the player, even if the items fail to delete (since r5842).
- Fixed missing 'close' in ::OnSellItem (since r5842).
- Replaced 'end' with 'close' in ::OnBuyItem (since r5842, followup to r11829).

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@14609 54d463be-8e91-2dee-dedb-b68131a5f0ec
2010-12-19 18:04:18 +00:00

86 lines
2.1 KiB
Plaintext

- shop dyn_shop1 -1,501:50
prontera,181,200,4 script Dynamic Shop 123,{
callshop "dyn_shop1",0;
npcshopattach "dyn_shop1";
end;
OnSellItem:
for(set @i, 0; @i < getarraysize(@sold_nameid); set @i, @i + 1){
if(countitem(@sold_nameid[@i]) < @sold_quantity[@i] || @sold_quantity[@i] <= 0){
mes "omgh4x!";
close;
}
if(@sold_nameid[@i] == 501){
delitem 501, @sold_quantity[@i];
set $@rpotsleft, $@rpotsleft + @sold_quantity[@i];
set Zeny, Zeny + @sold_quantity[@i]*20;
} else {
if(@sold_nameid[@i] == 502){
delitem 502, @sold_quantity[@i];
set $@opotsleft, $@opotsleft + @sold_quantity[@i];
set Zeny, Zeny + @sold_quantity[@i]*100;
} else {
mes "Sorry, I don't need your items.";
close;
}
}
}
deletearray @sold_quantity, getarraysize(@sold_quantity);
deletearray @sold_nameid, getarraysize(@sold_nameid);
mes "Deal completed.";
close;
OnBuyItem:
for(set @i, 0; @i < getarraysize(@bought_nameid); set @i, @i + 1){
if(@bought_quantity[@i] <= 0){
mes "omgh4x!";
close;
}
if(@bought_nameid[@i] == 501){
if(@bought_quantity[@i] > $@rpotsleft){
if($@rpotsleft > 0){
set @bought_quantity[@i], $@rpotsleft;
} else {
mes "We are out of red potions!";
close;
}
}
if(Zeny >= 40*@bought_quantity[@i]){
set Zeny, Zeny - 40*@bought_quantity[@i];
getitem 501, @bought_quantity[@i];
set $@rpotsleft, $@rpotsleft - @bought_quantity[@i];
} else {
mes "You have insufficient cash.";
close;
}
} else {
if(@bought_quantity[@i] > $@opotsleft){
if($@opotsleft > 0){
set @bought_quantity[@i], $@opotsleft;
} else {
mes "We are out of orange potions!";
close;
}
}
if(Zeny >= 200*@bought_quantity[@i]){
set Zeny, Zeny - 200*@bought_quantity[@i];
getitem 502, @bought_quantity[@i];
set $@opotsleft, $@opotsleft - @bought_quantity[@i];
} else {
mes "You have insufficient cash.";
close;
}
}
}
deletearray @bought_quantity, getarraysize(@bought_quantity);
deletearray @bought_nameid, getarraysize(@bought_nameid);
mes "Trade done.";
close;
OnInit:
npcshopitem "dyn_shop1", 501,40,502,200;
set $@rpotsleft, 10;
set $@opotsleft, 10;
end;
}