/*
||======================================================||
||======================================================||
|| NPC: ||
||======================================================||
|| Dynamic Shop ||
||======================================================||
|| Version 1.2 ||
||======================================================||
|| Made by Streiker ||
||======================================================||
|| Updates: ||
|| (5 latests) ||
|| ||
|| Version 1.1.1: ||
|| Fixed: uploaded the wrong npc! ||
|| ||
|| Version 1.1.2: ||
|| Fixed: some small mistakes. ||
|| Changed the default npc id. ||
|| ||
|| Version 1.1.3: ||
|| Fixed: items receive. ||
|| Fixed: while -> do while. ||
|| ||
|| Version 1.1.4: ||
|| Changed: the prize is show as "0". ||
|| Fixed: adding items. ||
|| ||
|| Version 1.2: ||
|| Added: items and variables in 1 item. ||
|| Added: weight check. ||
|| Added: items preview. ||
||======================================================||
|| Description: ||
|| ||
|| A dynamic shop, allow more than 1 variables and items||
||======================================================||
|| Additional Comments: ||
|| ||
|| To Do: GM menu (add, delete...) ||
|| SQL variables selection. ||
||======================================================||
||======================================================||
How to add items?
Read the information of the functions and add items.
Rembember I don't speak english, so don't criticise me, I did all I can!
This script requires my functions collection!
*/
- shop dshop -1,501:300
- script Dynamic_Shop_Conf -1,{
function Add_Item ;
function Add_Items ;
function Add_Vars ;
OnInit:
set $@DS_n$, "Dynamic Shop"; // Name of the npc.
set $@DS_id, 410; // ID of the npc.
setnpcdisplay ( "Dynamic Shop##DZ", $@DS_id ) ;
// I didn't put the setnpcdisplay ("name") because the last time I checked it didn't work.
// Maybe i've used it wrong X_x.
/*
Examples:
// Add_Item <id>, <price to show>.
Add_Item ( 501, 1 ) ;
// Add_Items <id>, <amount>.
Add_Items ( 512, 5, 513, 3 ) ;
// Add_Vars <"variable">, <"name to show">, <amount>.
Add_Vars ( "#CASHPOINTS", "Cash Points", 1, "Zeny", "Zenys", 500;
*/
npcshopitem "dshop", $@ds_1_1, $@ds_2_1 ;
for ( set .@a, 2; .@a <= $@ds_it ; set .@a, .@a + 1 )
npcshopadditem "dshop", getd ( "$@ds_1_"+ .@a ), getd ( "$@ds_2_"+ .@a ) ;
end ;
function Add_Item {
set $@ds_it, $@ds_it + 1;
setd "$@ds_1_"+ $@ds_it, getarg ( 0 );
setd "$@ds_2_"+ $@ds_it, getarg ( 1 );
return ;
}
function Add_Items {
while ( getarg ( .@a, 0 ) != 0 ) {
set .@b, .@b + 1;
setd "$@ds_3_"+ $@ds_it +"_"+ .@b, getarg ( .@a );
setd "$@ds_4_"+ $@ds_it +"_"+ .@b, getarg ( .@a + 1 );
set .@a, .@a + 2;
}
setd "$@ds_5_"+ $@ds_it, .@b;
return ;
}
function Add_Vars {
while ( getarg ( .@a, "" ) != "" ) {
set .@b, .@b + 1;
setd "$@ds_6_"+ $@ds_it +"_"+ .@b +"$", getarg ( .@a );
setd "$@ds_7_"+ $@ds_it +"_"+ .@b +"$", getarg ( .@a + 1 );
setd "$@ds_8_"+ $@ds_it +"_"+ .@b, getarg ( .@a + 2 );
set .@a, .@a + 3;
}
setd "$@ds_9_"+ $@ds_it, .@b;
return ;
}
}
prontera,148,167,5 script Dynamic Shop#DZ::dyn_shop 410,{
if ( ! $@DS_id ) donpcevent "Dynamic_Shop_Conf::OnInit" ;
while ( 1 ) {
set .@a$,"^2b86b5"+ $@DS_n$ +"^000000";
mes .@a$;
mes "Hi "+ strcharinfo ( 0 ) +", welcome to this shop.";
mes "Remember I use different conditions of payment depending of the item.";
mes "Would you like to buy or check these conditions?";
next ;
if ( select ( "Buy items", "Check conditions", "Preview items", "^911b1bExit^000000" ) == 1 ) {
close2 ;
callshop "dshop", 1 ;
npcshopattach "dshop" ;
end ;
}
mes .@a$;
if ( @menu == 4 ) {
mes "Have a nice day.";
close ;
}
if ( @menu == 3 ) {
mes "Which item do you want to preview?";
deletearray .@q ;
set .@m$, "";
for ( set .@m, 1; .@m <= $@ds_it ; set .@m, .@m + 1 ) {
set .@o, getiteminfo ( getd ( "$@ds_1_"+ .@m ), 5 ); // equip position.
set .@p, getiteminfo ( getd ( "$@ds_1_"+ .@m ), 11 ); // view id.
if ( ( .@o >= 0 ) && ( .@p ) ) {
set .@m$, .@m$ + getitemname ( getd ( "$@ds_1_"+ .@m ) ) +":";
set .@q[getarraysize ( .@q )], getd ( "$@ds_1_"+ .@m );
}
sleep2 ( ! ( .@m % 100 ) ) ;
}
set .@n, select ( .@m$ + ":^911b1bBack^000000" ) ;
if ( .@n <= $@ds_it )
callfunc "show_hat", getd ( "$@ds_1_"+ .@n ) ;
}
if ( @menu == 2 )
for ( set .@a, 1; .@a <= $@ds_it ; set .@a, .@a + 1 ) {
mes "^8627bc--- ^509343"+ getitemname ( getd ( "$@ds_1_"+ .@a ) ) +"^000000 ^8627bc---";
while ( set ( .@b, .@b + 1 ) <= getd ( "$@ds_5_"+ .@a ) )
mes "^2731fd"+ getd ( "$@ds_4_"+ .@a +"_"+ .@b ) +" "+ getitemname ( getd ( "$@ds_3_"+ .@a +"_"+ .@b ) );
set .@b, 0;
while ( set ( .@b, .@b + 1 ) <= getd ( "$@ds_9_"+ .@a ) )
mes "^bc2727"+ getd ( "$@ds_8_"+ .@a +"_"+ .@b ) +" "+ getd ( "$@ds_7_"+ .@a +"_"+ .@b +"$" );
sleep2 ( ! ( .@a % 100 ) ) ;
mes " ";
set .@b, 0;
}
next ;
}
OnBuyItem:
for ( set .@a, 0; .@a < getarraysize ( @bought_nameid ) ; set .@a, .@a + 1 )
do {
set .@b, .@b + 1;
if ( getd ( "$@ds_1_"+ .@b ) == @bought_nameid[.@a] ) {
set .@w, .@w + ( getiteminfo ( getd ( "$@ds_1_"+ .@b ), 6 ) * @bought_quantity[.@a] );
while ( set ( .@c, .@c + 1 ) <= getd ( "$@ds_5_"+ .@b ) ) {
set .@d, countitem ( getd ( "$@ds_3_"+ .@b +"_"+ .@c ) );
if ( .@d < ( getd ( "$@ds_4_"+ .@b +"_"+ .@c ) * @bought_quantity[.@a] ) ) {
dispbottom "You don't have "+ getd ( "$@ds_4_"+ .@b +"_"+ .@c ) +" "+ getitemname ( getd ( "$@ds_3_"+ .@b +"_"+ .@c ) );
set .@e, .@e + 1;
}
}
set .@c, 0;
while ( set ( .@c, .@c + 1 ) <= getd ( "$@ds_9_"+ .@b ) ) {
set .@d, getd ( getd ( "$@ds_6_"+ .@b +"_"+ .@c +"$" ) );
if ( .@d < ( getd ( "$@ds_8_"+ .@b +"_"+ .@c ) * @bought_quantity[.@a] ) ) {
dispbottom "You don't have "+ getd ( "$@ds_6_"+ .@b +"_"+ .@c ) +" "+ getd ( "$@ds_7_"+ .@b +"_"+ .@c +"$" );
set .@e, .@e + 1;
}
}
if ( MaxWeight < ( Weight + .@w ) ) {
dispbottom "You have overweight for carry item "+ getitemname ( getd ( "$@ds_1_"+ .@a ) ) +".";
set .@e, .@e + 1;
// for save space for any other item that support your weight...
set .@w, .@w - ( getiteminfo ( getd ( "$@ds_1_"+ .@b ), 6 ) * @bought_quantity[.@a] );
}
if ( ! ( .@e ) ) {
set .@g[getarraysize ( .@g )], .@a;
set .@l[getarraysize ( .@l )], .@b;
}
}
set .@e, 0;
sleep2 ( ! ( .@b % 100 ) ) ;
} while ( .@b < $@ds_it ) ;
while ( .@i <= getarraysize ( .@g ) ) {
set .@j, .@g[.@i];
set .@i, .@i + 1;
if ( ! ( getd ( "$@ds_1_"+ .@l[.@i - 1] ) ) ) continue ;
while ( set ( .@k, .@k + 1 ) <= getd ( "$@ds_5_"+ .@l[.@i - 1] ) )
delitem getd ( "$@ds_3_"+ .@l[.@i - 1] +"_"+ .@k ), getd ( "$@ds_4_"+ .@l[.@i - 1] +"_"+ .@k ) * @bought_quantity[.@j];
while ( set ( .@n, .@n + 1 ) <= getd ( "$@ds_9_"+ .@l[.@i - 1] ) )
setd getd ( "$@ds_6_"+ .@l[.@i - 1] +"_"+ .@n +"$" ), getd ( getd ( "$@ds_6_"+ .@l[.@i - 1] +"_"+ .@n +"$" ) ) - ( getd ( "$@ds_8_"+ .@l[.@i - 1] +"_"+ .@n ) * @bought_quantity[.@j] );
getitem getd ( "$@ds_1_"+ .@l[.@i - 1] ), @bought_quantity[.@j];
sleep2 ( ! ( .@i % 100 ) ) ;
}
deletearray @bought_quantity ;
deletearray @bought_nameid ;
end ;
}