AlliedModders

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

Napoleon_be 05-01-2018 17:20

Native help
 
I'm trying to test some stuff but it doesn't work.

get_user_level(id) simply returns 0 while i set iLevel[33] = 5 in the main plugin. what's wrong?

my include file is called level_test.inc

Code:
/* Plugin generated by AMXX-Studio */ #include <amxmodx> #include <amxmisc> #define PLUGIN "Native Test" #define VERSION "1.0" #define AUTHOR "author" new iLevel[33] = 5 public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     } public plugin_natives() {     register_library("level_test")         register_native("get_user_level", "_get_user_level") } public _get_user_level(iPlugin, iParams) {     if(iParams != 1) {         return PLUGIN_CONTINUE     }         new id = get_param(1)         if(!id) {         return PLUGIN_CONTINUE     }         return iLevel[id] }

Code:
/* Plugin generated by AMXX-Studio */ #include <amxmodx> #include <amxmisc> #include <level_test> #define PLUGIN "Test Plugin" #define VERSION "1.0" #define AUTHOR "author" public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)         register_clcmd("say /test", "Test") } public Test(id) {     client_print(id, print_chat, "level: %d", get_user_level(id)) }

Code:
#pragma reqlib "level_test" native get_user_level(id)

HamletEagle 05-01-2018 18:03

Re: Native help
 
new iLevel[33] = {5, ...}

Napoleon_be 05-04-2018 06:18

Re: Native help
 
Quote:

Originally Posted by HamletEagle (Post 2590320)
new iLevel[33] = {5, ...}


Well this was just to test something, thanks for your response.

How should it be done in a level system with the same array structure?

Native is meant to be used in a top 10 system.

HamletEagle 05-04-2018 07:09

Re: Native help
 
The native is correct. What is not correct is how you initialize your variable(meaning the test is wrong).
new iLevel[33] = 5 will set only index 0 to 5, the others remain 0. That's why your native returns 0. To set the entire array you must use the syntax I provided.

Napoleon_be 05-07-2018 09:28

Re: Native help
 
Well, players are given a certain value when killing someone in-game with the plugin i'm trying to fix. So that should work shouldn't it?

for example
Code:
iLevel[id] += 5

Then why does it still show 0 in the top 10?

Black Rose 05-07-2018 11:42

Re: Native help
 
new iLevel[33] = 5
This will only set iLevel[0] to 5, which will be ignored since the plugin returns 0 if the id is 0.

The native works as intended.

Code:
/* Plugin generated by AMXX-Studio */ #include <amxmodx> #include <amxmisc> #define PLUGIN "Native Test" #define VERSION "1.0" #define AUTHOR "author" new iLevel[33] = 5; public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     } public plugin_natives() {     register_library("level_test")     iLevel[2] = 666;     for ( new i ; i < sizeof iLevel ; i++ )         server_print("iLevel[%d]: %d", i, iLevel[i]);         register_native("get_user_level", "_get_user_level") } public _get_user_level(iPlugin, iParams) {     if(iParams != 1)         return 0         new id = get_param(1)     server_print("id: %d", id);         if(!id) {         return 0     }         return iLevel[id] }
Code:
/* Plugin generated by AMXX-Studio */ #include <amxmodx> #include <amxmisc> #pragma reqlib "level_test" native get_user_level(id) #define PLUGIN "Test Plugin" #define VERSION "1.0" #define AUTHOR "author" public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)         register_concmd("test", "Test") } public Test(id) {     server_print("level: %d", get_user_level(2)) }
Code:

iLevel[0]: 5
iLevel[1]: 0
iLevel[2]: 666
iLevel[3]: 0
iLevel[4]: 0
iLevel[5]: 0
iLevel[6]: 0
iLevel[7]: 0
iLevel[8]: 0
iLevel[9]: 0

... and so on...

test
id: 2
level: 666


HamletEagle 05-07-2018 12:25

Re: Native help
 
Quote:

Originally Posted by Napoleon_be (Post 2591086)
Well, players are given a certain value when killing someone in-game with the plugin i'm trying to fix. So that should work shouldn't it?

for example
Code:
iLevel[id] += 5

Then why does it still show 0 in the top 10?

Provide your actual test code.

Napoleon_be 05-13-2018 14:31

