01.08.2015, 08:06
Hello, there i will tell you some things you can use in your scripts !
For the beginning of that tutorial i will show you something very easy :
That need to be below #includes
You can use that like this , there we have a code :
You can make the same thing with what command you want (just use #define SHORTCUT COMMAND)
__________________________________________________ _____________________________________________
Next thing i want to learn you it's , how to save your space ..
1. Multi-Dimensional Strings (arrays) - There you can save your space using like that:
What we do there ? We created a 2 Dimensional string instead of "new String[128], String2[128];"
2.Colors - eh , that it's not too hard (that's more for the structure of FilterScript) - In PAWN colors are on the form of:
There exist another colors too for Game Texts:
3. Global Strings - You can use a global string if you use just a single string type in many cases !
It will reset the content every time you use it , and you can use it again , and again .
- 4. Stocks - Use stocks for few functions if you use it many times , like that:
It will show message like that:
SweeT was killed by Wiper !
We made our work easiest with that stock . Instead create 2 strings ("new pName[MAX_PLAYER_NAME], kName[MAX_PLAYER_NAME]") and write again "GetPlayerName(playerid, pName, sizeof(pName));" and too for kName , we just written one time and used stock many times ... Another good stock may be that:
That stock it's used to send message to a player (instead SendClientMessage) with many parameters ... Like a format .. Instead using every time
we will use
Another usefull stock
That stock will show player money (where you use that) with "." between 3 numbers , like that :
I have $30000 , if i use that stock like that :
There when player spawns , will appear a message like that:
You have $30.000 !
Remember : There the number (integer - %i | %d) change in a string , because "."
- 5. Loops
You want to add some classes to your script and you're bored of adding 300 lines ? Do that like that:
You can use loops and in other ways .. Another exemple it's that:
Format Specifiers :
Source - SA:MP wiki , to be used in text formats
- 6. Includes
I advise you to use easiest includes at the beginning . There it's a list with good includes for newbies in PAWN scripting:
easyDialogs.inc - Click There
ZCMD ~ Zeex command processor - Click There
Improved ZCMD by Yashas (Zeex Command Processor improved) - Click There
YSI libraries by Alex "******" Cole - Click There
Sscanf by Alex "******" Cole - Click There
foreach by Alex "******" Cole - Click There
YSY libraries are not so easy , but are very good includes , and you will need to learn it sometime (or go directly to MYSQL) , because there it's an y_ini.inc that it's a faster file writer ..
- 7. Final - I hope you learned something from that tutorial - more on SA:MP WIKI
For the beginning of that tutorial i will show you something very easy :
Code:
#define SCM SendClientMessage // You can use now SCM instead of SendClientMessage #define SPD ShowPlayerDialog // You can use SPD now instead of ShowPlayerDialog
You can use that like this , there we have a code :
HTML Code:
// Before SendClientMessage(playerid, 0xFFFFFFFF, "Hello world , there it's a dude !"); // Send to player a message // After you can type like that (more easy) SCM(playerid, 0xFFFFFFFF, "Hello world, there it's a dude !"); // Send to player the same message
__________________________________________________ _____________________________________________
Next thing i want to learn you it's , how to save your space ..
1. Multi-Dimensional Strings (arrays) - There you can save your space using like that:
HTML Code:
new String[2][128]; format(String[0], sizeof(String), "Message"); // format the string | sizeof(string) mean the cell size = 128 in our case format(String[1], sizeof(String), "Message2") // format another dimension of our string SCM(playerid, -1, String[0]); // Show player the content of String[0] ("Message") SCM(playerid, -1, String[1]); // Show player the content of String[1] ("Message2")
2.Colors - eh , that it's not too hard (that's more for the structure of FilterScript) - In PAWN colors are on the form of:
- A chat text or player color looks like this: 0xRRGGBBAA.
- If you want to change colors in a strings , you will need to use HEX colors - Only RRGGBB
Code:
#include <a_samp> #define RED 0xFF0000FF // There FF it's the maximum of RED (From AA to FF or numbers from 00 to 99) - 0000 are green and blue and FF again represents Alpha (00 it's invisible) #define BLUE "0000FF" // There it's blue - You need to write it in "" because it's used in a string (For multi color texts) -- You can write it like that too - #define BLUE "{0000FF}" // On a public or somewhere you can use it SetPlayerColor(playerid, RED); // Put the player color to RED (On radar the player will have color red - in Score Tab too) // But you can use it like that SCM(playerid, 0xFF0000FF, "That message it's red !"); // You can put too 'RED' instead of 0xFF0000FF SCM(playerid, RED, "That message it's red defined !"); // There used RED SCM(playerid, RED, "There it's red {"BLUE"} and there it's blue !"); // There the message will print RED util where in text appear {"BLUE"} , there the text color will change to BLUE SCM(playerid, -1, "That it's white , "BLUE" there it's blue !"); // What ? What color it's -1 ? -1 mean white - you can write -1 instead of 0xFFFFFF | Why i used "BLUE" with out { } ? You can use "BLUE" without brackets if you defined it like that "{0000FF}" SCMF(playerid, -1, "The last message {0000FF} there it's blue !"); // {0000FF} mean "BLUE", ("BLUE" mean that HEX code , anyway..) , you can use it like that too !
Code:
~r~ red // Source SA:MP wiki ~g~ green // Source SA:MP wiki ~b~ blue // Source SA:MP wiki ~w~ white // Source SA:MP wiki ~y~ yellow // Source SA:MP wiki ~p~ purple // Source SA:MP wiki ~l~ black // Source SA:MP wiki ~h~ lighter color // Source SA:MP wiki
HTML Code:
#include <a_samp>
new gString[256];
public OnPlayerSpawn(playerid)
{
format(gString, sizeof(gString), "You have spawned !");
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
format(gString, sizeof(gString), "You was killed !");
return 1;
}
- 4. Stocks - Use stocks for few functions if you use it many times , like that:
Code:
stock GetName(playerid) { new pName[MAX_PLAYER_NAME]; // MAX_PLAYER_NAME = 24 and our string cell size GetPlayerName(playerid, pName, sizeof(String)); // Get the player name and stock it on pName return pName; // return successfully } // Use public OnPlayerDeath(playerid, killerid, reason) { new String[128]; // Create the string format(String, sizeof(String), "%s was killed by %s !", GetName(playerid), GetName(killerid)); // format our string SendClientMessageToAll(-1, String); // Show message to all return 1; }
SweeT was killed by Wiper !
We made our work easiest with that stock . Instead create 2 strings ("new pName[MAX_PLAYER_NAME], kName[MAX_PLAYER_NAME]") and write again "GetPlayerName(playerid, pName, sizeof(pName));" and too for kName , we just written one time and used stock many times ... Another good stock may be that:
HTML Code:
#include <YSI\y_va> stock SendMessage(playerid, Color, Format[], va_args<>) // You will need y_va include { new String[148]; va_format(String, sizeof(String), Format, va_start<3>); SendClientMessage(playerid, Color, String); return 1; }
HTML Code:
new String[string size]; format(String, sizeof(String), "Your id it's %i !", playerid); SendClientMessage(playerid, -1, String);
HTML Code:
SendMessage(playerid, -1, "Your id it's %i !", playerid); // just it
HTML Code:
stock FormatMoney(Number) // Show player money with "." between 3 numbers
{
new str[16];
format(str, 16, "$%i", Number);
new l = strlen(str);
if(Number < 0)
{
if (l > 5) strins(str, ".", l-3);
if (l > 8) strins(str, ".", l-6);
if (l > 11) strins(str, ".", l-9);
}
else
{
if (l > 4) strins(str, ".", l-3);
if (l > 7) strins(str, ".", l-6);
if (l > 10) strins(str, ".", l-9);
}
return str;
}
I have $30000 , if i use that stock like that :
HTML Code:
public OnPlayerSpawn(playerid) { SendMessage(playerid, -1, "You have {008000}%s{FFFFFF} !", FormatMoney(GetPlayerMoney(playerid))); return 1; }
You have $30.000 !
Remember : There the number (integer - %i | %d) change in a string , because "."
- 5. Loops
You want to add some classes to your script and you're bored of adding 300 lines ? Do that like that:
HTML Code:
public OnFilterScriptInit( ) { for(new i=0; i<300; i++) // That will loop i from 0 to 299 ( before it's just < not and = ) { AddPlayerClass(i, ....); // There will a classes from 0 to 299 } // So we have added 299 classes in 4 lines . return 1; }
Code:
// somewhere new count=0; for(new i=0; i<=GetPlayerPoolSize( ); i++) { if(IsPlayerConnected(i)) { IsPlayerAdmin(i)) count++; } } SendMessage(playerid, -1, "There are %i admins online !", count);
HTML Code:
Specifier Meaning ____________________________ %i Integer (whole number) %d Integer (whole number). %s String %f Floating-point number (Float: tag) %c ASCII character %x Hexadecimal number %b Binary number %% Literal '%' %q Escape a text for SQLite. (Added in 0.3.7 R2)
- 6. Includes
I advise you to use easiest includes at the beginning . There it's a list with good includes for newbies in PAWN scripting:
easyDialogs.inc - Click There
ZCMD ~ Zeex command processor - Click There
Improved ZCMD by Yashas (Zeex Command Processor improved) - Click There
YSI libraries by Alex "******" Cole - Click There
Sscanf by Alex "******" Cole - Click There
foreach by Alex "******" Cole - Click There
YSY libraries are not so easy , but are very good includes , and you will need to learn it sometime (or go directly to MYSQL) , because there it's an y_ini.inc that it's a faster file writer ..
- 7. Final - I hope you learned something from that tutorial - more on SA:MP WIKI