Raised This Month: $ Target: $400
 0% 

register_native natives and ... parameters


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 06-14-2007 , 00:55   register_native natives and ... parameters
Reply With Quote #1

Here is a function prototype in Plugin A:

Code:
public func(a,b,c[],{Float,Sql,Result,_}:...)

I would like to call this with a register_native native (that is registered in Plugin A) from Plugin B. I know that I can collect all of the arguments using native style 1 like this:

Code:
public func_native_handler(a,b,c[],{Float,Sql,Result,_}:...) {     param_convert(3);           new i, argnum = numargs();     for(i=4;i<=argnum;i++) param_convert(i); }

However, from here I need to make a direct call to "func" with all of these extra parameters, which could be of any variable type. I can't use vformat or anything and then send the condensed result into "func". The only thing that I could come up with was callfunc, except that I can't get the parameter types required for each specific native.

Any suggestions?
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS

Last edited by XxAvalanchexX; 06-14-2007 at 00:57.
XxAvalanchexX is offline
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 06-14-2007 , 02:37   Re: register_native natives and ... parameters
Reply With Quote #2

I decided that only integers and strings would be fine, so I tried this. It sort of works, except that the "getarg(i-1,1)" check comes back true for integers. I think that it's dipping into other memory, because when I use two separate integers they both result in the same string being formed. Are there any other ways to differentiate between a string and an int that you know of?

Code:
public func_native_handler(a,b,c[],{Float,Sql,Result,_}:...) {     param_convert(3);         static funcid;     if(!funcid) funcid = get_func_id("func");         callfunc_begin_i(funcid);     callfunc_push_int(a);     callfunc_push_int(b);     callfunc_push_str(c);         static buildString[128];     new i, j, argnum = numargs();     for(i=4;i<=argnum;i++)     {         param_convert(i);         if(getarg(i-1,1))         {             j = 0;             while(getarg(i-1,j))             {                 buildString[j] = getarg(i-1,j);                 j++;             }             buildString[j] = 0; // finish string             callfunc_push_str(buildString);         }         else callfunc_push_int(getarg(i-1));     }         callfunc_end(); }
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
Greenberet
AMX Mod X Beta Tester
Join Date: Apr 2004
Location: Vienna
Old 06-14-2007 , 05:31   Re: register_native natives and ... parameters
Reply With Quote #3

Code:
//bla.inc /** * c ^ cell * s ^ string * a ^ array * * plugin < 0 calls executing plugin * * ex. ForceCall( 0, "punishClient", "ccs", Client, Victim, "H4xx0r" ); * **/ // Deprecated native ForceCall ( plugin, const name[], const format[], any:... ); //bla.sma register_native( "ForceCall", "__ForceCall" ); //... public __ForceCall ( CPlugin, CParams ) {     static plugin, name[ 31 ], format[ 14 ], func_id, source[ 65 ], p_format, param;         plugin = get_param( 1 );     get_string( 2, name, 30 );     if ( plugin < 0 )         plugin = CPlugin;             func_id = get_func_id( name, plugin );     if ( func_id < 0 )         return -1;             get_string( 3, format, 13 );             if ( strlen( format ) != CParams - 3 )     {         log_error( AMX_ERR_NATIVE, "<< CORE >> format doesn't match parameters" );                 return 0;     }     if ( callfunc_begin_i( func_id, plugin ) != 1 )     {         log_error( AMX_ERR_NATIVE, "<< CORE >> God seems to hate ya" );                 return 0;     }         p_format = 0;     for ( param = 4; param <= CParams; param++ )     {         switch ( format[ p_format ] )         {             case 'c':             {                 callfunc_push_int( get_param_byref( param ) );             }                         case 's':             {                 get_string( param, source, 63 );                 callfunc_push_str( source );             }                         case 'a':             {                 callfunc_push_int( get_param( param ) );             }             default:             {                 log_error( AMX_ERR_NATIVE, "<< CORE >> What's '%c' ?", format[ p_format ] );             }         }                 ++p_format;     }     return callfunc_end(); }
__________________
Greenberet is offline
Send a message via ICQ to Greenberet Send a message via MSN to Greenberet
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 06-14-2007 , 13:49   Re: register_native natives and ... parameters
Reply With Quote #4

Wow, that's really nice. I should be able to find a way to use it in my situation. Thanks.
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
Greenberet
AMX Mod X Beta Tester
Join Date: Apr 2004
Location: Vienna
Old 06-14-2007 , 15:11   Re: register_native natives and ... parameters
Reply With Quote #5

to use it in your situation shoudnt be hard^^

ForceCall( Plugin, "func", "cca", 3,1, your_array );
__________________
Greenberet is offline
Send a message via ICQ to Greenberet Send a message via MSN to Greenberet
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 10:43.


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