Hey, I was trying to create an auction plugin in which players can submit items for sale but I failed. In this plugin you can submit weapons like AK47, M4A1 etc.. ( Only if you already own them ) with a specific price and time, if someone has enough money to buy that item he can buy (The person who submitted it can't), when time has expired the item should be removed from the Auction House. Thanks !
PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#define PLUGIN "Auction House"
#define VERSION "1.0"
#define AUTHOR "DoNii"
new Array: g_AuctionItem;
new Array: g_AuctionPrice;
new g_AuctionMenu;
new const AVAILABLE_COMMANDS[][] = {
"say auction",
"say /auction",
"say_team auction",
"say_team /auction"
}
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
g_AuctionMenu = menu_create( "\rAuction Options", "auction_handler" );
g_AuctionItem = ArrayCreate(32)
g_AuctionPrice = ArrayCreate(1)
for (new i; i < sizeof AVAILABLE_COMMANDS; i++)
register_clcmd(AVAILABLE_COMMANDS[i], "show_auction_menu");
}
public show_auction_menu(id) {
menu_additem(g_AuctionMenu, "Open Auction House", _, _);
menu_additem(g_AuctionMenu, "Submit An Item", _, _);
menu_setprop( g_AuctionMenu, MPROP_EXIT, MEXIT_ALL );
if(is_user_alive(id))
menu_display(id, g_AuctionMenu, 0);
}
public auction_handler(id, menu, item) {
switch(item) {
case 0: {
OpenAuctionHouse(id)
}
case 1: {
SubmitItem(id)
}
}
return PLUGIN_HANDLED;
}
OpenAuctionHouse(id) {
new menu = menu_create( "\rAvailable Items To Buy", "auction_house_handler" );
new szTemp[ 15 ], buffer[128]
for( new i; i < ArraySize( g_AuctionItem ); i++ ) {
ArrayGetString( g_AuctionItem, i, szTemp, charsmax( szTemp ) );
for ( i < ArraySize(g_AuctionPrice); i++; )
formatex(buffer, 127, "%s %d", szTemp, ArrayGetCell( g_AuctionPrice, i ))
}
menu_additem(menu, buffer, _, _);
menu_setprop( menu, MPROP_EXIT, MEXIT_ALL );
if(is_user_alive(id))
menu_display(id, menu, 0);
}
public auction_house_handler(id, menu, item) {
switch(item) {
case 0: {
client_print(id, print_chat, "You Just Bought Deagle");
}
}
}
SubmitItem(id) {
new menu = menu_create( "\rChoose The Item You Want To Submit For Auction", "submit_handler" );
menu_additem(menu, "Deagle", _, _)
menu_additem(menu, "M4A1", _, _)
menu_setprop( menu, MPROP_EXIT, MEXIT_ALL );
if(is_user_alive(id))
menu_display(id, menu, 0);
}
public submit_handler(id, menu, item) {
switch(item) {
case 0: {
if(!user_has_weapon(id, CSW_DEAGLE)) {
client_print(id, print_chat, "You Can't Submit Items That You Don't Own");
return PLUGIN_HANDLED;
}
ArrayPushString(g_AuctionItem, "Deagle")
ArrayPushCell(g_AuctionItem, 30)
ham_strip_weapon(id, "weapon_deagle")
}
case 1: {
if(!user_has_weapon(id, CSW_M4A1)) {
client_print(id, print_chat, "You Can't Submit Items That You Don't Own");
return PLUGIN_HANDLED;
}
ArrayPushString(g_AuctionItem, "M4A1")
ArrayPushCell(g_AuctionItem, 50)
ham_strip_weapon(id, "weapon_m4a1")
}
}
return PLUGIN_HANDLED;
}
stock ham_strip_weapon(id,weapon[])
{
if(!equal(weapon,"weapon_",7)) return 0;
new wId = get_weaponid(weapon);
if(!wId) return 0;
new wEnt;
while((wEnt = engfunc(EngFunc_FindEntityByString,wEnt,"classname",weapon)) && pev(wEnt,pev_owner) != id) {}
if(!wEnt) return 0;
if(get_user_weapon(id) == wId) ExecuteHamB(Ham_Weapon_RetireWeapon,wEnt);
if(!ExecuteHamB(Ham_RemovePlayerItem,id,wEnt)) return 0;
ExecuteHamB(Ham_Item_Kill,wEnt);
set_pev(id,pev_weapons,pev(id,pev_weapons) & ~(1<<wId));
return 1;
}