Re: Native help
 
this is the code that needs to be fixed. This isn't my code, just edited the accuracy part into the level part but it doesn't work. get_player_level() is made like i posted before in the test version. The only difference is that i don't set iLevel[33] = 5, iLevel[33] changes all the time when players level up killing people.

PHP Code:

format_top15(sBuffer[MAX_BUFFER_LENGTH 1])
{
    new 
iMax get_statsnum()
    new 
izStats[8], izBody[8], istate[4]//, SzName[32]
    
new iLen 0
 
    
//get_user_name(id, szName, 31);
   
    
if (iMax 10)
        
iMax 10
    
new lNick[20], lKills[20], lDeaths[20], lHs[20], lAcc[20], lLvl[20]
    
format(lNick19"Nick")
    
format(lKills19"Kills")
    
format(lDeaths19"Deaths")
    
format(lHs19"Headshots")
    
format(lLvl,charsmax(lLvl), "Level")
    
//format(lAcc, 19, "Accuracy")
    //format(knifeGetLevel(id), 19, "Level")
 
    //ucfirst(lAcc)
 
    
iLen formatsBufferMAX_BUFFER_LENGTH,
                  
"<head><META http-equiv=Content-Type content='text/html ;charset=UTF-8'></head><style>body{background:#191818;background-image: url(^"http://i63.tinypic.com/2v0g7br.jpg^");margin:5pt;padding:2pt;font-family:Tahoma;color:#eaeaea}.A{background-color:#262626;opacity:0.6;filter:alpha(opacity=60);}.B{background-color:#0b0b0b;opacity:0.6;filter:alpha(opacity=60);}td{font-size:15px}</style><center><table width=100%% background=^"^">" ) 
    
iLen += formatsBuffer[iLen], MAX_BUFFER_LENGTH iLen,
                  
"<tr><td><br/> <td></tr><tr><td><br/> <td></tr><tr><td><br/> <td></tr><tr><td><br/> <td></tr><tr><td><br/> <b><td></tr><tr><td>%s<td>%s<td>%s<td>%s<td>%s<td>%s</b>",
                  
"#"lNicklKillslDeathslHslLvl //knifeGetLevel(id) )
   
    
new players[32], inumid
    get_players
(playersinum)
   
    for(new 
iinumi++) {
        
id players[i]
    }
   
    for (new 
0iMax && MAX_BUFFER_LENGTH iLen 0i++)
    {
        if (
equal(istate,"A")) copy(istate,3,"B")
                else 
copy(istate,3,"A")
                
get_stats(iizStatsizBodyt_sNameMAX_NAME_LENGTH,sAuthid,MAX_NAME_LENGTH)
        while( 
contain t_sName"<" ) != -)
                
replacet_sName,MAX_BUFFER_LENGTH 1,"<""[" )
        while( 
contain t_sName">" ) != -)
                
replacet_sName,MAX_BUFFER_LENGTH 1,">""]" )
        if(
get_pcvar_num(authidgoster) == 1){
            
iLen += format(sBuffer[iLen], MAX_BUFFER_LENGTH iLen"<tr class=%s><td>%d<td>%s (%s)<td>%d<td>%d<td>%d<td>%d%%",istate1t_sNamesAuthidizStats[STATS_KILLS],
                
izStats[STATS_DEATHS], izStats[STATS_HS], get_player_level(id))
 
        }
        else{
            
iLen += format(sBuffer[iLen], MAX_BUFFER_LENGTH iLen"<tr class=%s><td>%d<td>%s <td>%d<td>%d<td>%d<td>%d%%",istate1t_sNameizStats[STATS_KILLS],
                
izStats[STATS_DEATHS], izStats[STATS_HS], get_player_level(id))
 
 
        }
    }
    
copy(sBuffer[iLen],MAX_BUFFER_LENGTH iLen,"</table></center>")



Napoleon_be 05-27-2018 13:13

Re: Native help
 
bump

CrazY. 05-28-2018 08:59

Re: Native help
 
Quote:

Originally Posted by Black Rose (Post 2591111)
iLevel[2] = 666;

what the...

OP, this won't work since you're only getting the last id that was set in players[32] by get_players.

Spoiler


:arrow:

Spoiler


All times are GMT -4. The time now is 04:43.

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