AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Register_Native (https://forums.alliedmods.net/showthread.php?t=309444)

PurposeLessx 07-26-2018 12:08

Register_Native
 
Hey friends,
I am making a native plugin for using commands simply.
How can I make plugin more optimized? I don't want to use style 1. It's not recommended.
Waiting for your help :)

Native plugin (will work in server)
PHP Code:


// new bool:g_unammocuk[33] // will give players unammo.

public plugin_natives()
{
    
register_library("np");

    
register_native("np_set_user_unammo""native_set_user_unammo");
    
register_native("np_get_user_unammo""native_get_user_unammo"1);
    
register_native("np_set_user_rendering""native_set_user_rendering");
}

public 
native_set_user_unammo(indexunammo 0)
{
    new 
id get_param(1);

    if(!
id)
    {
        
set_fail_state("Error not found player.");
        return 
1;
    }

    
g_unammocuk[id] = unammo == false:true;
    return 
1;
}

public 
native_get_user_unammo(index)
{
    new 
id get_param(1);

    if(!
id)
    {
        
set_fail_state("Error not found player.");
        return 
1;
    }

    return 
g_unammocuk[id] ? true:false;
}

public 
native_set_user_rendering(indexfx kRenderFxNone, {Float,_}:color[3] = {0.0,0.0,0.0}, render kRenderNormalFloat:amount 0.0)
{
    new 
id get_param(1);
    new 
fx_id get_param(2);
    new 
Float:color_id get_param(3);
    new 
render_id get_param(4);
    new 
Float:amount_id get_param(5);

    if(!
id)
    {
        
set_fail_state("set_user_rendering user bulunamadi.");
        return 
1;
    }

    
set_entvar(idvar_renderfxfx_id fx_id:kRenderFxNone);
    
set_entvar(idvar_rendercolorcolor_id color_id:{0.0,0.0,0.0});
    
set_entvar(idvar_rendermoderender_id render_id:kRenderNormal);
    
set_entvar(idvar_renderamtamount_id amount_id:0.0);
    return 
1;


Np.inc
PHP Code:

#pragma reqlib "np"

/*
* Enable/Disable player's unammo skill.
*
* @param index            Client index
* @param unammo        To enable unammo
*
* @return        1 on success, 0 otherwise
*/

native np_set_user_unammo(const indexunammo 0)

/*
* Get the unammo of the player
*
* @param index            Client index
*
* @return        1 on success, 0 otherwise
*/

native np_get_user_unammo(const index)

native np_set_user_rendering(blabla// not finished enough 


CrazY. 07-26-2018 13:29

Re: Register_Native
 
Next time, search.

Why you just don't use set_user_rendering of fun?

PurposeLessx 07-26-2018 13:30

Re: Register_Native
 
Wow, that is f awesome :D

Because of I am using reapi include and think that do not need use fun. These are almost same.

OciXCrom 07-26-2018 13:31

Re: Register_Native
 
Don't use style 1. Style 0 natives have only 2 parameters:

PHP Code:

public your_native(iPluginiParams

iPlugin = plugin id
iParams = number of parameters in the native

CrazY. 07-26-2018 13:41

Re: Register_Native
 
@OP, again, the objective of ReAPI is not replace other modules, the objective is provide a more stable version. Anyway, case you still don't want to use the fun, better make a stock instead of create a native.

Convert this stock to ReAPI, the end.

Code:
/*  Set rendering of an entity */ stock set_rendering(index, fx=kRenderFxNone, r=255, g=255, b=255, render=kRenderNormal, amount=16) {     entity_set_int(index,EV_INT_renderfx,fx);     new Float:RenderColor[3];     RenderColor[0] = float(r);     RenderColor[1] = float(g);     RenderColor[2] = float(b);     entity_set_vector(index,EV_VEC_rendercolor,RenderColor);     entity_set_int(index,EV_INT_rendermode,render);     entity_set_float(index,EV_FL_renderamt,float(amount));     return 1; }

Celena Luna 07-26-2018 17:47

Re: Register_Native
 
if you used style 1 then you don't need to use get_param();


All times are GMT -4. The time now is 12:18.

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