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

Little help with a native issue


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 04-17-2019 , 19:30   Little help with a native issue
Reply With Quote #1

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <pubnite_mod>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
set_task(2.0"getValue")
}

public 
getValue()
{
    new 
iItemNewIDiItemNewRarityszItemModelSet[MAX_MODEL_LENGTH]
    
pubnite_get_randomitem(iItemNewIDiItemNewRarityszItemModelSet)
                
    
log_amx("iItemNewID: %d"iItemNewID)
    
log_amx("iItemNewRarity: %d"iItemNewRarity)
    
log_amx("szItemModelSet: %s"szItemModelSet)


So, basically, the first plugin reads an .ini file that gets all avaliable informations about a determined item (it works). Then I registered a native that I can use with another plugin, it's supposed to return a random's item information (the rarity, id and model). But, somehow, the set_param_byref is not doing it's job (for some reason it was working before, but magically, it stopped working). Anyone can tell me what I'm doing wrong or I need to do?

Also, both debug I did is the prove that the native is getting a random's item information, but it's not passing the value through the native.

Output:

Code:
L 04/17/2019 - 20:27:34: [PUBNite_CustomItens.amxx] native: 82 4 models/player/leet/leet.mdl
L 04/17/2019 - 20:27:34: [aaa.amxx] iItemNewID: 0
L 04/17/2019 - 20:27:34: [aaa.amxx] iItemNewRarity: 0
L 04/17/2019 - 20:27:34: [aaa.amxx] szItemModelSet: models/player/leet/leet.mdl
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 04-17-2019 at 21:54.
EFFx is offline
E1_531G
Senior Member
Join Date: Dec 2017
Old 04-17-2019 , 21:42   Re: Little help with a native issue
Reply With Quote #2

A simple cell/int are passed by value. Arrays are passed by reference.

A time ago i've seen a thing related to this subject, but i don't remember...
It was something about reference operator: &

Try this, maybe:
pubnite_get_randomitem(&iItemNewID, &iItemNewRarity, szItemModelSet)

We will wait together for someone who knows it better.

edit: ... i've mixed some things ... well, will see
__________________
My English is A0

Last edited by E1_531G; 04-17-2019 at 21:47.
E1_531G is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 04-17-2019 , 21:55   Re: Little help with a native issue
Reply With Quote #3

You're right, after adding the & it worked. I appreciate.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 04-17-2019 at 22:09.
EFFx is offline
E1_531G
Senior Member
Join Date: Dec 2017
Old 04-17-2019 , 22:46   Re: Little help with a native issue
Reply With Quote #4

Quote:
Originally Posted by EFFx View Post
You're right, after adding the & it worked. I appreciate.
LOL, really? Is it a joke?
If not then i am glad.
My memories about & were like in a fog.
__________________
My English is A0

Last edited by E1_531G; 04-17-2019 at 22:49.
E1_531G is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 04-17-2019 , 23:06   Re: Little help with a native issue
Reply With Quote #5

Yes, it actually worked.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-17-2019 , 23:46   Re: Little help with a native issue
Reply With Quote #6

Yes, arrays are always passed by reference by default, but 'regular' single-cell variables are passed by value. Adding the & passes them by reference allowing you to modify the 'original' variable that is passed within your function.

Here's a basic demo
PHP Code:

#include <amxmodx>

public plugin_init() 
{
    
//Define variable with a value of 10
    
new iByRef 10;
    
//Since & is used, the memory address of iByRef is passed, 
    //allowing the function to modify the variable directly.
    
TestByRefiByRef );
    
//Print value of iByRef
    
server_print"Val=%d" iByRef );
    
    
    
    
//Define variable with a value of 10
    
new iByVal 10;
    
//Since the variable is passed by-value, the function cannot
    //modify its value so we must return the value through the 
    //function.
    
server_print"Val=%d" TestByValiByVal ) );
}

public 
TestByRef( &)
{
    
10;
}

public 
TestByVal)
{
    return 
10;

__________________
Bugsy is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 04-18-2019 , 01:57   Re: Little help with a native issue
Reply With Quote #7

The major difference is that without the & I need to return the value?
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-18-2019 , 02:28   Re: Little help with a native issue
Reply With Quote #8

Quote:
Originally Posted by EFFx View Post
The major difference is that without the & I need to return the value?
You can either return a value or populate a byref parameter. If you have multiple outputs from a function, using at least one byref parameter is required.
__________________
fysiks is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-18-2019 , 07:11   Re: Little help with a native issue
Reply With Quote #9

I wouldn't think of it as 'if not byref then make the function return a value', because you can do both. It's just a means to get data into a variable. A common example is when you use get_players(), the players array and count variables (params 1 & 2) are passed by reference and both get data without the function itself returning anything.

Using byref is useful when you need a function to return multiple values, you can either use an array (by reference by default) or pass multiple variables by-reference using &. With this, you can set values in each variable, plus make the function return a value.
__________________
Bugsy is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 04-18-2019 , 13:29   Re: Little help with a native issue
Reply With Quote #10

Gotcha, thank you.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
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 09:14.


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