[Include] DynamicParams.inc - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (
https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (
https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] DynamicParams.inc (
/showthread.php?tid=364287)
DynamicParams.inc -
RyDeR` - 30.07.2012
DynamicParams.inc
I promised to start a topic about this include in my rCmd.inc topic a while ago, but I forgot about it - so here it is. It's basically an include to call functions (not natives) dynamically; you can push all parameters apart and then call the function itself wherever you want.
Functions
These are the types you can push:
pawn Код:
enum e_Types {
Mixed,
String,
ByRef
};
Here are the main functions:
pawn Код:
stock Push_Param(const e_Types: iType, { Float, _ }: ...);
stock Set_Param(const e_Types: iType, iIdx, { Float, _ }: ...);
stock Pop_Param();
stock CallFunction(const szName[], const bool: bPop = true);
Examples
pawn Код:
public OnFilterScriptInit() {
new
Float: fFloat = 360.0
;
Push_Param(Mixed, fFloat);
Push_Param(Mixed, 50000);
new
iIdx = Push_Param(String, "Bla Bla!")
;
Set_Param(String, iIdx, "Oh sorry, wrong string!");
new
iInteger2,
Float: fFloat2,
szBuf[32]
;
Push_Param(ByRef, iInteger2);
Push_Param(ByRef, fFloat2);
Push_Param(String, szBuf);
CallFunction("foo", .bPop = true);
printf("%d %f %s", iInteger2, fFloat2, szBuf); // 12345 270.000000 Hello World!
return 1;
}
pawn Код:
forward foo(Float: fFloat, iInteger, szStr[], &iInteger2, &Float: fFloat2, szBuf[]); public foo(Float: fFloat, iInteger, szStr[], &iInteger2, &Float: fFloat2, szBuf[]) {
printf("%f %d %s", fFloat, iInteger, szStr); // 360.000000 50000 Oh sorry, wrong string!
iInteger2 = 12345;
fFloat2 = 270.0;
strcat(szBuf, "Hello World!", 32);
}
Prints:
pawn Код:
360.000000 50000 Oh sorry, wrong string!
12345 270.000000 Hello World!
Download
DynamicParams.inc
Re: DynamicParams.inc -
Kaperstone - 30.07.2012
What it used for ?
Re: DynamicParams.inc -
RyDeR` - 30.07.2012
Quote:
Originally Posted by xkirill
What it used for ?
|
Well, I'm using it in my rCmd.inc for example. You could also call functions in-game with this (just an idea).
Re: DynamicParams.inc -
Arca - 30.07.2012
Quote:
Originally Posted by RyDeR`
Well, I'm using it in my rCmd.inc for example. You could also call functions in-game with this (just an idea).
|
When to use it?
Re: DynamicParams.inc -
MP2 - 30.07.2012
You should give examples.
Re: DynamicParams.inc -
RyDeR` - 30.07.2012
Quote:
Originally Posted by Arca
When to use it?
|
Sorry, what do you mean by that? I think everything is clear.
Quote:
Originally Posted by MP2
You should give examples.
|
No offense, but can't you see the big-ass "Examples" title in the main post?
Re: DynamicParams.inc -
FireCat - 30.07.2012
Nice one!
I was searching something like this some time ago