22.10.2013, 18:57
"Content"
- Introduction
- A "chat" about the script
- Tutorial itself
It will contain:
zCMD, how to #include etc.
Color defines.
Script itself.
- Full code
"Introduction"
So, today i will hopefully teach you how to create a pretty "advanced"( i guess ) /afk and /back system.
"The Chat"
Basically this /afk | /back script is like any other i guess, but people won't be able to spam /afk 2x or /back 2x.
"The Tutorial (0/3)"
"Finally", right?
Alright, first of all, you will need to get zCMD.
// https://sampforum.blast.hk/showthread.php?tid=91354 \\
That's the only Include you will need for this tutorial.
"#include <zcmd> (1/3) [Super basic]"
Alright, now that you've downloaded the zcmd.ini file, you will need to do the following:
1) Open your "Pawno"(Or how-ever you named the folder, where you have your pawno.exe, gamemode folder etc.
2) Inside of that, you will have "Pawno", open it, open "include" and drag your zcmd.ini file there.
3) Open up your pawno.exe, and open your gamemode.
Then type
This is how it looks for me.
well, i have other includes too..
Alright, next thing.
"color #define (2/3) [Super basic]"So, today i will hopefully teach you how to create a pretty "advanced"( i guess ) /afk and /back system.
"The Chat"
Basically this /afk | /back script is like any other i guess, but people won't be able to spam /afk 2x or /back 2x.
"The Tutorial (0/3)"
"Finally", right?
Alright, first of all, you will need to get zCMD.
// https://sampforum.blast.hk/showthread.php?tid=91354 \\
That's the only Include you will need for this tutorial.
"#include <zcmd> (1/3) [Super basic]"
Alright, now that you've downloaded the zcmd.ini file, you will need to do the following:
1) Open your "Pawno"(Or how-ever you named the folder, where you have your pawno.exe, gamemode folder etc.
2) Inside of that, you will have "Pawno", open it, open "include" and drag your zcmd.ini file there.
3) Open up your pawno.exe, and open your gamemode.
Then type
pawn Code:
#include <zcmd>
pawn Code:
#include <a_samp>
#include <zcmd>
Alright, next thing.
You will need these color defines, for this script.
COLOR_GREEN 0x33AA33AA
COLOR_ORANGE 0xFF9900AA
To define them, simply add this under your #include(s)
pawn Code:
#define COLOR_GREEN 0x33AA33AA
#define COLOR_ORANGE 0xFF9900AA
pawn Code:
#include <a_samp>
#include <zcmd>
#define COLOR_GREEN 0x33AA33AA
#define COLOR_ORANGE 0xFF9900AA
"The commands" (3/3) [?]"
Alright, now we will start scripting..
"/afk(3/3) [?]"
First of all, you will need to add this under your #include(s) and under your #define(s)
pawn Code:
new
afk[ MAX_PLAYERS char ]
;
Alright, now that you have zCMD, you can't script in the "OnPlayerCommandText" callback.
Go to your scripts bottom, and paste/type this.
pawn Code:
CMD:afk(playerid, params[]) {
When the player types "/afk" it will start triggering the command.
pawn Code:
new name[MAX_PLAYER_NAME], string[128];
GetPlayerName(playerid, name, sizeof(name));
if( afk{ playerid } ) SendClientMessage(playerid, COLOR_ORANGE, "[AFK] - You're already afk!");
pawn Code:
if( afk{ playerid } ) SendClientMessage(playerid, COLOR_ORANGE, "[AFK] - You're already afk!");
This should avoid some spam.
But it won't avoid /back and /afk spam..
pawn Code:
else
{
afk{ playerid } = true;
...
...
If the player isn't AFK already, it will set his afk char to true.
pawn Code:
SetPlayerHealth(playerid, 99999);
SetPlayerArmour(playerid, 99999);
TogglePlayerControllable(playerid, 0);
(You can also use OnPlayerUpdate for this..)
pawn Code:
TogglePlayerControllable(playerid, 0);
pawn Code:
format(string, sizeof(string), "[AFK] - %s is now afk!", name);
SendClientMessageToAll(COLOR_ORANGE, string);
SendClientMessage(playerid, COLOR_ORANGE, "[AFK] - When you come back, use /back!");
Without the format(string, you wouldn't be able to use %s.
And without %s, you would need to use "SendClientMessageToAll(COLOR_ORANGE, "Somebody went afk!");", which wouldn't be so nice.
The last "SendClientMessage" will tell the player, how to get back from the afk "position".
"/afk full-script(3/3) [?]"
pawn Code:
CMD:afk(playerid, params[]) {
new name[MAX_PLAYER_NAME], string[128];
GetPlayerName(playerid, name, sizeof(name));
if( afk{ playerid } ) SendClientMessage(playerid, COLOR_ORANGE, "[AFK] - You're already afk!");
else
{
afk{ playerid } = true;
SetPlayerHealth(playerid, 99999);
SetPlayerArmour(playerid, 99999);
TogglePlayerControllable(playerid, 0);
format(string, sizeof(string), "[AFK] - %s is now afk!", name);
SendClientMessageToAll(COLOR_ORANGE, string);
SendClientMessage(playerid, COLOR_ORANGE, "[AFK] - When you come back, use /back!");
}
return 1;
}
Now we will start working on the /back command.
pawn Code:
CMD:back(playerid, params[]) {
if( !afk{ playerid } ) SendClientMessage(playerid, COLOR_ORANGE, "[BACK] - You aren't afk!");
If the player is NOT afk, he will receive the mesasge "[BACK] - You aren't afk!"
pawn Code:
else
{
new name[MAX_PLAYER_NAME], string[128];
GetPlayerName(playerid, name, sizeof(name));
Again, will get the players name for a format (SendClientMessageToAll)
pawn Code:
SetPlayerHealth(playerid, 99);
SetPlayerArmour(playerid, 99);
TogglePlayerControllable(playerid, 1);
pawn Code:
TogglePlayerControllable(playerid, 1);
pawn Code:
format(string, sizeof(string), "[BACK] - %s is now back!", name);
SendClientMessageToAll(COLOR_GREEN, string);
SendClientMessage(playerid, COLOR_GREEN, "[BACK] - Welcome back!");
afk{ playerid } = false;
pawn Code:
format(string, sizeof(string), "[BACK] - %s is now back!", name);
Again, this is needed for the %s.
pawn Code:
SendClientMessageToAll(COLOR_GREEN, string);
pawn Code:
SendClientMessage(playerid, COLOR_GREEN, "[BACK] - Welcome back!");
pawn Code:
afk{ playerid } = false;
It will say "You aren't afk!"
pawn Code:
if( !afk{ playerid } ) SendClientMessage(playerid, COLOR_ORANGE, "[BACK] - You aren't afk!");
pawn Code:
afk{ playerid } = false;
"/back full-script(3/3) [?]"
pawn Code:
CMD:back(playerid, params[]) {
if( !afk{ playerid } ) SendClientMessage(playerid, COLOR_ORANGE, "[BACK] - You aren't afk!");
else
{
new name[MAX_PLAYER_NAME], string[128];
GetPlayerName(playerid, name, sizeof(name));
SetPlayerHealth(playerid, 99);
SetPlayerArmour(playerid, 99);
TogglePlayerControllable(playerid, 1);
format(string, sizeof(string), "[BACK] - %s is now back!", name);
SendClientMessageToAll(COLOR_GREEN, string);
SendClientMessage(playerid, COLOR_GREEN, "[BACK] - Welcome back!");
afk{ playerid } = false;
}
return 1;
}