Raised This Month: $ Target: $400
 0% 

Retrieving strings by using fake/dynamic natives


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 06-22-2010 , 10:33   Retrieving strings by using fake/dynamic natives
Reply With Quote #1

I have a problem regarding retrieving strings using fake natives..
For eg i made a plugin who's native can be used by other plugins to get a players name..so in the sub-plugin the native is used like this:
PHP Code:
new user_name
user_name 
get_persons_nameid 
and in the main plugin the function behind the native looks like this:
PHP Code:
// ......
 
public native_get_persons_nameid )
{
    static 
name[32]
    
get_user_nameid name 30 )
    
    
// return his name [It is not working....!!!]
    
return name[32]

But the problem is that this method is not working....
I didnt try it but according to my knowledge, in pawn we can not return arrays through natives ....
So is there any other method which can be used here...Thnx in advance
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
Kreation
Veteran Member
Join Date: Jan 2010
Location: Illinois
Old 06-22-2010 , 11:02   Re: Retrieving strings by using fake/dynamic natives
Reply With Quote #2

For one take the native_ out of the function name, I don't see why that's there.
__________________
Hi.
Kreation is offline
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 06-22-2010 , 11:09   Re: Retrieving strings by using fake/dynamic natives
Reply With Quote #3

Quote:
Originally Posted by Kreation View Post
For one take the native_ out of the function name, I don't see why that's there.
The code would be like this:
PHP Code:
#include < amxmodx >
#include < amxmisc >
 
// ...Code
 
public plugin_natives( )
{
    
register_native"get_persons_name" "native_get_persons_name" )
}
 
// ...Code
 
public native_get_persons_nameid )
{
   
// Blah blah code i wrote

__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 06-22-2010 , 11:13   Re: Retrieving strings by using fake/dynamic natives
Reply With Quote #4

You can't return an array. Follow the Plugin API and Fake Native tutorials by Hawk to learn about array packing in natives.
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 06-22-2010 , 11:36   Re: Retrieving strings by using fake/dynamic natives
Reply With Quote #5

Quote:
Originally Posted by Kreation View Post
Ah, well I didn't think about that. You can try:

PHP Code:
public native_get_user_name(paramsplugin)
{
    new 
id get_param(1);
 
    static 
name[32];
    return 
get_user_name(idname31);

I'm not sure if that will work or not.

I think this might be an off day for me.
It will not work bcoz you cant return arrays in natives
Quote:
Originally Posted by wrecked_ View Post
You can't return an array. Follow the Plugin API and Fake Native tutorials by Hawk to learn about array packing in natives.
Hawk's tutorials are always confusing and incomplete....
i read the natives tutorial but regarding my question nothing is covered there so i came up with another idea:
PHP Code:
public native_get_persons_nameid, const var_name[], maxlength )
{
    static 
name[32]
    
get_user_nameid name 30 )
 
    
// Copy the name into the array 
    // I think this will work !
    
copyvar_namemaxlength name)
 
    return 
1

sub-plugin will look like this:
PHP Code:
new user_name[32]
get_persons_nameiduser_namecharmaxuser_name ) ) 
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
Kreation
Veteran Member
Join Date: Jan 2010
Location: Illinois
Old 06-22-2010 , 11:16   Re: Retrieving strings by using fake/dynamic natives
Reply With Quote #6

Ah, well I didn't think about that. You can try:

PHP Code:
public native_get_user_name(paramsplugin)
{
    new 
id get_param(1);
    
    static 
name[32];
    return 
get_user_name(idname31);

I'm not sure if that will work or not.

I think this might be an off day for me.
__________________
Hi.
Kreation is offline
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 06-22-2010 , 11:48   Re: Retrieving strings by using fake/dynamic natives
Reply With Quote #7

I assumed you were doing this for zombie mod or whatever and got the native to search for a zombie. Feel free to replace the search function with whatever you need to get.

Code:
native get_zombie_name( name[], len ) /* Usage: new name[32] get_zombie_name( name, 31 ) */ public plugin_natives() {     register_native( "get_zombie_name", "NativeGetZombieName" ) } public NativeGetZombieName( plugin, paramsnum ) {     if( !paramsnum )     {         return PLUGIN_CONTINUE;     }         new id     new iPlayers[32]     new iNum         get_players( iPlayers, iNum )         // search for your player or whatever     // store the id for the zombie in id     for( new i = 0; i < iNum; i++ )     {         if( zp_get_user_zombie( iPlayers[i] ) )         {             id = iPlayers[i]                         break;         }     }         new name[32]     get_user_name( id, name, 31 )         set_string( 1, name, get_param( 2 ) )         return PLUGIN_CONTINUE; }
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 06-22-2010 , 14:02   Re: Retrieving strings by using fake/dynamic natives
Reply With Quote #8

Quote:
Originally Posted by wrecked_ View Post
I assumed you were doing this for zombie mod or whatever and got the native to search for a zombie. Feel free to replace the search function with whatever you need to get.
@wrecked_ : Can you give me a description about what this function performs.:
PHP Code:
set_string1nameget_param) ) 
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 06-22-2010 , 14:26   Re: Retrieving strings by using fake/dynamic natives
Reply With Quote #9

Quote:
Originally Posted by abdul-rehman View Post
@wrecked_ : Can you give me a description about what this function performs.:
PHP Code:
set_string1nameget_param) ) 
That sets the first native parameter (the string you pass when calling the function) to 'name'. It then uses the len you provide as the second native parameter.

set_string( destparam, string[], len )
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 06-22-2010 , 12:03   Re: Retrieving strings by using fake/dynamic natives
Reply With Quote #10

You can return an array as long as the destination is the same size as the source. In the code in the first post, user_name needs to be declared as "new user_name[32]" and your return should be just "return name"
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Reply


Thread Tools
Display Modes

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 14:44.


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