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

need help [API]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Krle
Senior Member
Join Date: Jul 2011
Location: Serbia, Nis
Old 09-16-2011 , 06:25   need help [API]
Reply With Quote #1

Okay this is my first API but im stuck and i don't know what to do further

INCLUDE FILE
PHP Code:
#if defined _achievements_included
    #endinput
#endif

#define _achievements_included

native register_achievement(const naziv[], const opis[]) 
Main Plugin File
PHP Code:
#include <amxmodx>
#include <cstrike>
#include <fakemeta>
#include <fun>
#include <hamsandwich>
#include <nvault>

new killstreak[33]
new 
deathstreak[33]
new 
killstreak_deagle[33]
new 
killstreak_knife[33]
new 
kills[33]

new 
bool:first_kill[33]
new 
bool:first_death[33]
new 
bool:marine[33]
new 
bool:rambo[33]
new 
bool:killer[33]
new 
bool:looser[33]
new 
bool:senior_member[33]
new 
bool:veteran_member[33]

new 
g_Vault

public plugin_init()
{
    
register_plugin("Achievements""0.3""MiloS -.-")
    
    
g_Vault nvault_open("Achievements")
    
    
RegisterHam(Ham_Spawn"player""HamSpawn"1)
    
RegisterHam(Ham_Killed"player""HamKilled"1)
    
    
register_clcmd("say /a""Achievements")
    
register_clcmd("say_team /a""Achievements")
    
    
register_dictionary("Achievements.txt")
}

public 
plugin_natives()
{
    
register_native("register_achievement""RegisterAchievement")
}

public 
RegisterAchievement(pluginparams)
{
    

public 
client_putinserver(id)
{
    
set_task(10.0"ShowMarketing"id 149)
}

public 
Achievements(id)
{
    new 
cb menu_makecallback("Achievements_CallBack")
    
    new 
menu menu_create("Achievements:""Achievements_Handle")
    
menu_additem(menu"First Kill"__cb)
    
menu_additem(menu"First Death"__cb)
    
menu_additem(menu"Marine"__cb)
    
menu_additem(menu"Rambo"__cb)
    
menu_additem(menu"Killer"__cb)
    
menu_additem(menu"Looser"__cb)
    
menu_additem(menu"Senior Member"__cb)
    
menu_additem(menu"Veteran Member"__cb)
    
    
menu_display(idmenu)
}

public 
Achievements_CallBack(idmenuitem)
{
    if(!
first_kill[id] && item == || !first_death[id] && item == || !marine[id] && item == || !rambo[id] && item == || !killer[id] && item == ||
    !
looser[id] && item == || !senior_member[id] && item == || !veteran_member[id] && item == 7)
    {
        return 
ITEM_DISABLED
    
}
    else
    {
        return 
ITEM_ENABLED
    
}
    
    return 
PLUGIN_CONTINUE
}

public 
Achievements_Handle(idmenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(menu)
        return 
PLUGIN_HANDLED
    
}
    
    
menu_display(idmenu)
    
    switch(
item)
    {
        case 
0:
        {
            
client_print(idprint_chat"[Achievements] %L"id"FIRST_KILL")
        }
        
        case 
1:
        {
            
client_print(idprint_chat"[Achievements] %L"id"FIRST_DEATH")
        }
        
        case 
2:
        {
            
client_print(idprint_chat"[Achievements] %L"id"MARINE")
            
client_print(idprint_chat"[Achievements] %L"id"MARINE_REWARD")
        }
        
        case 
3:
        {
            
client_print(idprint_chat"[Achievements] %L"id"RAMBO")
        }
        
        case 
4:
        {
            
client_print(idprint_chat"[Achievements] %L"id"KILLER")
            
client_print(idprint_chat"[Achievements] %L"id"KILLER_REWARD")
        }
        
        case 
5:
        {
            
client_print(idprint_chat"[Achievements] %L"id"LOOSER")
            
client_print(idprint_chat"[Achievements] %L"id"LOOSER_REWARD")
        }
        
        case 
6:
        {
            
client_print(idprint_chat"[Achievements] %L"id"SENIOR_MEMBER")
            
client_print(idprint_chat"[Achievements] %L"id"SENIOR_MEMBER_REWARD")
        }
        
        case 
7:
        {
            
client_print(idprint_chat"[Achievements] %L"id"VETERAN_MEMBER")
            
client_print(idprint_chat"[Achievements] %L"id"VETERAN_MEMBER_REWARD")
        }
    }
    
    return 
PLUGIN_CONTINUE
}

