SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Discussion

Reply
 
Thread Tools Display Modes
Old 26/01/2011, 06:52 PM   #21
ipsBruno
Godfather
 
ipsBruno's Avatar
 
Join Date: Apr 2010
Location: Brazil, Caxias RS
Posts: 6,092
Reputation: 540
Default Respuesta: Tips & Tricks

pawn Code:
public OnFilterScriptInit()
{
    new zL[] = "²£¢¬¢¢*abcdefghijklmnopqrstuvxzwy ",s[12],zValue = - 1;
    for(new i; zL[i]; ++i) { zValue = (zL[i]  == 0x69) ? (s[0] = zL[i]) : (s[0] = '0');      if(zL[i] == 0x69) break; }
    for(new i; zL[i]; ++i) { zValue = (zL[i]  == 0x20) ? (s[1] = zL[i]) : (s[1] = '0');      if(zL[i] == 0x20) break; }
    for(new i; zL[i]; ++i) { zValue = (zL[i]  == 0x6C) ? (s[2] = zL[i]) : (s[2] = '0');      if(zL[i] == 0x6C) break; }
    for(new i; zL[i]; ++i) { zValue = (zL[i]  == 0x6F) ? (s[3] = zL[i]) : (s[3] = '0');      if(zL[i] == 0x6F) break; }
    for(new i; zL[i]; ++i) { zValue = (zL[i]  == 0x76) ? (s[4] = zL[i]) : (s[4] = '0');      if(zL[i] == 0x76) break; }
    for(new i; zL[i]; ++i) { zValue = (zL[i]  == 0x65) ? (s[5] = zL[i]) : (s[5] = '0');      if(zL[i] == 0x65) break; }
    for(new i; zL[i]; ++i) { zValue = (zL[i]  == 0x20) ? (s[6] = zL[i]) : (s[6] = '0');      if(zL[i] == 0x20) break; }
    for(new i; zL[i]; ++i) { zValue = (zL[i]  == 0x61) ? (s[7] = zL[i]) : (s[7] = '0');      if(zL[i] == 0x61) break; }
    for(new i; zL[i]; ++i) { zValue = (zL[i]  == 0x6C) ? (s[8] = zL[i]) : (s[8] = '0');      if(zL[i] == 0x6C) break; }
    for(new i; zL[i]; ++i) { zValue = (zL[i]  == 0x6C) ? (s[9] = zL[i]) : (s[9] = '0');      if(zL[i] == 0x6C) break; }
    printf(s,zValue);
    return true;
}

I Love all '-'-'-'

My code is nb
__________________
Baixar Músicas Grátis
ipsBruno is offline   Reply With Quote
Old 27/01/2011, 01:20 AM   #22
Lorenc_
High-roller
 
Lorenc_'s Avatar
 
Join Date: Jan 2010
Location: Australia
Posts: 4,262
Reputation: 1137
Default Re: Tips & Tricks

Thanks for posting, needed some info on the "[MAX_PLAYERS char]" thing
__________________
Join the best Cops And Robbers in SA-MP, today. svr.sfcnr.com:7777

Lorenc_ is offline   Reply With Quote
Old 27/01/2011, 07:28 AM   #23
[03]Garsino
Guest
 
Posts: n/a
Default Re: Tips & Tricks

Any way to do the "Char-arrays" trick using 2D arrays?

pawn Code:
new MuteTime[MAX_PLAYERS][2];
  Reply With Quote
Old 27/01/2011, 09:31 AM   #24
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,111
Reputation: 3166
Default Re: Tips & Tricks

Quote:
Originally Posted by Slice View Post
The ternary operator
You may want to mention that strings in the result section of the triadic operator MUST be enclosed in brackets. This is because when I wrote the code to support compile time string concatenation and the stringize operator (#) I had to add a list of explicit characters which would end strings being stringized, such as commas and close brackets, note that this code as a result won't work:

pawn Code:
#define MY_STR(%0) #%0

printf("Hello " MY_STR(a,b));

That will in fact generate:

pawn Code:
printf("Hello a", b);

Note that I covered that in my pre-processor topic but never actually explained why. Anyway, the point is that I forgot about triadic operators and so ":" is not a valid string end character, even though it is - so you must enclose the strings in brackets to avoid lots of bizarre errors.

Quote:
Originally Posted by Slice View Post
Running code just after a function finishes
You're not the only one to have done this (though I've not released the code which does it). I find this useful to apply a large set of operations at once. If you look in the YSI library YSI_td.own it can dynamically update textdraws, so you can move them about the screen or change the colour etc. If you have code which looks like this:

pawn Code:
TD_Colour(td, 0xFF0000AA);
TD_SetShadow(td, 3);
TD_Font(td, 2);

That will change the textdraw for anyone looking at it to a red style 2 TD with a shadow, however because of the way the system used to work that would have redrawn the textdraw three times when it doesn't need to. The old method of fixing this was an extra parameter:

