Raised This Month: $12 Target: $400
 3% 

Formatted Strings in Dynamic Natives


Post New Thread Reply   
 
Thread Tools Display Modes
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
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 07-23-2006 , 10:43   Re: Formatted Strings in Dynamic Natives
Reply With Quote #2

probably better to just add this to my dynamic native tutorial, but whatever
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
jtp10181
Veteran Member
Join Date: May 2004
Location: Madison, WI
Old 07-23-2006 , 10:57   Re: Formatted Strings in Dynamic Natives
Reply With Quote #3

go for it, still gonna leave this here though
__________________
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
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 11:33.


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