public 
HamKilled(idattacker)
{
    if(!
is_user_alive(attacker) || !is_user_connected(attacker))
    {
        
killstreak[attacker] = 0
        killstreak_deagle
[attacker] = 0
        killstreak_knife
[attacker] = 0
        
return HAM_IGNORED
    
}
    
    if(
get_user_team(attacker) != get_user_team(id))
    {
        
killstreak[attacker] ++
        
kills[attacker] ++
        
deathstreak[attacker] = 0
        
        
switch(get_user_weapon(attacker))
        {
            case 
CSW_DEAGLE:
            {
                
killstreak_deagle[attacker] ++
            }
            case 
CSW_KNIFE:
            {
                
killstreak_knife[attacker] ++
            }
        }
    }
    
    if(
get_user_team(id) != get_user_team(attacker))
    {
        
deathstreak[id] ++
    }
    
    switch(
killstreak[attacker])
    {
        case 
1:
        {
            
first_kill[attacker] = true
            client_print
(attackerprint_chat"%L"id"C_FIRST_KILL")
            
SaveData(attacker)
        }
        
        case 
10:
        {
            
killer[attacker] = true
            client_print
(attackerprint_chat"%L"id"C_KILLER")
            
SaveData(attacker)
        }
    }
    
    switch(
kills[attacker])
    {
        case 
1000:
        {
            
senior_member[attacker] = true
            client_print
(attackerprint_chat"%L"id"C_SENIOR_MEMBER")
            
SaveData(attacker)
        }
        
        case 
10000:
        {
            
veteran_member[attacker] = true
            client_print
(attackerprint_chat"%L"id"C_VETERAN_MEMBER")
            
SaveData(attacker)
        }
    }
    
    switch(
killstreak_deagle[attacker])
    {
        case 
7:
        {
            
marine[attacker] = true
            client_print
(attackerprint_chat"%L"id"C_MARINE")
            
SaveData(attacker)
        }
    }
    
    switch(
killstreak_knife[attacker])
    {
        case 
5:
        {
            
rambo[attacker] = true
            client_print
(attackerprint_chat"%L"id"C_RAMBO")
            
SaveData(attacker)
        }
    }
    
    switch(
deathstreak[id])
    {
        case 
1:
        {
            
first_death[id] = true
            client_print
(attackerprint_chat"%L"id"C_FIRST_DEATH")
            
SaveData(id)
        }
        
        case 
10:
        {
            
looser[id] = true
            client_print
(attackerprint_chat"%L"id"C_LOOSER")
            
SaveData(id)
        }
    }
    
    return 
HAM_IGNORED
}

public 
HamSpawn(id)
{
    if(!
is_user_alive(id))
    {
        return 
HAM_IGNORED
    
}
    
    if(
marine[id])
    {
        
give_item(id"weapon_deagle")
        
cs_set_user_bpammo(idCSW_DEAGLE35)
    }
    
    if(
killer[id])
    {
        
set_user_health(idget_user_health(id) + 5)
    }
    
    if(
looser[id])
    {
        
set_user_health(idget_user_health(id) - 3)
    }
    
    return 
HAM_IGNORED
}

public 
SaveData(id)
{
    new 
AuthID[35]
    
get_user_authid(idAuthID34)
    
    new 
vaultkey[64], vaultdata[256]
    
format(vaultkey63"%s-Mod"AuthID)
    
format(vaultdata255"%i#%i#%i#%i#%i#%i#%i#"first_kill[id], first_death[id], marine[id], rambo[id], killer[id], looser[id], kills[id])
    
nvault_set(g_Vaultvaultkeyvaultdata)
    
    return 
PLUGIN_CONTINUE
}

public 
LoadData(id)
{
    new 
AuthID[35]
    
get_user_authid(idAuthID34)
    
    new 
vaultkey[64], vaultdata[256]
    
format(vaultkey63"%s-Mod"AuthID)
    
format(vaultdata255"%i#%i#%i#%i#%i#%i#%i#"first_kill[id], first_death[id], marine[id], rambo[id], killer[id], looser[id], kills[id])
    
nvault_get(g_Vaultvaultkeyvaultdata255)
    
    
replace_all(vaultdata255"#"" ")
    
    new 
first_kill_a[32], first_death_a[32], marine_a[32], rambo_a[32], killer_a[32], looser_a[32], kills_a[32]
    
parse(vaultdatafirst_kill_a31first_death_a31marine_a31rambo_a31killer_a31looser_a31kills_a31)
    
    
first_kill[id] = str_to_num(first_kill_a) ? false true
    first_death
[id] = str_to_num(first_death_a) ? false true
    marine
[id] = str_to_num(marine_a) ? false true
    rambo
[id] = str_to_num(rambo_a) ? false true
    killer
[id] = str_to_num(killer_a) ? false true
    looser
[id] = str_to_num(looser_a) ? false true
    kills
[id] = str_to_num(kills_a)
    
    return 
PLUGIN_CONTINUE
}

