Raised This Month: $ Target: $400
 0% 

[API] Need Little Help Here :)


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Krle
Senior Member
Join Date: Jul 2011
Location: Serbia, Nis
Old 09-20-2011 , 09:28   [API] Need Little Help Here :)
Reply With Quote #1

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(iPluginiParams)
{
    
// create an array to hold our item data
    
new eItemData[ItemData]
    
// get item name from function
    
get_string(1eItemData[ItemName], charsmax(eItemData[ItemName]))
    
// save the plugin adding the item
    
eItemData[ItemPlugin] = iPlugin
    
// get item callback function
    
new szHandler[32]
    
get_string(2szHandlercharsmaxszHandler))
    
eItemData[ItemFuncID] = get_func_id(szHandleriPlugin)
    
// add item to array and increase size
    
ArrayPushArray(g_aItemseItemData)
    
g_iTotalItems++
    
// return the index of this item in the array
    // this creates the unique item index
    
return (g_iTotalItems 1)
}

public 
ShowShopMenu(idiPage)
{
    
// check if there are no items
    
if(!g_iTotalItems)
    {
        return
    }
    
// clamp page to valid range of pages
    
iPage clamp(iPage0, (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 0g_iTotalItemsi++)
    {
        
// get item data from array
        
ArrayGetArray(g_aItemsieItemData)
        
// format item for menu
        
formatex(szItemcharsmax(szItem), "%s\R"eItemData[ItemName])
        
// pass array index to menu to find information about it later
        
num_to_str(iszNumcharsmax(szNum))
        
// add item to menu
        
menu_additem(menuszItemszNum)
    }
    
// display menu to player
    
menu_display(idmenuiPage)
}

public 
Achievements_Handle(idmenuitem)
{    
    if(
item == MENU_EXIT)
    {
        
menu_destroy(menu)
        return
    }
    new 
iAccess
    
new szNum[3]
    new 
hCallback
    
    menu_item_getinfo
(menuitemiAccessszNumcharsmax(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_aItemsiItemIndexeItemData)
    
    
// 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(idprint_chat"[Achievements] Earned for youre first Kill")
}

public 
HamKilled(victimattacker)
{
    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
__________________

Sorry about my BAD English

Last edited by Krle; 09-20-2011 at 12:08.
Krle is offline
Send a message via MSN to Krle
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:44.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode