AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Native: get_user_rank (https://forums.alliedmods.net/showthread.php?t=325610)

Supremache 06-29-2020 08:12

Native: get_user_rank
 
I made Native for get_user_rank but it show me only first word of rank name how to fix it ?

https://i.ibb.co/PDqtd9P/5121.png

PHP Code:

enum _:mData {
    
m_szRankName32 ],
    
m_iRankXP
};

new const 
g_mPlayerDataMAXLEVEL ][ mData ] = {
    { 
"Private"},
    { 
"Specialist"50 },
    { 
"Corporal"200 },
    { 
"Sargeant"350 },
    { 
"Staff Sargeant"600 },
    { 
"Warrant Officer"1000 },
    { 
"Chief Warrant Officer"1500 },
    { 
"Second Lieutenant"2500 },
    { 
"First Lieutenant"5000 },
    { 
"Captain"8250 },
    { 
"Major"13500 },
    { 
"Colonel"20000 },
    { 
"General"30000 },
    { 
"General of The Army"45000 }
};


public 
plugin_natives()
{
    
register_native("get_user_rank""native_get_user_rank"1)
}

// Native: get_user_rank
public native_get_user_rank(id)
{
    return 
g_mPlayerDatag_iPlayerLevelid ] ][ m_szRankName ]



alferd 06-29-2020 08:32

Re: Native: get_user_rank
 
PHP Code:

m_szRankName512 

test

Bugsy 06-29-2020 08:42

Re: Native: get_user_rank
 
https://forums.alliedmods.net/showthread.php?t=242017

Supremache 06-29-2020 10:17

Re: Native: get_user_rank
 
@alferd - Not worked


@Bugsy - I did it but i have got this problme

What i did:
PHP Code:


public plugin_natives()
{

    
register_native("get_user_rank""_get_user_rank"1)
}

public 
_get_user_rank()
{
    new 
iLen get_param);
    
set_string2g_mPlayerDatag_iPlayerLevelget_param(1) ] ] [ m_szRankName ], iLen );


The problem:

Code:

L 06/29/2020 - 16:16:22: [AMXX] Run time error 10 (plugin "lvl.amxx") (native "get_param") - debug not enabled

MagNNusS 06-29-2020 11:46

Re: Native: get_user_rank
 
Quote:

Originally Posted by Supremache (Post 2707810)
PHP Code:

register_native("get_user_rank""_get_user_rank"1


You registered a native on style 1 but the function you've used it is in the old one.
Take a real quick look at this post. So you can see where's the difference between style 1 and the old one.

Supremache 06-29-2020 12:13

Re: Native: get_user_rank
 
Quote:

Originally Posted by MagNNusS (Post 2707826)
You registered a native on style 1 but the function you've used it is in the old one.
Take a real quick look at this post. So you can see where's the difference between style 1 and the old one.

I dont understand!!, Sorry this is my first time in native coding.

HamletEagle 06-29-2020 12:54

Re: Native: get_user_rank
 
Quote:

Originally Posted by MagNNusS (Post 2707826)
You registered a native on style 1 but the function you've used it is in the old one.
Take a real quick look at this post. So you can see where's the difference between style 1 and the old one.

"the old one"
Style 0 is not "old", in fact it is what you should use. Style 1 is deprecated, do not use it.
OP, just switch to style 0 natives, no point in trying to fix code you shouldn't write in the first place.
Then read this: https://forums.alliedmods.net/showthread.php?t=41251

P.S: enable debug already. Don't post error logs with debug disabled, they are useless.

Supremache 06-29-2020 15:37

Re: Native: get_user_rank
 
Quote:

Originally Posted by HamletEagle (Post 2707834)
"the old one"
Style 0 is not "old", in fact it is what you should use. Style 1 is deprecated, do not use it.
OP, just switch to style 0 natives, no point in trying to fix code you shouldn't write in the first place.
Then read this: https://forums.alliedmods.net/showthread.php?t=41251

P.S: enable debug already. Don't post error logs with debug disabled, they are useless.

I did it but rank name didn't show

https://i.ibb.co/Qj8jZDF/15.png

.inc
Quote:

/**
* Returns the client's current rank.
*
* @param id Client index.
* @param buffer Buffer to store the rank name in.
* @param len Maximum buffer length.
* @noreturn
*/

native get_user_rank(id)

PHP Code:


public plugin_natives()
{
    
register_library("levels")
    
register_native("get_user_rank""_get_user_rank"1)
}


public 
_get_user_rank(iPlugin,iParams)
{
    if(
iParams != 1)
        return 
PLUGIN_CONTINUE
        
    
new id get_param(1)
    if(!
id)
        return 
PLUGIN_CONTINUE;
        
    
set_string(idg_mPlayerDatag_iPlayerLevelid ] ][ m_szRankName ], 2)
    
    return 
PLUGIN_CONTINUE




Bugsy 06-29-2020 16:50

Re: Native: get_user_rank
 
You're still using style 1

register_native("get_user_rank", "_get_user_rank", 1)

And maxlen is set to 2, use charsmax( g_mPlayerData[][ m_szRankName ] )

set_string( id, g_mPlayerData[ g_iPlayerLevel[ id ] ][ m_szRankName ], 2)

Bugsy 06-29-2020 16:56

Re: Native: get_user_rank
 
And show me how you're using this native in your plugin. You should post all code, not snippets.


All times are GMT -4. The time now is 17:45.

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