PDA

View Full Version : [Filterscript] AFK System



k@lu^
20-04-2013, 18:57
-Opis:
Jednostavan AFK system. Kada ste AFK kucate /afk a kada se vracate u igru kucate /back.

-Komande:
/afk - Kada niste tu
/back - Kada ste se vratili

PHP CODE:

/*
F-AFK System by iFear
*/

#include <a_samp>
#include <YSI\y_commands>

#define RED 0xFF0000FF
#define GREEN 0x33FF33AA
#define BLUE 0x0000FFFF
#define ORANGE 0xFF8000FF

#if !defined INFINITY
#define INFINITY (Float:0x7F800000)
#endif

// Creates new variables

new
bool: g_AFK[MAX_PLAYERS],
Float: g_fHealth[MAX_PLAYERS];

// Main script

public OnFilterScriptInit()
{
print("\n**************************************");
print("********F-AFK System by iFear*********");
print("**************************************\n");
return 1;
}

public OnPlayerConnect(playerid)
{
g_AFK[playerid] = false; // Set g_AFK to false.
return true;
}

public OnPlayerText(playerid, text[])
{
if (g_AFK[playerid]) // The player is AFK and tried to chat!
return SendClientMessage(playerid, RED, "You are AFK! You cannot talk."),
0; // Sends a message and return 0, therefore the text will not be send.

return true;
}

YCMD:afk(playerid, params[], help)
{
if (g_AFK[playerid]) // The player is already AFK.
return SendClientMessage(playerid, RED, "You are AFK. Use /back if you're back.");

if (IsPlayerInAnyVehicle(playerid)) // The player is in a vehicle
{
new iVeh = GetPlayerVehicleID(playerid); // Get's the player's vehicle ID
GetVehicleHealth(iVeh, g_fHealth[playerid]); // Get's the current vehicle health
SetVehicleHealth(iVeh, INFINITY); // Set the vehicle's health to INFINITY
}

else // The player is on foot.
{
GetPlayerHealth(playerid, g_fHealth[playerid]); // Get's the player's current health
SetPlayerHealth(playerid, INFINITY); // Set the player's health to INFINITY
}

g_AFK[playerid] = true; // The player is now AFK.
TogglePlayerControllable(playerid, false); // Freeze the player so they can't move.

new name[MAX_PLAYER_NAME], str[128];
GetPlayerName(playerid, name, MAX_PLAYER_NAME); // Get's the player name
format(str, sizeof str, "%s is now AFK!", name); // Format the string

// Send client messages.
SendClientMessage(playerid, -1, "You are now AFK. Use /back if you are back!");
SendClientMessageToAll(GREEN, str);

return true;
}

YCMD:back(playerid, params[], help)
{
if (!g_AFK[playerid]) // The player is not AFK
return SendClientMessage(playerid, RED, "You are not AFK!");

if (IsPlayerInAnyVehicle(playerid)) // The player is in a vehicle
{
new iVeh = GetPlayerVehicleID(playerid); // Get's the player's vehicle ID
SetVehicleHealth(iVeh, g_fHealth[playerid]); // Set the vehicle's health to the vehicle's old health
}

else // The player is on foot.
{
SetPlayerHealth(playerid, g_fHealth[playerid]); // Set the player's health to the player's old health
}

g_AFK[playerid] = false; // The player is now not AFK.
TogglePlayerControllable(playerid, true); // The player can now move again.

new name[MAX_PLAYER_NAME], str[128];
GetPlayerName(playerid, name, MAX_PLAYER_NAME); // Get's the player name
format(str, sizeof str, "%s is back from AFK!", name); // Format the string

// Send client messages.
SendClientMessage(playerid, -1, "Welcome back!");
SendClientMessageToAll(GREEN, str);

return true;
}

Credits: iFear