View Single Post
Author Message
jtp10181
Veteran Member
Join Date: May 2004
Location: Madison, WI
Old 07-23-2006 , 10:15   Formatted Strings in Dynamic Natives
Reply With Quote #1

This is geared towards people who already know how to use register_native but want to create one with a formatted string as the last argument


This is how you define it in your include
This changes with what things you want passed to it
Code:
native someNativeName(var1, var2[], Float:var3, const message[], {Float,Sql,Result,_}:...);
Register the native as normal except set it to mode 1 at the end there
Code:
register_native("someNativeName","someMessage",1)
These arguments are only for example you could also define it like this and some of the numbers within the function would need to be changed
public someMessage(const message[], {Float,Sql,Result,_}:...)
Code:
public someMessage(var1, var2[], Float:var3, const message[], {Float,Sql,Result,_}:...)
{
 //Need to convert arg 2 because its an array (string) which is always passed byref
 param_convert(2)
 
 new nargs = numargs()
 //The number here is where it needs to start converting the Formatted String
 //Everything passed after "message" is by ref, and "message" is byref because its a string
 for (new x = 4; x <= nargs; x++) {
  param_convert(x)
 }
 new output[512]
 //The last number here is the number of the FIRST variable argument parameter
 //See "string.inc" for more info about vformat
 vformat(output, 511, message, 5)
 
 //Now "output" containts your message formatted with the arguments after it
yes I know I did not use small tags and thats because if I edit the post is messes everything up.
__________________
jtp10181 is offline
Send a message via ICQ to jtp10181 Send a message via AIM to jtp10181 Send a message via MSN to jtp10181 Send a message via Yahoo to jtp10181