public 
ShowMarketing(id)
{
    
id -= 149
    client_print
(idprint_chat"[Achievements] %L"id"MARKETING")
}

public 
client_disconnect(id)
{
    
remove_task(id 149)
}

public 
plugin_end()
{
    
nvault_close(g_Vault)

Side Plugin
PHP Code:
#include <amxmodx>
#include <fun>
#include <cstrike>
#include <hamsandwich>
#include <achievements>

new const naziv[] = "Marinac"
new const opis[] = "Svake nove runde dobija pun Deagle"

new killstreak_deagle[33]

new 
bool:marinac[33]

public 
plugin_init()
{
    
register_plugin(naziv"1.0""MiloS -.-")
    
    
register_achievement(nazivopis)
    
    
RegisterHam(Ham_Killed"player""HamKilled"1)
    
RegisterHam(Ham_Spawn"player""HamSpawn"1)
}

public 
HamKilled(victimattacker)
{
    if(!
is_user_alive(attacker))
    {
        
killstreak_deagle[attacker] = 0
        
return PLUGIN_HANDLED
    
}
    
    if(
attacker != victim)
    {
        if(
get_user_weapon(attacker) == CSW_DEAGLE)
        {
            
killstreak_deagle[attacker] ++
        }
    }
    
    if(
get_user_weapon(attacker) == CSW_DEAGLE)
    {
        switch(
killstreak_deagle[attacker])
        {
            
            case 
10:
            {
                
client_print(attackerprint_chat"[Achievements] Cestitamo, dobio si achievement Marinac")
                
marinac[attacker] = true
            
}
        }
    }
    
    return 
PLUGIN_CONTINUE
}

public 
HamSpawn(id)
{
    if(
marinac[id])
    {
        
give_item(id"weapon_deagle")
        
cs_set_user_bpammo(idCSW_DEAGLE35)
    }

I know i'm near, i want to put side achievement plugin into main's plugin menu, and thats where i'm stuck :\
And P.S. Ignore Marine achievement in main plugin, i will delete it

Please HELP OUT!!!
__________________

Sorry about my BAD English

Last edited by Krle; 09-16-2011 at 07:14.
Krle is offline
Send a message via MSN to Krle
Backstabnoob
Veteran Member
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 09-16-2011 , 06:32   Re: need help [API]
Reply With Quote #2

Plugin is the plugin ID that called the native
Params is the number of params (you should check if(Params != 2) return)

PHP Code:
new string[maxlen]
get_string(1stringmaxlen 1
This will copy the first parameter to the string variable. Then you can do w/e you want with it.
__________________
Currently busy working on a very large scale anime database project.
Backstabnoob is offline
Krle
Senior Member
Join Date: Jul 2011
Location: Serbia, Nis
Old 09-16-2011 , 06:44   Re: need help [API]
Reply With Quote #3

Soo,
PHP Code:
public RegisterAchievement(pluginparams)
{
        new 
string[maxlen]
        
get_string(1stringmaxlen 1)  

And this will solve my problem...??

I will make an side plugin for every achievement, and then just add it to the main's plugin menu , but should i make a new native get_achievement? or sumthing?

Thanks

Oh, oh, how to add side plugin's achievement to menu :O
__________________

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-16-2011 , 06:48   Re: need help [API]
Reply With Quote #4

You could check out how I coded Achievements API.

Or simply use it as base.
__________________
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-16-2011 , 06:53   Re: need help [API]
Reply With Quote #5

I don't want to steal youre plugin, i want to learn for further plugins i will made, this is just a simple plugin of How To do API... Or just Test plugin... I'm learning API from Cod Mod by QTM.Peyote, but thats not helping enough

But i will check your code for shure
__________________

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-16-2011 , 06:57   Re: need help [API]
Reply With Quote #6

Just check how I did it, and try to recreate something similar. That way you will learn
__________________
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-16-2011 , 07:05   Re: need help [API]
Reply With Quote #7

i just checked youre code, and it looks complicated... Can you just tell me what i need to do in my code... I'm soo near... Damn it XD
__________________

Sorry about my BAD English
Krle is offline
Send a message via MSN to Krle
Krle
Senior Member
Join Date: Jul 2011
Location: Serbia, Nis
Old 09-17-2011 , 13:23   Re: need help [API]
Reply With Quote #8

Hey Anyhow i can fix this i really need this fast...
__________________

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-17-2011 , 14:14   Re: need help [API]
Reply With Quote #9

What is the point of having an API and register the achievements in seperate plugins even though you hardcoded the menu (and the saving for that matter)?

Just make it simple. Keep everything in one plugin.
__________________
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-17-2011 , 15:07   Re: need help [API]
Reply With Quote #10

Lol as i said, i want to learn pawn, not to make plugin... My point is to learn api...
__________________

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 19:59.


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