14.12.2013, 20:26
(
Last edited by Emmet_; 05/04/2015 at 10:16 AM.
)
Packed-safe format!
Introduction
As you may notice, the format function doesn't work at all with packed strings. And that couldn't be fixed without heavily modifying the format function. I've decided to add a solution for this - make format support packed strings!
What does it do?
This include allows you to pass a packed string to any parameter in format(). It also hooks printf() aswell, so it supports both functions aswell.
Instructions
Download ps-format.inc at the bottom of this post, and add it at the top of your script:
Make sure you include it AFTER all YSI includes!
You can now do this, something you couldn't do before:
Which outputs the following:
You can also use "printf" to print packed strings:
Which isn't possible without this include!
Download
Pastebin
Thanks to ****** for some #emit tips, and Zeex for the #emit pushing method.
Introduction
As you may notice, the format function doesn't work at all with packed strings. And that couldn't be fixed without heavily modifying the format function. I've decided to add a solution for this - make format support packed strings!
What does it do?
This include allows you to pass a packed string to any parameter in format(). It also hooks printf() aswell, so it supports both functions aswell.
Instructions
Download ps-format.inc at the bottom of this post, and add it at the top of your script:
pawn Code:
#include <ps-format>
You can now do this, something you couldn't do before:
pawn Code:
new
Packed:str[32],
Packed:str2[64];
format(str, sizeof(str), !"Cookies.");
format(str2, sizeof(str2), !"I like to eat %s.", str);
print(str2);
pawn Code:
I like to eat Cookies.
pawn Code:
printf(!"I like to eat %s with %d bottles of ketchup.", !"fried chicken", 38);
Download
Pastebin
Thanks to ****** for some #emit tips, and Zeex for the #emit pushing method.