This is actually easier than hard maths to Zero :x
If you are new to scripting, then this tutorial is good for you.
SA-MP uses PAWN programming language.
In scripting, usually we do logic and maths.
Take a look at this code below :
new
var;
var = 5;
Which is really understandable.
Create a variable called "var" and set it to '5'.
Now, let's add something to it
new
var;
var = 5;
if (var == 5)
{
var = 7;
}
Again, it's very understandable.
If var is 5, then set it to 7.
Easy, isn't it?
Now :
if (var != 5 )
{
var = 5;
}
'!' means NO or "== 0"
So it means if var IS NOT 5, it set's var to 5.
if (var < 5 ) var = 5; // Var is less than 5
if (var > 5 ) var = 5; // Var is greater than 5
'>' and '<' operator also works here.
Now, let's do basic maths
new var = 0;
var = (var + 5);
// Add var by 5
var += 5;
// Add var by 5, which is the same thing as above.
var *= 5;
// Multiply var by 5;
new i = (var * 5);
// Make a variable called 'i' and set's the value as "var * 5".
Now for strings :
new
hi[6] = "Hello";
If you ask, why 6? There's only 5 characters!
'H' 'e' 'l' 'l' 'o' '\0'
'H' = 0
'e' = 1
'l' = 2
'l' = 3
'o' = 4
'\0' = 5 (null)
Which is 6 characters, not 5 (as we count from 0 in PAWN)
And
new
hi[1] = "Hello";
Will give an error, because Hello should have more array size, not 1.
Now, how do you compare strings at PAWN?
You don't use :
if (string1 == string2)
To compare strings.
Instead, we use strcmp to compare strings at PAWN :
if (strcmp(string1, string2, true) == 0)
strcmp returns '0' if the string matches.
"true" means it's not case sensitive.
About case-sensitive I mean :
new str1[] = "HELLO";
new str2[] = "Hello";
if (strcmp(string1, string2, true) == 0)
// String matches, because it's not case sensitive.
// But
if (strcmp(string1, string2, false) == 0)
// String will not match, because it's case sensitive.
To be continued