Main Plugin
PHP Code:
#include <amxmodx>
#include <cstrike>
#include <hamsandwich>
// create the structure for each item
// we need the item name, cost, plugin adding it, and the callback function
enum _:ItemData {
ItemName[32],
ItemPlugin,
ItemFuncID
}
// create a dynamic array to hold all the items
new Array:g_aItems
// this will tell how many are in the array instead of using ArraySize()
new g_iTotalItems
public plugin_init()
{
// register player spawn to show the shop menu
register_clcmd("say /a", "ShowShopMenu")
// create our array with the size of the item structure
g_aItems = ArrayCreate(ItemData)
}
public plugin_natives()
{
// register our custom library
register_library("achievements")
// create a native to allow other plugins to add items
register_native("achievements_add_item", "achievements_add_item")
}
public achievements_add_item(iPlugin, iParams)
{
// create an array to hold our item data
new eItemData[ItemData]
// get item name from function
get_string(1, eItemData[ItemName], charsmax(eItemData[ItemName]))
// save the plugin adding the item
eItemData[ItemPlugin] = iPlugin
// get item callback function
new szHandler[32]
get_string(2, szHandler, charsmax( szHandler))
eItemData[ItemFuncID] = get_func_id(szHandler, iPlugin)
// add item to array and increase size
ArrayPushArray(g_aItems, eItemData)
g_iTotalItems++
// return the index of this item in the array
// this creates the unique item index
return (g_iTotalItems - 1)
}
public ShowShopMenu(id, iPage)
{
// check if there are no items
if(!g_iTotalItems)
{
return
}
// clamp page to valid range of pages
iPage = clamp(iPage, 0, (g_iTotalItems - 1) / 7)
// create menu
new menu = menu_create("Achievements", "Achievements_Handle")
// used to display item in the menu
new eItemData[ItemData]
new szItem[64]
// used for array index to menu
new szNum[3]
// loop through each item
for(new i = 0; i < g_iTotalItems; i++)
{
// get item data from array
ArrayGetArray(g_aItems, i, eItemData)
// format item for menu
formatex(szItem, charsmax(szItem), "%s\R", eItemData[ItemName])
// pass array index to menu to find information about it later
num_to_str(i, szNum, charsmax(szNum))
// add item to menu
menu_additem(menu, szItem, szNum)
}
// display menu to player
menu_display(id, menu, iPage)
}
public Achievements_Handle(id, menu, item)
{
if(item == MENU_EXIT)
{
menu_destroy(menu)
return
}
new iAccess
new szNum[3]
new hCallback
menu_item_getinfo(menu, item, iAccess, szNum, charsmax(szNum), _, _, hCallback)
//menu_destroy(menu)
// get item index from menu
new iItemIndex = str_to_num(szNum)
// get item data from array
new eItemData[ItemData]
ArrayGetArray(g_aItems, iItemIndex, eItemData)
// notify the plugin that the player bought this item
callfunc_begin_i(eItemData[ItemFuncID], eItemData[ItemPlugin])
callfunc_push_int(id)
callfunc_end()
ShowShopMenu(id, .iPage = (iItemIndex / 7))
}
Side Plugin
PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <achievements>
new bool:first_blood[33]
new killstreak[33]
public plugin_init()
{
achievements_add_item("First Blood", "FirstBlood_Handle")
RegisterHam(Ham_Killed, "player", "HamKilled", 1)
}
public FirstBlood_Handle(id)
{
client_print(id, print_chat, "[Achievements] Earned for youre first Kill")
}
public HamKilled(victim, attacker)
{
if(!is_user_alive(attacker) || !is_user_connected(attacker))
{
killstreak[attacker] = 0
return HAM_HANDLED
}
if(get_user_team(attacker) != get_user_team(victim))
{
killstreak[attacker] ++
}
if(killstreak[attacker] == 1)
{
first_blood[attacker] = true
}
return HAM_IGNORED
}
Include File
PHP Code:
#if defined _achievements_included
#endinput
#endif
#define _achievements_included
#if AMXX_VERSION_NUM >= 175
#pragma reqlib achievements
#if !defined AMXMODX_NOAUTOLOAD
#pragma loadlib achievements
#endif
#else
#pragma library achievements
#endif
native achievements_add_item(const szName[], const szHandler[])
Help?
http://forums.alliedmods.net/showpos...87&postcount=5
__________________