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

Looking for Custom header tutorial


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Abiss32
Junior Member
Join Date: Dec 2018
Old 03-27-2020 , 07:37   Looking for Custom header tutorial
Reply With Quote #1

Hello!

I am new to Scripting( sorry if i ask dump questions). I want to know how header files work.
I am trying to make my own script for a level and money system but i want to make custom natives
so i can make external menus but i want to know how i can make my own custom header files

I'll give an simple example of the natives i want to make but i don't know how to make it funcional:
Code:
native zp_get_user_level(id)
native zp_set_user_level(id, valiue)
I will be so greatful if someone gives me a tutorial about this!

Last edited by Abiss32; 03-29-2020 at 12:31. Reason: writing mistake
Abiss32 is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 03-27-2020 , 08:16   Re: Looking for Custom header tutorisl
Reply With Quote #2

https://forums.alliedmods.net/showthread.php?t=41251
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 03-27-2020 , 16:06   Re: Looking for Custom header tutorisl
Reply With Quote #3

First, you need to define your natives in your main plugin using this public:
Example:
PHP Code:
public plugin_natives()
{
    
register_native("zp_get_user_level""_zp_get_user_level"0);
    return 
0;

and then define what does that native:

PHP Code:
public _zp_get_user_level(/**some index **/)
{
    
//what should do this native?

That's it. This is how the natives works.
If you want to use a native in a plugin, just define it like this:
PHP Code:
native zp_get_user_level(/**some index **/
Hope I helped you
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]

Last edited by Shadows Adi; 03-27-2020 at 16:07. Reason: some grammer
Shadows Adi is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 03-27-2020 , 16:27   Re: Looking for Custom header tutorisl
Reply With Quote #4

@Shadows Adi - there is no index in the native's body when using style 0. The body needs to contain 2 parameters - iPlugin (the plugin that's calling the native) and iParams (number of arguments).
__________________

Last edited by OciXCrom; 03-27-2020 at 16:27.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Abiss32
Junior Member
Join Date: Dec 2018
Old 03-29-2020 , 08:48   Re: Looking for Custom header tutorisl
Reply With Quote #5

Quote:
Originally Posted by Shadows Adi View Post
First, you need to define your natives in your main plugin using this public:
Example:
PHP Code:
public plugin_natives()
{
    
register_native("zp_get_user_level""_zp_get_user_level"0);
    return 
0;

and then define what does that native:

PHP Code:
public _zp_get_user_level(/**some index **/)
{
    
//what should do this native?

That's it. This is how the natives works.
If you want to use a native in a plugin, just define it like this:
PHP Code:
native zp_get_user_level(/**some index **/
Hope I helped you
Ok. So i've tryed to make a small plugin but i am getting errors like this:

Code:
L 03/29/2020 - 15:39:33: Function "get_user_money" was not found
L 03/29/2020 - 15:39:33: [AMXX] Run time error 19 (plugin "oz_money_system_beta.amxx") - debug not enabled!
L 03/29/2020 - 15:39:33: [AMXX] To enable debug mode, add "debug" after the plugin name in plugins.ini (without quotes).
L 03/29/2020 - 15:39:33: [AMXX] Run time error -1 (plugin "oz_money_system_beta.amxx") - debug not enabled!
L 03/29/2020 - 15:39:33: An error occurred in plugin_natives. This is dangerous!
L 03/29/2020 - 15:39:33: [AMXX] Plugin "money_sys_beta_system.amxx" failed to load: Plugin uses an unknown function (name "zp_set_user_money") - check your module
and here's the code i've made( its some stupid mistakes i made but i don't know how to fix them).

Main plugin:
PHP Code:
#include <amxmodx>


#define PLUGIN "[OZ]Money System(beta)"
#define VERSION "0.1"
#define AUTHOR "real<Abiss>"

new g_Msg_Money;
new 
zp_player_money[33];

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
g_Msg_Money get_user_msgid("Money")
    
}
public 
plugin_natives()
{
    
register_native("zp_get_user_money","get_user_money",1)
    
register_native("zp_set_user_money","set_user_money",1)
    return 
0;
}


public 
native_get_user_money(id)
{
    return 
zp_player_money[id]
}

public 
native_set_user_money(idvalue)
{
    
zp_player_money[id] = value;
    if (!
is_user_alive(id))
    {
        return 
0;
    }
    
sent_money(idvalue)
    return 
0;
}
sent_money(idnum)
{
     
message_begin(MSG_ONE_UNRELIABLEg_Msg_Money_,id)
     
write_long(num)
     
write_byte(1)
     
message_end()
     return 
0;

The actual Money system:
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <money_sys>
#include <hamsandwich>
#include <zombieplague>

#define PLUGIN "[OZ] Money System beta"
#define VERSION "0.1"
#define AUTHOR "real<Abiss>"


//=========================================
#define ADMIN_LEVEL    ADMIN_LEVEL_H
//=========================================
#define LIMIT 150000
#define LIMIT_ADMIN 300000
//=========================================
new pcvar_humans_dmg_reward;
public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
RegisterHam(Ham_TakeDamage"player","fwTakeDamage",1)
    
pcvar_humans_dmg_reward register_cvar("ms_money_devide","1");
    
}

public 
fwTakeDamage(idweaponattackerFloat:damage)
{    
    if(!
is_user_alive(attacker))
        return
        
    if(
zp_get_user_zombie(attacker))
        return    
        
    
damage/=get_pcvar_num(pcvar_humans_dmg_reward)
            
    
set_money(attackerfloatround(damage))
}

public 
set_money(idvalue)
{
    new 
money=zp_get_user_money(id)+value
        
    money
=amx_clamp(money, (get_user_flags(id)&ADMIN_LEVEL)?LIMIT_ADMIN:LIMIT)
        
    
zp_set_user_money(idmoney)
}

stock amx_clamp(valuemaximum)
    return 
value>maximum?maximum:value 
And the header file:
PHP Code:
native zp_get_user_money(id)

native zp_set_user_money(idvalue
Abiss32 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 03-29-2020 , 10:05   Re: Looking for Custom header tutorisl
Reply With Quote #6

Style 1 natives are deprecated. You should use style 0. Example:

Code:
public native_set_user_money(iPlugin, iParams) {     new id = get_param(1);     zp_player_money[id] = get_param(2);     if (!is_user_alive(id))     {         return 0;     }     sent_money(id, value)     return 0; }

PS: you set the function name to "get_user_money", but you're using "native_get_user_money".
__________________

Last edited by OciXCrom; 03-29-2020 at 10:07.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Abiss32
Junior Member
Join Date: Dec 2018
Old 03-29-2020 , 10:47   Re: Looking for Custom header tutorial
Reply With Quote #7

Ok so I fixed the errors but I have problem with a bug. Sometimes I get some wierd incomes and I lose money when I hit someone or when I kill someone. How can fix it?

Main Plugin:
PHP Code:
#include <amxmodx>

#define PLUGIN "[OZ]Money System(beta)"
#define VERSION "0.1"
#define AUTHOR "real<Abiss>"

#define MAXPLAYERS 32

#define is_user_valid(%1) (1 <= %1 <= g_MaxPlayers)

new g_Msg_Money;
new 
g_MaxPlayers;
new 
zp_player_money[MAXPLAYERS+1];

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
g_Msg_Money get_user_msgid("Money")
    
g_MaxPlayers get_maxplayers()
    
}
public 
plugin_natives()
{
    
register_native("zp_get_user_money","get_user_money",0)
    
register_native("zp_set_user_money","set_user_money",0)
    return 
0;
}


public 
get_user_money(id)
{
    new 
id get_param(1)
    
    if (!
is_user_valid(id))
    {
        
        return -
1;
    }
    
    
    return 
zp_player_money[id];
}

public 
set_user_money(plugin_idparam_num)
{
    new 
id get_param(1);
   

    if (!
is_user_alive(id))
    {
        return 
0;
    }
    
    new 
amount get_param(2)
    
    
zp_player_money[id] = amount
    

    message_begin
(MSG_ONE_UNRELIABLEg_Msg_Money_,id)
    
write_long(amount)
    
write_byte(1)
    
message_end()
    return 
0;

And the money system:
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <money_sys>
#include <hamsandwich>
#include <zombieplague>

#define PLUGIN "[OZ] Money System beta"
#define VERSION "0.1"
#define AUTHOR "real<Abiss>"


//=========================================
#define ADMIN_LEVEL    ADMIN_LEVEL_H
//=========================================
#define LIMIT 150000
#define LIMIT_ADMIN 300000
//=========================================
new pcvar_humans_dmg_reward;


public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
RegisterHam(Ham_TakeDamage"player","fwTakeDamage",1)
    
pcvar_humans_dmg_reward register_cvar("ms_money_devide","1");
    
}

public 
fwTakeDamage(idweaponattackerFloat:damage)
{    
    if(!
is_user_alive(attacker))
        return
        
    if(
zp_get_user_zombie(attacker))
        return    
        
    
damage/=get_pcvar_num(pcvar_humans_dmg_reward)
            
    
set_money(attackerfloatround(damage))
}

public 
set_money(idvalue)
{
    new 
money zp_get_user_money(id)+value
        
    money
=amx_clamp(money, (get_user_flags(id)&ADMIN_LEVEL)?LIMIT_ADMIN:LIMIT)
        
    
zp_set_user_money(idmoney)
}

stock amx_clamp(valuemaximum)
    return 
value>maximum?maximum:value 

Last edited by Abiss32; 03-29-2020 at 13:36. Reason: some fixed issues
Abiss32 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 03-29-2020 , 13:35   Re: Looking for Custom header tutorial
Reply With Quote #8

The first one, no - it's still style 1.
The second, yes.
__________________

Last edited by OciXCrom; 03-29-2020 at 13:35.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Abiss32
Junior Member
Join Date: Dec 2018
Old 03-29-2020 , 14:10   Re: Looking for Custom header tutorial
Reply With Quote #9

I fixed the plugin but I came accross bugs you can see full detail on the comment above yours. I was editing the comment while you replyed.
Abiss32 is offline
Abiss32
Junior Member
Join Date: Dec 2018
Old 04-12-2020 , 11:55   Re: Looking for Custom header tutorial
Reply With Quote #10

I've fixed some of the issues but I can't fix one bug. I am loseing money in certain conditions:
- When the 1st hit occurs.
- And at the end of the round or when i die.

Please tell me how to fix this data loss.

This is the plugin with the code that has this bug:

PHP Code:
#include <amxmodx>

#define PLUGIN "[OZ]Money System(beta)"
#define VERSION "0.1"
#define AUTHOR "real<Abiss>"

#define MAXPLAYERS 32

#define is_user_valid(%1) (1 <= %1 <= g_MaxPlayers)

new g_Msg_Money;
new 
g_MaxPlayers;
new 
zp_player_money[MAXPLAYERS+1];

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
g_Msg_Money get_user_msgid("Money")
    
g_MaxPlayers get_maxplayers()
    
}
public 
plugin_natives()
{
    
register_native("zp_get_user_money","get_user_money",0)
    
register_native("zp_set_user_money","set_user_money",0)
}


public 
get_user_money(id)
{
    new 
id get_param(1)
    
    if (!
is_user_valid(id))
    {
        
        return 
0;
    }
    
    
    return 
zp_player_money[id];
}

public 
set_user_money(plugin_idparam_num)
{
    new 
id get_param(1);
   

    if (!
is_user_alive(id))
    {
        return 
0;
    }
    
    new 
amount get_param(2);
    
    
zp_player_money[id] = amount
    

    message_begin
(MSG_ONE_UNRELIABLEg_Msg_Money_,id)
    
write_long(amount)
    
write_byte(1)
    
message_end()

Abiss32 is offline
Reply


Thread Tools
Display Modes

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 13:24.


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