AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Retrieving strings by using fake/dynamic natives (https://forums.alliedmods.net/showthread.php?t=130290)

abdul-rehman 06-22-2010 10:33

Retrieving strings by using fake/dynamic natives
 
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

Kreation 06-22-2010 11:02

Re: Retrieving strings by using fake/dynamic natives
 
For one take the native_ out of the function name, I don't see why that's there.

abdul-rehman 06-22-2010 11:09

Re: Retrieving strings by using fake/dynamic natives
 
Quote:

Originally Posted by Kreation (Post 1216273)
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



wrecked_ 06-22-2010 11:13

Re: Retrieving strings by using fake/dynamic natives
 
You can't return an array. Follow the Plugin API and Fake Native tutorials by Hawk to learn about array packing in natives.

Kreation 06-22-2010 11:16

Re: Retrieving strings by using fake/dynamic natives
 
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.

abdul-rehman 06-22-2010 11:36

Re: Retrieving strings by using fake/dynamic natives
 
Quote:

Originally Posted by Kreation (Post 1216290)
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_ (Post 1216286)
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 ) ) 


wrecked_ 06-22-2010 11:48

Re: Retrieving strings by using fake/dynamic natives
 
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; }

YamiKaitou 06-22-2010 12:03

Re: Retrieving strings by using fake/dynamic natives
 
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"

abdul-rehman 06-22-2010 14:02

Re: Retrieving strings by using fake/dynamic natives
 
Quote:

Originally Posted by wrecked_ (Post 1216318)
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) ) 


wrecked_ 06-22-2010 14:26

Re: Retrieving strings by using fake/dynamic natives
 
Quote:

Originally Posted by abdul-rehman (Post 1216408)
@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 )


All times are GMT -4. The time now is 14:44.

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