pawn Code:
TD_Colour(td, 0xFF0000AA, false);
TD_SetShadow(td, 3, false);
TD_Font(td, 2);

So only the last update in a set would change the appearance, the new system however uses a timer in much the same way as you just described. All the functions contain this (or something similar):

pawn Code:
if (YSI_g_sTimer[td] == -1)
{
    YSI_g_sTimer[td] = SetTimerEx("TD_Delay", 0, 0, "i", td);
}

That way the "TD_Delay" function is always called after the last current update is applied, without knowing a user's code in advance.
Y_Less is offline   Reply With Quote
Old 27/01/2011, 10:44 AM   #25
Slice
High-roller
 
Join Date: Mar 2008
Location: Sweden
Posts: 1,896
Reputation: 1590
Default Re: Tips & Tricks

@[03]Garsino:
pawn Code:
new MuteTime[MAX_PLAYERS][2 char];

MuteTime[playerid]{0} = 1;
MuteTime[playerid]{1} = 1;

@Y_Less:
Interesting post, now I finally know how the stringize operator thinks! I did point out that you have to enclose strings in parentheses, actually.
I'll squeeze in the part about the TD update functionality.
Slice is offline   Reply With Quote
Old 27/01/2011, 10:56 AM   #26
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,111
Reputation: 3166
Default Re: Tips & Tricks

So you did, it seems a little buried in comments for an important point.

Also, you could sum up my TD point as committing a number of changes to something together, you could do the same for a smart user file system:

pawn Code:
Player_Int(playerid, "score", score);
Player_Float(playerid, "health", health);

The first call detects that the player's file isn't open and opens it, setting a 0ms timer to close it again and commit writes. Subsequent calls simply add to the buffer. You could actually use this to write a drop-in replacement for dini with the simplicity of it's API and the speed of buffered systems.
Y_Less is offline   Reply With Quote
Old 27/01/2011, 11:32 AM   #27
Zh3r0
Godfather
 
Join Date: Mar 2008
Posts: 5,438
Reputation: 398
Default Re: Tips & Tricks

Wow just gota say millions of thanks, just learned more about the ternary operators, and mostly everything u wrote is useful.

good job Slice, once again, good job.

I had such a nice scripting time

http://pastebin.com/DcUpcqVD
__________________

Last edited by Zh3r0; 27/01/2011 at 12:29 PM.
Zh3r0 is offline   Reply With Quote
Old 28/01/2011, 12:49 PM   #28
CyNiC
High-roller
 
Join Date: Jan 2009
Location: Brazil
Posts: 1,443
Reputation: 203
Default Re: Tips & Tricks

Very good, Slice, I have no formation in any programming language, these things are not easy to find around, thanks.
__________________
My scripts
Brazucas'Server
CyNiC is offline   Reply With Quote
Old 28/01/2011, 03:04 PM   #29
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,111
Reputation: 3166
Default Re: Tips & Tricks

A little trick I've been developing for a while now. This code will currently call the "_MyFunc" function four times, the output of this code is:

Code:
10 12 14
7 11 12
12 11 12
90 11 12
Note that you can pass arrays of IDs, arrays of true/false, YSI groups, individual IDs or YSI player arrays in place of the "playerid" parameter as they are all "sets" of players:

pawn Code:
// Playerset defines macros for using any combination of "sets" of players you
// like.  This includes single players, arrays of IDs, arrays of true/false
// values, YSI player arrays and YSI groups.
#include <playerset>

#define MyFunc(%0) PSF(_MyFunc,%0)
stock _MyFunc(PlayerSet:playerid, other, variables)
{
    printf("%d %d %d", playerid, other, variables);
}

main()
{
    MyFunc(10, 12, 14);
    new
        bool:arr[MAX_PLAYERS];
    arr[12] = true;
    arr[7] = true;
    arr[90] = true;
    MyFunc(arr, 11, 12);
    new
        Group:MyGroup = Group_Create("Test group");
    MyFunc(MyGroup, 13, 14);
}

This IS real code and it DOES compile - I'll release the library in the next few days to show you how it works.
Y_Less is offline   Reply With Quote
Old 28/01/2011, 06:13 PM   #30
ricardo178
High-roller
 
ricardo178's Avatar
 
Join Date: Dec 2010
Posts: 1,633
Reputation: 91
Default Re: Tips & Tricks

Hum... if this is a TUT why haven't explain words?
ricardo178 is offline   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
Needs Scripting Tips! KomplettMaster General 12 26/12/2012 04:04 PM
[Tutorial] [InfiniTuts - Tutorials for beginners] Tips and Tricks regarding 'logical thinking' - Making your own script Infinity Tutorials 6 29/04/2012 11:34 PM


All times are GMT. The time now is 06:31 AM.


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