Tips & Tricks
#21

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
Reply
#22

Thanks for posting, needed some info on the "[MAX_PLAYERS char]" thing
Reply
#23

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

pawn Code:
new MuteTime[MAX_PLAYERS][2];
Reply
#24

@[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.
Reply
#25

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
Reply
#26

Very good, Slice, I have no formation in any programming language, these things are not easy to find around, thanks.
Reply
#27

Hum... if this is a TUT why haven\'t explain words?
Reply
#28

Nice tutorial, most of those things I already knew, but:


- I didn\'t know how to use ternary operator (LOL)

- How to convert integer to boolean using "!!"

- The usage of brackets in char arrays.



Thanks for tutorial!
Reply
#29

Slice, put in Tutorial



~=

^=

|=

_:



Hugs
Reply
#30

DraKiNs, here\'s a tutorial explaining the first 3 operators: An in-depth look at binary and binary operators.


The _: operator removes tags from variables/values.
Reply
#31

I need your explaining


Yes,i know,it was only a hint to improve the tutorial


Hugs Slice
Reply
#32

Wait, I\'m a bit confused about char-arrays.. since one byte can hold values from 0-255 (which means it can hold all characters), does this mean I can replace almost all cell-arrays to char-arrays?


So basically this
pawn Code:
new str[64];
format(str, 64, "%s %d %d", "abcdefghijklmnopqrstuvwxyz", 255, 12345);
can be replaced with this..
pawn Code:
new str[64 char];
format(str, 64, "%s %d %d", "abcdefghijklmnopqrstuvwxyz", 255, 12345);
Reply
#33

No. 64 chars is equal to 16 cells (64/4), which is not big enough to hold the entire string.
Reply
#34

I don\'t get it, I thought each byte can hold one character, just like this:
pawn Code:
new str[6 char];
str{0} = 51; str{1} = 50; str{2} = 49;
str{3} = 97; str{4} = 98; str{5} = 99;
print(str); //prints 321abc
Reply
#35

Most SA-MP natives can\'t handle packed strings. Using the packed string arrays for actual strings isn\'t something you often do.
Reply
#36

Ok, you lost me after packed strings part.. anyway, can the code below cause any side effects?
pawn Code:
new
    gPlayerName[MAX_PLAYERS][MAX_PLAYER_NAME char];

//OnPlayerConnect
GetPlayerName(playerid, gPlayerName[playerid], MAX_PLAYER_NAME);
format(str, 64, "%s has joined the server.", gPlayerName[playerid]);
It seems to work great
Reply
#37

Quote:
Originally Posted by YJIET
View Post
Ok, you lost me after packed strings part.. anyway, can the code below cause any side effects?
pawn Code:
new
    gPlayerName[MAX_PLAYERS][MAX_PLAYER_NAME char];

//OnPlayerConnect
GetPlayerName(playerid, gPlayerName[playerid], MAX_PLAYER_NAME);
format(str, 64, "%s has joined the server.", gPlayerName[playerid]);
It seems to work great
First off, this is a normal string:
pawn Code:
"string"
and this is a packed string:
pawn Code:
!"string"


To deal with packed strings, you need functions that can deal with them aswell. format, print, printf, SendClientMessage, .. does NOT work with packed strings.

gPlayerName[MAX_PLAYERS][MAX_PLAYER_NAME char]

this will make the string 4 times smaller - try connecting with a nick like hellohellohelloh and see how far that gets you.


Also, LIKE I SAID, don\'t use packed strings for actual strings. In your case, just don\'t use them - you will find yourself having loads of weird bugs and such.
Reply
#38

I guess I'll stick with normal strings :\
Reply
#39

Thanks, I actually like only yours and Y_Less's tutorials, because they actually teach something, not just take a script and explain it.
Reply
#40

Hey Slice, can you add what does the '~' means?

Thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)