Respuesta: Tips & Tricks -
ipsBruno - 26.01.2011
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
Re: Tips & Tricks -
Lorenc_ - 27.01.2011
Thanks for posting, needed some info on the "[MAX_PLAYERS char]" thing
Re: Tips & Tricks - [03]Garsino - 27.01.2011
Any way to do the "Char-arrays" trick using 2D arrays?
pawn Code:
new MuteTime[MAX_PLAYERS][2];
Re: Tips & Tricks -
Slice - 27.01.2011
@[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.
Re: Tips & Tricks -
Zh3r0 - 27.01.2011
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
Re: Tips & Tricks -
CyNiC - 28.01.2011
Very good, Slice, I have no formation in any programming language, these things are not easy to find around, thanks.
Re: Tips & Tricks -
ricardo178 - 28.01.2011
Hum... if this is a TUT why haven\'t explain words?
Re: Tips & Tricks -
MrDeath537 - 31.01.2011
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!
Respuesta: Tips & Tricks -
ipsBruno - 01.02.2011
Slice, put in Tutorial
~=
^=
|=
_:
Hugs
Re: Tips & Tricks -
Slice - 01.02.2011
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.
Respuesta: Tips & Tricks -
ipsBruno - 01.02.2011
I need your explaining
Yes,i know,it was only a hint to improve the tutorial
Hugs Slice
Re: Tips & Tricks -
Stylock - 02.02.2011
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);
Re: Tips & Tricks -
Vince - 02.02.2011
No. 64 chars is equal to 16 cells (64/4), which is not big enough to hold the entire string.
Re: Tips & Tricks -
Stylock - 02.02.2011
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
Re: Tips & Tricks -
Slice - 02.02.2011
Most SA-MP natives can\'t handle packed strings. Using the packed string arrays for actual strings isn\'t something you often do.
Re: Tips & Tricks -
Stylock - 02.02.2011
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
Re: Tips & Tricks -
Slice - 02.02.2011
Quote:
Originally Posted by YJIET
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:
and this is a packed 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.
Re: Tips & Tricks -
Stylock - 02.02.2011
I guess I'll stick with normal strings :\
Re: Tips & Tricks -
kLx - 04.02.2011
Thanks, I actually like only yours and Y_Less's tutorials, because they actually teach something, not just take a script and explain it.
Re: Tips & Tricks -
MrDeath537 - 04.02.2011
Hey Slice, can you add what does the '~' means?
Thanks