Raised This Month: $51 Target: $400
 12% 

[API] Need Little Help Here :)


Post New Thread Reply   
 
Thread Tools Display Modes
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
OvidiuS
Chillaxin'
Join Date: Dec 2009
Location: Serbia
Old 09-20-2011 , 09:35   Re: [API] Need Little Help Here :)
Reply With Quote #2

register first blood, and than give hp
OvidiuS is offline
Send a message via Skype™ to OvidiuS
Krle
Senior Member
Join Date: Jul 2011
Location: Serbia, Nis
Old 09-20-2011 , 09:45   Re: [API] Need Little Help Here :)
Reply With Quote #3

khm, khm... I'm not shure i understand you

Please explain better, like i'm stupid and i didn't understood you
You already know i am XD
__________________

Sorry about my BAD English
Krle is offline
Send a message via MSN to Krle
e12harry
Member
Join Date: Apr 2010
Old 09-20-2011 , 11:09   Re: [API] Need Little Help Here :)
Reply With Quote #4

You have removed item cost from menu co you have less parameters in achievements_add_item native. But then in
PHP Code:
public _item_add(iPluginiParams
you still read third param:
PHP Code:
 new szHandler[32]
 
get_string(3szHandlercharsmaxszHandler)) 
try:
PHP Code:
 new szHandler[32]
 
get_string(2szHandlercharsmaxszHandler)) 
I hope it will help
e12harry is offline
Krle
Senior Member
Join Date: Jul 2011
Location: Serbia, Nis
Old 09-20-2011 , 11:28   Re: [API] Need Little Help Here :)
Reply With Quote #5

i hope it will help, too... I will edit this post to tell did it worked, or no

Wroks!!! THANKS MY FRIEND!!!

New question:

How to make menu callback..
Like side plugin has bool, and while player hasn't got bool, item will be blank, when he gets the bool, item will be available...
So,
Main Plugin = Menu
Side Plugin = Bool - > Thats what makes me confused...

Should i register kills n killstreaks n bools into main plugin, and in side plugin only item and handler for item... 1. Post edited, thanks
__________________

Sorry about my BAD English

Last edited by Krle; 09-20-2011 at 12:06.
Krle is offline
Send a message via MSN to Krle
e12harry
Member
Join Date: Apr 2010
Old 09-21-2011 , 02:34   Re: [API] Need Little Help Here :)
Reply With Quote #6

I think you could use forwards:
http://forums.alliedmods.net/showthread.php?t=41241
But don't know if it will be the best option.
e12harry is offline
Krle
Senior Member
Join Date: Jul 2011
Location: Serbia, Nis
Old 09-21-2011 , 07:39   Re: [API] Need Little Help Here :)
Reply With Quote #7

nah, i don't understand it xD
__________________

Sorry about my BAD English
Krle is offline
Send a message via MSN to Krle
Xellath
Veteran Member
Join Date: Dec 2007
Location: Sweden
Old 09-21-2011 , 11:13   Re: [API] Need Little Help Here :)
Reply With Quote #8

Place the boolean in the main plugin, then create a native to set the bool = true | false.
__________________
Achievements API - a simple way for you to create your OWN custom achievements!
Xellath is offline
Krle
Senior Member
Join Date: Jul 2011
Location: Serbia, Nis
Old 09-21-2011 , 12:55   Re: [API] Need Little Help Here :)
Reply With Quote #9

Nevermind i put everything in one plugin, API is still complicated for me...

Anyway thanks
__________________

Sorry about my BAD English
Krle is offline
Send a message via MSN to Krle
Reply



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 08:43.


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