Raised This Month: $ Target: $400
 0% 

Return string through native


Post New Thread Reply   
 
Thread Tools Display Modes
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-12-2014 , 16:37   Re: Return string through native
Reply With Quote #11

Quote:
Originally Posted by KliPPy View Post
There is actually some kind of pointers.
Pointers are not defined in the scope of Pawn (or at least in the version that is used by AMX Mod X) IIRC.
__________________
fysiks is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 06-12-2014 , 16:42   Re: Return string through native
Reply With Quote #12

Quote:
Originally Posted by fysiks View Post
Pointers are not defined in the scope of Pawn (or at least in the version that is used by AMX Mod X) IIRC.
That is why i put "(not really)" behind that statement... I know they are not the real pointers.
klippy is offline
Backstabnoob
Veteran Member
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 06-12-2014 , 16:47   Re: Return string through native
Reply With Quote #13

Your question about freeing the allocated string is a good one, I'd also like to know the answer even though I'm almost sure it's not possible.
__________________
Currently busy working on a very large scale anime database project.
Backstabnoob is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 06-12-2014 , 17:48   Re: Return string through native
Reply With Quote #14

I attempted again a test, failed...
Didn't test it with allocating strings though and I also couldn't get it to work with the param_convert native.

PHP Code:
public plugin_natives()
{
    
register_native("get_user_pmessage""native_get_user_pmessage")
}

public 
native_get_user_pmessage(idszBuffer[], iLen)
{
    new 
szBuffer32 ]
//testing purpose
    
get_user_nameidszBuffer31)
    return 
szBuffer
}

/* *******

Other plugin

*/ 
*******

    new 
szPMsg[32]
    
get_user_pmessage(idszPMsg31)
    
    
//param_convert(2); // 2 being the parameter number. 
    
    
client_print(idprint_chat"PMsg: %s"szPMsg
Empty string..
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
Old 06-12-2014, 18:00
Black Rose
This message has been deleted by Black Rose. Reason: Misunderstanding
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 06-12-2014 , 18:03   Re: Return string through native
Reply With Quote #15

You have 2 variables named szBuffer.
Also the style doesn't match the parameter types.
__________________

Last edited by Black Rose; 06-12-2014 at 18:05.
Black Rose is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 06-12-2014 , 18:15   Re: Return string through native
Reply With Quote #16

Quote:
Originally Posted by Backstabnoob View Post
Your question about freeing the allocated string is a good one, I'd also like to know the answer even though I'm almost sure it's not possible.
Well, if it is not possible, I guess we need to make an AMXX module that will provide a native that can release a memory with a given offset(or whatever the value returned by EngFunc_AllocString is).
klippy is offline
Backstabnoob
Veteran Member
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 06-12-2014 , 18:32   Re: Return string through native
Reply With Quote #17

PHP Code:
public plugin_natives()
{
    
register_native("get_user_pmessage""native_get_user_pmessage")
}

public 
native_get_user_pmessageiPluginiParams )
{
    new 
szBuffer32 ]
//testing purpose
    
get_user_nameget_param), szBuffer31)
    return 
szBuffer
}


/* *******

Other plugin

*/ 
*******

client_print(idprint_chat"PMsg: %s"get_user_pmessageid ) ) 
Try this
__________________
Currently busy working on a very large scale anime database project.
Backstabnoob is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-12-2014 , 19:03   Re: Return string through native
Reply With Quote #18

Quote:
Originally Posted by Backstabnoob View Post
PHP Code:
public plugin_natives()
{
    
register_native("get_user_pmessage""native_get_user_pmessage")
}

public 
native_get_user_pmessageiPluginiParams )
{
    new 
szBuffer32 ]
//testing purpose
    
get_user_nameget_param), szBuffer31)
    return 
szBuffer
}


/* *******

Other plugin

*/ 
*******

client_print(idprint_chat"PMsg: %s"get_user_pmessageid ) ) 
Try this
You have to use the set_string() function (also you shouldn't return the string). I do it in Polymorph, check it out for an example.
__________________

Last edited by fysiks; 06-12-2014 at 19:05.
fysiks is offline
Backstabnoob
Veteran Member
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 06-12-2014 , 19:24   Re: Return string through native
Reply With Quote #19

I know how set_string works, I just thought this method might work with natives as well, but it doesn't seem it does.

This works:
Spoiler


This doesn't:
Spoiler



Edit:
I was just experimenting, don't take my posts in this thread too seriously. @bibu: You should of course use set_string because that's the most reliable and readable option.
__________________
Currently busy working on a very large scale anime database project.

Last edited by Backstabnoob; 06-12-2014 at 19:48.
Backstabnoob is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 06-12-2014 , 19:39   Re: Return string through native
Reply With Quote #20

Natives work differently.

Assuming your trying to set the length yourself bibu, then do so like in the following. If not, remove the param, and return set_string() / get_user_name().

Registered as per usual:
Code:
#include <amxmodx> public plugin_natives() {     register_native( "get_user_pmessage", "_get_user_pmessage" ); } public _get_user_pmessage() {     new iLen = get_param( 2 );         new szName[ 32 ];     get_user_name( get_param( 1 ), szName, iLen );         set_string( 2, szName, iLen ); }

Registered with style 1:
Code:
#include <amxmodx> public plugin_natives() {     register_native( "get_user_pmessage2", "_get_user_pmessage2", 1 ); } public _get_user_pmessage2( id, szName[], iLen ) {     param_convert( 2 );     get_user_name( id, szName, iLen ); }

Code:
native get_user_pmessage( id, szName[], iLen ); native get_user_pmessage2( id, szName[], iLen );
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet 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 08:55.


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