new str[96];
format(str, sizeof(str), "It is %02d:%02d.", GetDateEx(HOUR), GetDateEx(MINUTE));
public OnGameModeInit()
{
// blah blah blah
ProtectServer();
}
#define ANTI_IP "127.0.0.1"
#define ANTI_MESSAGE "This script is stolen! You do not have the permission to use it."
#define ANTI_MSGREPEAT 1000
/* TheBetaFox' Random Useful Functions Include */
/*------------ Version 0.001a ---------------- */
// ADDONS, NOT VERY NEW FUNCTIONS
// stock SetPlayerMoney(playerid, amount) -- To set a player's money; slightly more convenient than SetPlayerMoney.
// stock TakePlayerMoney(playerid, amount) -- To take money from the player; slightly more convenient than SetPlayerMoney.
// stock GivePlayerScore(playerid, amount) -- To give a player score; slightly more convenient than SetPlayerScore.
// stock TakePlayerScore(playerid, amount) -- To take a player's score slightly more convenient than SetPlayerScore.
// stock ResetPlayerScore(playerid, amount) -- To reset a player's score; more convenient than SetPlayerScore.
// stock GivePlayerHealth(playerid, amount) -- To give health to a player; slightly more convenient than using SetPlayerHealth for this.
// stock TakePlayerHealth(playerid, amount) -- To take health from a player; slightly more convenient than using SetPlayerHealth for this.
// stock ResetPlayerHealth(playerid, amount) -- To reset a player's health; slightly more convenient than SetPlayerHealth.
// stock GivePlayerArmour(playerid, amount) -- To give armour to a player; slightly more convenient than using SetPlayerArmour for this.
// stock TakePlayerArmour(playerid, amount) -- To take armour from a player; slightly more convenient than using SetPlayerArmour for this.
// stock ResetPlayerArmour(playerid, amount) -- To reset a player's armour; slightly more convenient than SetPlayerArmour.
// stock ShowMessageDialog(playerid, caption[], info[]) -- Show a static dialog (messagebox with only one button; ID is 9876, you can change it in the include).
// stock SendClientMessageToRCON(playerid, msg) -- Sends a message to all the RCON admins on a server.
// stock KickAll(admins = 1) -- Kicks all players; if first param (admins) is 0, RCON admins won't be kicked.
// stock BanAll(admins = 1) -- Bans all players; if first param (admins) is 0, RCON admins won't be banned.
// stock FreezeAll(admins = 1) -- Freezes all players; if first param (admins) is 0, RCON admins won't be frozen.
// stock UnfreezeAll(admins = 1) -- Unfreezes all players; if first param (admins) is 0, RCON admins won't be unfrozen.
// stock Freeze(playerid) -- More comfortable than SetPlayerControllable.
// stock Unfreeze(playerid) -- More comfortable than SetPlayerControllable.
// stock GetPlayerNameEx(playerid) -- Returns the player's name directly, much more convenient for string formatting.
// stock GetPlayerIPEx(playerid) -- Returns the player's IP directly, much more convenient for string formatting.
// stock GetDateEx(part) -- Returns part of date/time directly, much more convenient for string formatting.
// -- 0 = second, 1 = minute, 2 = hour, 3 = day, 4 = month, 5 = year.
// stock RestartServer(time) -- Restarts the server after the specified amount of time in milliseconds.
// stock SetPlayerPosToPlayer(playerid, targetid) -- Teleports the player with the ID of playerid to the player with the ID of targetid.
// stock SetPlayerPosEx(playerid, Float:X, Float:Y, Float:Z, Float:A, interior = 0, virtualworld = 0, televehicle = 0, message = 0, telename[] = "") -- Function to make player teleporting much easier. Interior, virtual world, televehicle, message and telename are optional parameters; only use telename if message is enabled.
// ADDONS, NEW FUNCTIONS
// stock ProtectMode() // Protects the gamemode from being used on another server.
// In server.cfg, set 'bind' to your server's IP.
// Remember to also define ANTI_IP (same IP as in bind), ANTI_MESSAGE (the message that will be spammed) and ANTI_MSGREPEAT (how many times will the message be spammed).
// stock SendBotMsg(playerid, botcolor[], botname[], msg[]); // Sends a bot message to yourself.
// stock SendBotMsgToAll(botcolor[], botname[], msg[]); // Sends a bot message to everyone.
#include <a_samp>
#define ANTI_IP "127.0.0.1"
#define ANTI_MESSAGE "This script is stolen! You do not have the permission to use it."
#define ANTI_MSGREPEAT 1000
#define EMB_BLUE "{003DF5}"
#define EMB_RED "{FF0000}"
#define EMB_GREEN "{66FF00}"
#define EMB_WHITE "{FFFFFF}"
#define STATIC_DIALOG 9876
#define SECOND 0
#define MINUTE 1
#define HOUR 2
#define DAY 3
#define MONTH 4
#define YEAR 5
forward OnServerRestart();
stock SetPlayerMoney(playerid, amount) // Function to set a player's amount of money.
{
ResetPlayerMoney(playerid); // Set the player's money to 0
GivePlayerMoney(playerid, amount); // Give a player the amount of money
}
stock TakePlayerMoney(playerid, amount) // Function to take an amount of money from the player.
{
new moneytake = 0; // Declaring variable 'moneytake'.
moneytake -= amount; // Did it like this because, for some reason, the compiler likes spewing out errors otherwise.
GivePlayerMoney(playerid, moneytake); // Give player the amount from above. (or rather, take)
}
stock GivePlayerScore(playerid, amount) // Function to give score to a player.
{
SetPlayerScore(playerid, GetPlayerScore(playerid) + amount); // Sets a player's score to the current amount + the specified amount.
}
stock TakePlayerScore(playerid, amount) // Function to take score from a player.
{
SetPlayerScore(playerid, GetPlayerScore(playerid) - amount); // Sets a player's score to the current amount minus the specified amount.
}
stock ResetPlayerScore(playerid) // Function to reset a player's score.
{
SetPlayerScore(playerid, 0); // Sets the player's score to 0.
}
stock GivePlayerHealth(playerid, amount) // Function to give health to a player.
{
new Float:health; // Declaring the health as a float.
GetPlayerHealth(playerid, Float:health); // Loading the player's current health as a float.
SetPlayerHealth(playerid, Float:health + amount); // Setting the player's health to the current health amount plus the specified amount.
}
stock TakePlayerHealth(playerid, amount) // Function to take health from a player.
{
new Float:health; // Declaring the health as a float.
GetPlayerHealth(playerid, Float:health); // Loading the player's current health as a float.
SetPlayerHealth(playerid, Float:health - amount); // Setting the player's health to the current health amount minus the specified amount.
}
stock ResetPlayerHealth(playerid) // Resets a player's health.
{
SetPlayerHealth(playerid, 0); // Sets the player's health to 0.
}
stock GivePlayerArmour(playerid, amount) // Function to give armour to a player.
{
new Float:armour; // Declaring the armour as a float.
GetPlayerArmour(playerid, Float:armour); // Loading the player's current armour as a float.
SetPlayerArmour(playerid, Float:armour + amount); // Setting the player's armour to the current armour amount plus the specified amount.
}
stock TakePlayerArmour(playerid, amount) // Function to take armour from a player.
{
new Float:armour; // Declaring the armour as a float.
GetPlayerArmour(playerid, Float:armour); // Loading the player's current armour as a float.
SetPlayerArmour(playerid, Float:armour - amount); // Setting the player's armour to the current armour amount minus the specified amount.
}
stock ResetPlayerArmour(playerid) // Resets a player's armour.
{
SetPlayerArmour(playerid, 0); // Sets the player's armour to 0.
}
stock ShowMessageDialog(playerid, caption[], info[]) // Shows a static dialog to the player.
{
ShowPlayerDialog(playerid, STATIC_DIALOG, DIALOG_STYLE_MSGBOX, caption, info, "OK", "");
}
stock SendClientMessageToAdmins(playerid, msg[]) // Sends a clientmessage to all RCON admins.
{
new maxplr = GetMaxPlayers();
for(new i = 0; i < maxplr; i++)
{
if(!IsPlayerConnected(i)) continue;
if(!IsPlayerAdmin(i)) continue;
SendClientMessage(playerid, msg);
}
}
stock GetPlayerNameEx(playerid) // Returns a player's name directly.
{
new pName[MAX_PLAYER_NAME]; // Declaring the name as a string.
GetPlayerName(playerid, pName, MAX_PLAYER_NAME); // Getting the player's name in variable pName, with size MAX_PLAYER_NAME
return pName; // Return the player's name.
}
stock GetPlayerIPEx(playerid) // Returns a player's IP directly.
{
new IP[16]; // Declaring the IP as a string.
GetPlayerIp(playerid, IP, sizeof(IP)); // Getting the player's IP, in variable IP, with size 16
return IP; // Return the player's IP.
}
stock GetDateEx(part) // Return part of a date/time.
{
new second, minute, hour, day, month, year;
getdate(year, month, day);
gettime(hour, minute, second);
switch(part)
{
case SECOND: return second;
case MINUTE: return minute;
case HOUR: return hour;
case DAY: return day;
case MONTH: return month;
case YEAR: return year;
}
}
stock RestartServer(time)
{
SetTimer("OnServerRestart", time, 0);
SendClientMessageToAll(-1, "The server is going to be restarted!");
}
stock SetPlayerPosToPlayer(playerid, targetid) // Sets a player's position to another player's position.
{
new Float:X, Float:Y, Float:Z, Float:A; // Declaring variables
GetPlayerPos(targetid, Float:X, Float:Y, Float:Z); // Getting the target's position
GetPlayerFacingAngle(targetid, Float:A); // Getting the target's facing angle
SetPlayerPos(playerid, Float:X, Float:Y + 2, Float:Z); // Setting the player's position
SetPlayerFacingAngle(playerid, Float:A); // Setting the player's facing angle
}
stock SetPlayerPosEx(playerid, Float:X, Float:Y, Float:Z, Float:A, interior = 0, virtualworld = 0, televehicle = 0, message = 0, telename[] = "") // Awesome teleport function.
{
if(televehicle == 0) // If teleporting with a vehicle is not enabled (default), then:
{
plr_Teleport:
SetPlayerPos(playerid, Float:X, Float:Y, Float:Z); // Set the player's position
SetPlayerFacingAngle(playerid, Float:A); // Set the player's facing angle
SetPlayerInterior(playerid, interior); // Set the player's interior
SetPlayerVirtualWorld(playerid, virtualworld); // Set the player's virtual world
}
else // Otherwise:
{
if(IsPlayerInAnyVehicle(playerid)) // If the player is in a vehicle
{
new vehicleid = GetPlayerVehicleID(playerid); // Get the vehicle id
SetVehiclePos(playerid, Float:X, Float:Y, Float:Z); // Set the vehicle's position
LinkVehicleToInterior(vehicleid, interior); // Link the vehicle to the interior
SetVehicleVirtualWorld(vehicleid, virtualworld); // Link the vehicle to a virtual world
}
else goto plr_Teleport; // Otherwise, go back to plr_Teleport
}
if(message == 1)
{
new msg[96];
format(msg, sizeof(msg), ""EMB_BLUE"SERVER: "EMB_WHITE"%s has teleported to %s!", GetPlayerNameEx(playerid));
}
}
stock KickAll(admins = 1) // Kicks everyone from the server.
{
new maxplr = GetMaxPlayers();
for(new i = 0; i < maxplr; i++)
{
if(!IsPlayerConnected(i)) continue;
if(admins == 0 && !IsPlayerAdmin(i)) continue;
Kick(i);
}
}
stock BanAll(admins = 1) // Bans everyone from the server.
{
new maxplr = GetMaxPlayers();
for(new i = 0; i < maxplr; i++)
{
if(!IsPlayerConnected(i)) continue;
if(admins == 0 && !IsPlayerAdmin(i)) continue;
Ban(i);
}
}
stock FreezeAll(admins = 1) // Freezes everyone on the server.
{
new maxplr = GetMaxPlayers();
for(new i = 0; i < maxplr; i++)
{
if(!IsPlayerConnected(i)) continue;
if(admins == 0 && !IsPlayerAdmin(i)) continue;
TogglePlayerControllable(i, 0);
}
}
stock UnfreezeAll(admins = 1) // Unfreezes everyone on the server.
{
new maxplr = GetMaxPlayers();
for(new i = 0; i < maxplr; i++)
{
if(!IsPlayerConnected(i)) continue;
if(admins == 0 && !IsPlayerAdmin(i)) continue;
TogglePlayerControllable(i, 1);
}
}
stock Freeze(playerid) // Freezes a player.
{
TogglePlayerControllable(playerid, 0);
}
stock Unfreeze(playerid) // Unfreezes a player.
{
TogglePlayerControllable(playerid, 1);
}
stock SendClientMessageToRCON(playerid, msg[]) // Sends a clientmessage to all RCON admins.
{
new maxplr = GetMaxPlayers();
for(new i = 0; i < maxplr; i++)
{
if(!IsPlayerConnected(i)) continue;
if(!IsPlayerAdmin(i)) continue;
SendClientMessage(playerid, msg);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
stock SendBotMsg(playerid, botcolor[], botname[], msg[])
{
new str[196];
format(str, sizeof(str), "%s%s "EMB_BLUE"[BOT]: "EMB_WHITE"%s", botcolor, botname, msg);
SendClientMessage(playerid, -1, str);
}
stock SendBotMsgToAll(botcolor[], botname[], msg[])
{
new str[196];
format(str, sizeof(str), "%s%s "EMB_BLUE"[BOT]: "EMB_WHITE"%s", botcolor, botname, msg);
SendClientMessageToAll(-1, str);
}
stock ProtectMode()
{
new ip[16];
GetServerVarAsString("bind", ip, sizeof(ip));
if (!ip[0] || strcmp(ip, ANTI_IP))
{
for(new i = 0; i < ANTI_MSGREPEAT + 5; i++)
{
printf(ANTI_MESSAGE);
if(i >= ANTI_MSGREPEAT) SendRconCommand("exit");
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public OnServerRestart()
{
GameTextForAll("RESTARTING...", 5000, 0);
SendRconCommand("gmx");
}
You shouldn't have call it "Useless Functions" because forum members (well most of them), will not be interested in checking the thread.
Anyway, good job, keep updating it. |
stock TakePlayerMoney(playerid, amount) // Function to take an amount of money from the player.
{
new moneytake = 0; // Declaring variable 'moneytake'.
moneytake -= amount; // Did it like this because, for some reason, the compiler likes spewing out errors otherwise.
GivePlayerMoney(playerid, moneytake); // Give player the amount from above. (or rather, take)
}
stock TakePlayerMoney(playerid, amount) // Function to take an amount of money from the player.
{
GivePlayerMoney(playerid, -amount); // Give player the amount from above. (or rather, take)
}
I love the function "BanAll"! I am sure I will use it on my server if I gain 200 players!
|