SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 14/12/2013, 08:26 PM   #1
Emmet_
Guest
 
Posts: n/a
Default Packed-safe format!

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:

pawn Code:
#include <ps-format>

Make sure you include it AFTER all YSI includes!

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);

Which outputs the following:

pawn Code:
I like to eat Cookies.

You can also use "printf" to print packed strings:

pawn Code:
printf(!"I like to eat %s with %d bottles of ketchup.", !"fried chicken", 38);

Which isn't possible without this include!

Download
Pastebin

Thanks to ****** for some #emit tips, and Zeex for the #emit pushing method.

Last edited by Emmet_; 05/04/2015 at 10:16 AM.
  Reply With Quote
Old 14/12/2013, 08:30 PM   #2
Wizzy951
Huge Clucker
 
Wizzy951's Avatar
 
Join Date: Jul 2013
Posts: 285
Reputation: 41
Default Re: Packed-safe format!

Nice!
Wizzy951 is offline   Reply With Quote
Old 14/12/2013, 08:43 PM   #3
DavidLuango
Huge Clucker
 
Join Date: Aug 2013
Posts: 279
Reputation: 29
Default Re: Packed-safe format!

Awesome release emmet!
DavidLuango is offline   Reply With Quote
Old 14/12/2013, 09:10 PM   #4
Emmet_
Guest
 
Posts: n/a
Default Re: Packed-safe format!

Thanks, guys.

Also everyone, feel free to perform some tests with this! Packed strings are a great feature for saving memory and it's a shame that format doesn't support it entirely - now it does!
  Reply With Quote
Old 14/12/2013, 09:14 PM   #5
Jimmy0wns
Gangsta
 
Join Date: Sep 2012
Location: Netherlands
Posts: 686
Reputation: 208
Default Re: Packed-safe format!

Very nice, thanks!
Jimmy0wns is offline   Reply With Quote
Old 14/12/2013, 09:31 PM   #6
Zamora
Big Clucker
 
Zamora's Avatar
 
Join Date: Sep 2013
Posts: 175
Reputation: 25
Default Re: Packed-safe format!

Very nice...!
__________________

Discord: Click Here


you.tube.com/watch?v=fmBd0ZoH2AU - MDC System
Zamora is offline   Reply With Quote
Old 14/12/2013, 11:06 PM   #7
Emmet_
Guest
 
Posts: n/a
Default Re: Packed-safe format!

Thanks, people.

I should also say that the 3rd argument in format (after the size / length) can't take a packed parameter. This is good as it lets people use more wiser methods of copying strings (strcat and strpack).
  Reply With Quote
Old 14/12/2013, 11:12 PM   #8
iJumbo
High-roller
 
iJumbo's Avatar
 
Join Date: Sep 2009
Location: HEX 69 74 61 6C 79
Posts: 2,175
Reputation: 136
Default Re: Packed-safe format!

Good
__________________

Need a VPS? Get it here!
Website designer & developer php, html, css, html5, javascript
iJumbo is offline   Reply With Quote
Old 14/12/2013, 11:44 PM   #9
BizzyD
Gangsta
 
BizzyD's Avatar
 
Join Date: Jan 2011
Location: Home
Posts: 879
Reputation: 66
Default Re: Packed-safe format!

Very nice release
__________________
We never fail, we only shine with brilliance. One king one faith one religion. And if you hear me come and join the revolution
BizzyD is offline   Reply With Quote
Old 15/12/2013, 01:36 AM   #10
Emmet_
Guest
 
Posts: n/a
Default Re: Packed-safe format!

Anybody have any ideas on what functions I should make packed-safe? AFAIK, all string.inc functons support packed strings - but there a few SA-MP natives that don't.
  Reply With Quote
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] Packed strings in PAWN Emmet_ Tutorials 16 25/12/2013 10:37 AM
Packed String Support MP2 Scripting Help 3 30/03/2013 08:08 AM
packed string problem KoczkaHUN Help Archive 0 08/08/2011 11:11 AM
Packed strings - speed? RSX Help Archive 0 30/08/2010 02:48 PM
Packed Strings Nekom Help Archive 2 10/03/2010 11:31 AM


All times are GMT. The time now is 04:39 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.