// CREATE TABLE `Dynamic_Shop` ( // `id` int(11) NOT NULL default '0', // `price` int(11) NOT NULL default '0', // PRIMARY KEY (`id`) // ); - shop Dynamic_Shop_b -1,512:-1 // Dummy-Shop prontera,147,173,5, script Faeroth 762,{ if ( getgmlevel() < .min_gm_level ) { L_player: if ( .lock_npc && getgmlevel() < .min_gm_level ) { mes .npc_name$; mes "I'm sorry, the NPC has been locked by an Admin."; close; } else if ( $item_ID_dynamic ) { mes .npc_name$; mes "Hello, I only want to advise you of the fact that you have to pay with the item ^999999" + getitemname( $item_ID_dynamic ) + " instead of Zenys.^000000"; mes "^FF0000(So the amount of Zenys stands for the amount of items.)"; close2; } callshop "Dynamic_Shop_b",1; npcshopattach "Dynamic_Shop_b"; end; } while (1) { mes .npc_name$; .@item_id = .@price = 0; mes "Hello, what do you want to do?"; mes "~ ^FF0000Status:^000000 ~"; if ( !$item_ID_dynamic ) mes "^FF9900You pay with Zenys in the shop."; else mes "^FF9900You pay with the item ^999999" + getitemname( $item_ID_dynamic ) + " (ID: " + $item_ID_dynamic + ") ^FF9900in the shop!^000000"; mes " "; if ( .lock_npc ) mes "^FF0000The NPC is locked.^000000"; next; set .@menu, select( "- Add an item with price.", "- List all item with their prices.", "- Chose the way to pay.", "- "+ ( .lock_npc ? "Unlock" : "Lock" ) +" the NPC.", "- Debug Help.", "- Preview of the shop.", "- Nothing, thanks." ); switch( .@menu ) { case 1: { deletearray .@nameid; deletearray .@p; mes .npc_name$; mes "Do you really want to add an item with price?"; next; if ( select( "- No.:- Yes!" ) == 1 ) break; mes .npc_name$; mes "Please input the ^FF0000Item ID^000000."; next; input .@item_id; if ( getiteminfo( .@item_id,0 ) == -1 ) { mes .npc_name$; mes "Wrong item ID."; break; } mes .npc_name$; mes "Please input now the ^FF0000Price^000000 for the items."; next; if ( input( .@price, 1 ) == -1 ) { mes .npc_name$; mes "Price can't be <= 0."; break; } .@nb = query_sql( "SELECT * FROM `Dynamic_Shop`", .@nameid, .@p ); for ( .@i = 0; .@i < .@nb; .@i++ ) if ( .@item_id == .@nameid[.@i] ) break; mes .npc_name$; if ( .@i != .@nb ) { mes "There is already a "+ getitemname( .@item_id ) +" (^ff0000"+ .@item_id +"^000000) with the price "+ .@p[.@i] +"."; mes "Action aborted."; break; } mes "Summary:"; mes "^FF0000Name: " + getitemname( .@item_id ); mes "ID: " + .@item_id; mes "Price: " + .@price + "^000000"; mes "Is everything fine?"; next; if ( select( "- No.:- Yes!" ) == 1 ) { mes .npc_name$; mes "The action has been aborted."; } else { query_sql "INSERT INTO `Dynamic_Shop` ( `id`, `price` ) VALUES ( '"+.@item_id+"' , '"+.@price+"' )"; npcshopadditem "Dynamic_Shop_b", .@item_id, .@price; mes .npc_name$; mes "The new item has been added!"; } break; } case 2: while(1) { deletearray .@item_id; deletearray .@price_all; .@menu_d$ = ""; .@nb = query_sql( "SELECT * FROM `Dynamic_Shop`", .@item_id, .@price_all ); mes .npc_name$; if ( !.@nb ) { mes "You don't have added any ^FF0000Items^000000 yet.."; break; } else { mes "All of the ^FF0000Items^000000 will now be listed as a Menu."; mes "If you want to delete one, you may chose it."; mes "^FF0000Attention:^000000 Name ( ID , Price )."; next; for( set .@i, 0; .@i < .@nb; set .@i, .@i + 1) set .@menu_d$, .@menu_d$ + "- " + getitemname( .@item_id[.@i] ) + " ( " + .@item_id[.@i] + " , " + .@price_all[.@i] + " ):"; set .@menu_d$, .@menu_d$ + "- I'm finished, thanks."; set .@s, select( .@menu_d$ ) - 1; if ( .@s == .@nb ) break; mes .npc_name$; mes "Do you want to delete the ^FF0000Item^000000 ^FF0000" + getitemname( .@item_id[.@s] ) + "^000000 with the ID ^FF0000" + .@item_id[.@s] + "^000000?"; if ( select( "- No.:- Yes!" ) == 2 ) { next; query_sql "DELETE FROM `Dynamic_Shop` WHERE `id` = '"+.@item_id[.@s]+"'"; npcshopdelitem "Dynamic_Shop_b", .@item_id[.@s]; mes .npc_name$; mes "The item has been deleted."; } next; } } break; case 3: mes .npc_name$; mes "Do you really want to chose the way to pay?"; next; if ( select( "- No.:- Yes!" ) == 1 ) break; mes .npc_name$; mes "Please input the ^999999ID^000000 of an ^FF0000Item^000000 to be payed with."; mes "^FF0000Attention: Insert 0 means pay with Zenys."; next; input .@tmp; mes .npc_name$; if ( !.@tmp && !$item_ID_dynamic ) mes "You already pay with zeny."; else if ( !.@tmp ) { mes "Should you pay with ^999999Zenys^000000 in the shop?"; next; if ( select( "- No!:- Yes." ) == 1 ) { mes .npc_name$; mes "Aborted."; } else { mes .npc_name$; mes "You will pay with ^999999Zenys^000000 now."; set $item_ID_dynamic, 0; } } else if ( getiteminfo( .@tmp,0 ) == -1 ) mes "Item ID (^ff0000"+ .@tmp + "^000000) doesn't exist."; else { mes "^FF0000Name : " + getitemname( .@tmp ) + "^000000"; mes "^999999Item ID: " + .@tmp; mes "^000000Everything right?"; next; if ( select( "- No, it's not.:- Yes." ) == 1 ) { mes .npc_name$; mes "Aborted.."; if ( !$item_ID_dynamic ) mes "You will continue on paying with ^999999Zenys^000000."; else mes "You will continue on paying with the ^FF0000Item^000000 " + getitemname( $item_ID_dynamic ) + " gezahlt."; break; } set $item_ID_dynamic, .@tmp; mes .npc_name$; mes "Thank you."; mes "You will now have to pay with the ^FF0000Item^000000 " + getitemname( $item_ID_dynamic ) + "."; } break; case 4: mes .npc_name$; mes "Do you want to ^FF0000"+ ( .lock_npc ? "unlock" : "lock" ) +"^000000 the NPC?"; next; if ( select( "- No.:- Yes." ) == 1 ) break; mes .npc_name$; set .lock_npc, !.lock_npc; mes "The NPC ^FF0000"+ ( .lock_npc ? "has been ^FF0000locked" : "is now ^FF0000no longer locked" ) +"^000000."; mes "A reloadscript => default state (set .lock_npc, 0; in the script)."; break; case 5: mes .npc_name$; mes "If you find any bugs usw, please inform ^33CC00Faeroth | Kaze^000000."; mes "Contact me:"; mes "MSN: faeroth@hotmail.de"; mes "ICQ: 284-209-043"; mes "eAthena: F!re"; next; mes .npc_name$; mes "First help:"; mes "- Are the Item-IDs all right?"; mes "- [...] (will follow)"; next; mes .npc_name$; mes "Scripted and Copyright by ^33CC00Faeroth | Kaze^000000."; break; case 6: mes .npc_name$; mes "Do you really want to see the preview of the shop?"; next; if ( select( "- No.:- Yes!" ) == 1 ) break; mes .npc_name$; mes "The shop will be open now..."; next; goto L_player; case 7: goto L_end; } next; } L_end: mes .npc_name$; mes "I'm always to your command."; close; OnBuyItem: .@nb = query_sql( "SELECT `id`, `price` FROM `Dynamic_Shop`", .@item_id, .@price_all ); if ( !.@nb ) end; for( set .@i, 0; .@i < getarraysize( @bought_nameid ); set .@i, .@i + 1) for( set .@z, 0; .@z < .@nb; set .@z, .@z + 1) if ( .@item_id[.@z] == @bought_nameid[.@i] ) set .@price_tot, .@price_tot + ( .@price_all[.@z] * @bought_quantity[.@i] ); if ( !$item_ID_dynamic ) { if ( Zeny < .@price_tot ) dispbottom "You don't have enough Zenys.."; else { set Zeny, Zeny - .@price_tot; for( set .@i,0; .@i < getarraysize(@bought_nameid); set .@i, .@i + 1) getitem @bought_nameid[.@i], @bought_quantity[.@i]; } } else { mes "~ ^999999Bill^000000 ~"; for( set .@i, 0; .@i < getarraysize(@bought_nameid); set .@i, .@i + 1 ) mes "^FF0000" + getitemname(@bought_nameid[.@i]) + ": " + @bought_quantity[.@i] + "^000000"; mes "This will cost you ^999999" + .@price_tot + " " + getitemname($item_ID_dynamic) + "^000000!"; mes "Do you want to complete the purchase?"; next; if ( select( "- No, I don't..:- Yes, I do." ) == 1 ) { mes .npc_name$; mes "The purchase has been aborted."; } else if ( countitem($item_ID_dynamic) < .@price_tot ) { mes .npc_name$; mes "I'm sorry, you don't have enough ^999999" + getitemname( $item_ID_dynamic ) + "^000000..."; } else { delitem $item_ID_dynamic, .@price_tot; for( set .@i, 0; .@i < getarraysize(@bought_nameid); set .@i, .@i + 1 ) getitem @bought_nameid[.@i], @bought_quantity[.@i]; mes .npc_name$; mes "Thank you for your purchase."; } close2; } deletearray @bought_quantity; deletearray @bought_nameid; end; OnInit: set .npc_name$,"~ ^00B200Faeroth^000000 ~"; set .min_gm_level, 99; set .lock_npc, 0; // lock the npc (1: yes ; 0: no) // End of setting npcshopdelitem "Dynamic_Shop_b", 512; set .@nb, query_sql( "SELECT `id`, `price` FROM `Dynamic_Shop`", .@item_id, .@price_all ); if ( !.@nb ) end; for ( set .@i, 0; .@i < .@nb; set .@i, .@i + 1 ) npcshopadditem "Dynamic_Shop_b", .@item_id[.@i], .@price_all[.@i]; end; }