I decided to check this forum after a looooong time of inactivity, Still can't decide if this game is still dead? is it?
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menufunction onPlayerCommand( player, cmd, text )
{
else if ( cmd == "rand" )
{
local RandPlayerID = FindRandPlayer();
print ( "Random PlayerID " + RandPlayerID );
}
}
function FindRandPlayer()
{
local
MAX_PLAYERS = 50,
count = 0,
buffer = "",
param;
for(local i = 0; i < MAX_PLAYERS; i++)
{
if ( FindPlayer( i ) )
{
buffer = buffer + " " + i;
count++;
}
}
param = split(buffer, " ");
return param[ rand() % count ];
}
function onScriptLoad( )
{
// Create/load the database
database <- ConnectSQL( "vcmp.db" );
// Create the table
QuerySQL( database, "CREATE TABLE IF NOT EXISTS money ( nick UNIQUE COLLATE NOCASE, cash INT, bank INT)" );
// Create an array to store the money information for each online player.
MoneySlot <- array( GetMaxPlayers(), null );
print( "=== Loaded SQLite Money Example ===" );
}
// Create a base class
class money {
constructor(player, icash, ibank) {
nick = player;
cash = icash;
bank = ibank;
}
function load(player)
{
// Create a class instance and store the object in our array.
MoneySlot[ player.ID ] = money( player, 0, 0 );
// Check for previously saved data
if ( money.find_plr(player) )
{
local query = ::QuerySQL( database, "SELECT cash, bank FROM money WHERE nick='" + player + "'" );
if ( ::GetSQLColumnData( query, 0 ) != null )
{
// Fetch the asked values from the columns of the returned row into the array index
MoneySlot[ player.ID ].cash = ::GetSQLColumnData( query, 0 );
MoneySlot[ player.ID ].bank = ::GetSQLColumnData( query,1 );
}
// Ask for the next row to finalize the query result
::GetSQLNextRow( query );
}
// sets the player's cash in-game
player.Cash = MoneySlot[ player.ID ].cash;
}
function save(player)
{
// Grab our player data from the array
local
plr = player.Name,
cash = MoneySlot[ player.ID ].cash,
bank = MoneySlot[ player.ID ].bank;
// If player had any data in the database, update the old entry
if ( money.find_plr(player) )
{
// Format the query string using 'format'
local query = format( "UPDATE money SET cash=%i, bank=%i WHERE nick='%s'", cash, bank, plr );
// Then execute the query
::QuerySQL( database, query );
}
// Else let's just make a new entry
else
{
local query = format( "INSERT INTO money (nick, cash, bank) VALUES ('%s', %i, %i)", plr, cash, bank );
::QuerySQL( database, query );
}
// Reset the array slot
MoneySlot[ player.ID ] = null;
}
function SetDisplay(player)
{
// Sets the players in-game money display
player.Cash = MoneySlot[ player.ID ].cash;
}
function formatInteger(number) // by Boylett
{
local string = "";
local newnum = number % 1000;
while(newnum != number)
{
string = format(",%03d", (newnum < 0 ? -newnum : newnum)) + string;
number /= 1000;
newnum = number % 1000;
}
string = newnum.tostring() + string;
return "$" + string;
}
function find_plr(player)
{
local query = ::QuerySQL( database, "SELECT nick FROM money WHERE nick='" + player + "'" );
return ::GetSQLColumnData( query, 0 ) != null ? true : false;
}
nick = null;
cash = null;
bank = null;
}
// Derived class declaration ( A derived class inherits all members and properties of it's base )
class bank extends money {
function deposit(player, amount)
{
// Amend the 'bank' property of our class instance.
MoneySlot[ player.ID ].bank += amount;
// Subtract amount from the 'cash' value.
MoneySlot[ player.ID ].cash -= amount;
// Set players in-game money display.
money.SetDisplay(player);
}
function withdraw(player, amount)
{
// Amend the bank property value
MoneySlot[ player.ID ].bank -= amount;
// Add amount to the 'cash' value.
MoneySlot[ player.ID ].cash += amount;
// Set players in-game money display.
money.SetDisplay(player);
}
function balance(player)
{
return MoneySlot[ player.ID ].bank;
}
}
class cash extends money {
function inc(player, amount)
{
// Amend the cash property of our class instance.
MoneySlot[ player.ID ].cash += amount;
// Set players in-game money display.
money.SetDisplay(player);
}
function dec(player, amount)
{
// Amend the cash propery of our class instance.
MoneySlot[ player.ID ].cash -= amount;
// Set players in-game money display.
money.SetDisplay(player);
}
function get(player)
{
return MoneySlot[ player.ID ].cash;
}
}
/*
------------
EVENTS
------------
*/
function onPlayerChat( player, text )
{
local backupText = text;
local firstChar = backupText.slice( 0, 1 );
if ( firstChar == "!" )
{
// The following function makes any ! commands go to the OnPlayerCommand handler
local splittext = text.slice( 1 );
local params = split( splittext, " " );
if ( params.len() == 1 ) onPlayerCommand( player, params[ 0 ], "" );
else
{
splittext = splittext.slice( splittext.find( " " ) + 1 );
onPlayerCommand( player, params[ 0 ], splittext );
}
}
}
function onPlayerJoin( player )
{
money.load( player ); // add to login function
}
function onPlayerSpawn( player )
{
money.load( player ); // IsLoggedIn check needed
}
function onPlayerPart( player, reason )
{
money.save( player ); // add to logout function
}
function onPlayerCommand( player, command, text )
{
// Identify the player
local
plr = text != "" ? IsNum( text ) ? FindPlayer( text.tointeger() ) : FindPlayer( text ) : player,
arg = split( text, " " );
if ( command == "money" )
{
if ( !plr ) MessagePlayer( "Player " + text + " is not online.", player );
else
{
local cash = cash.get( plr );
local bank = bank.balance( plr );
MessagePlayer( plr.Name + "'s money:" + " Cash: " + money.formatInteger(cash) + ", Bank: " + money.formatInteger(bank), player );
}
}
else if ( command == "deposit" )
{
// var holding parameter 0 as an integer (chat-box holds it as a string)
local iarg = arg.len() > 0 ? IsNum( arg[ 0 ] ) ? arg[ 0 ].tointeger() : arg[ 0 ] : null;
if ( arg.len() == 0 ) MessagePlayer( "no params", player );
else if ( !IsNum( arg[ 0 ] ) ) MessagePlayer( "Invalid Amount!", player );
else if ( iarg > cash.get( player ) ) MessagePlayer( "You cannot deposit more than you have!", player );
else
{
bank.deposit( player, iarg );
MessagePlayer( " You Deposited " + money.formatInteger(iarg), player );
}
}
else if ( command == "withdraw" )
{
// var holding parameter 0 as an integer (chat-box holds it as a string)
local iarg = arg.len() > 0 ? IsNum( arg[ 0 ] ) ? arg[ 0 ].tointeger() : arg[ 0 ] : null;
if ( arg.len() == 0 ) MessagePlayer( "no params", player );
else if ( !IsNum( arg[ 0 ] ) ) MessagePlayer( "Invalid Amount!", player );
else if ( iarg > bank.balance( player ) ) MessagePlayer( "You cannot withdraw more than you have!", player );
else
{
bank.withdraw( player, iarg );
MessagePlayer( " You withdrew " + money.formatInteger(iarg), player );
}
}
else if ( command == "payday" )
{
cash.inc( player, 500000 ); // looking forward to driving that ferrari!!
MessagePlayer( " Pay day arrived, check your cash with !money", player );
}
}
SpreeSlot <- array( 100, null ); // Creates a static 100 size array with all values at null.
class KillingSpree {
constructor(Player, Kills) {
PlayerName = Player;
num_kills = Kills;
}
function find_plr(player)
{
return SpreeSlot[ player.ID ] != null ? true : false;
}
function AnnounceSpree(text)
{
::Message( " **** " + text );
}
function list_players()
{
local tmp = "";
foreach ( obj in SpreeSlot )
{
if ( ( obj != null ) && ( obj.num_kills >= 5 ) )
{
tmp = tmp + obj.PlayerName + " " + obj.num_kills + ", ";
}
}
return tmp != "" ? tmp.slice(0, tmp.len() - 2) : "No Players are on a Killspree";
}
function IsSpree(killer, player, reason)
{
if ( KillingSpree.find_plr(player) ) // Spree Ended
{
// Calculate kills for the victim
local kills = SpreeSlot[ player.ID ].num_kills;
// Filter killed/died reasons
reason = reason < 39 ? "KILLED" : reason;
// Prevent spree ending for Drive-By/Vehicle killings.
if ( ( reason != 39 ) && ( reason != 42 ) )
{
// Empty the SpreeSlot.
SpreeSlot[ player.ID ] = null;
if ( kills >= 5 )
{
// Establish end type
switch ( reason )
{
case "KILLED":
AnnounceSpree( killer + " ended " + player + "'s Killing Spree of " + kills + " kills in a row." );
break;
case 43: AnnounceSpree( player + "'s Killing Spree was ended by drowning themselves" );
break;
default: AnnounceSpree( player + "'s Killing Spree was ended" );
}
}
}
}
if ( ( KillingSpree.find_plr(killer) ) || ( SpreeSlot[ killer.ID ] == null ) )
{
// Calculate kills for the killer
local kills = KillingSpree.find_plr(killer) ? SpreeSlot[ killer.ID ].num_kills + 1 : 1;
// Allocate a killing spree slot for the killer.
SpreeSlot[ killer.ID ] = KillingSpree( killer, kills );
// Establish the killspree mode.
if ( kills == 5 ) AnnounceSpree( killer + " is on a Killing Spree with " + kills + " kills in a row!" );
else if ( kills == 10 ) AnnounceSpree( killer + " is Dangerous! Killing Spree with " + kills + " kills in a row!" );
else if ( kills == 15 ) AnnounceSpree( killer + " is Murderous!! Deadly Killing Spree with " + kills + " kills in a row!" );
else if ( kills == 20 ) AnnounceSpree( killer + " is Psychotic!!! Insane Killing Spree with " + kills + " kills in a row!" );
else if ( kills == 25 ) AnnounceSpree( killer + " is an Assassin!!!! Professional Killing Spree with " + kills + " kills in a row!" );
else if ( ( kills >= 30 ) && ( kills % 5 == 0 ) ) AnnounceSpree( killer + " is UNSTOPPABLE!!!! Untouchable Killing Spree with " + kills + " kills in a row!" );
}
}
PlayerName = null;
num_kills = null;
}
function onPlayerKill( killer, player, reason, bodypart )
{
KillingSpree.IsSpree( killer, player, reason );
}
function onPlayerDeath( player, reason )
{
KillingSpree.IsSpree( null, player, reason );
}
function onPlayerPart( player, reason )
{
// Reset the spree array slot
SpreeSlot[ player.ID ] = null;
}
function onPlayerCommand( player, cmd, text )
{
if ( cmd == "spree" ) Message( " **** " + KillingSpree.list_players() );
}
local backupText = text;
local firstletteris = backupText.slice( 0, 1 ); //slice the text
if ( firstletteris == "!" ) //you can change the ! to anything to make it work it with that
{
local splitthetext = text.slice( 1 ); //now split it
local params = split( splitthetext, " " ); //split it further
if ( params.len() == 1 ) onPlayerCommand( player, params[ 0 ], "" );
else
{ //send it to function OnPlayerCommand
splitthetext = splitthetext.slice( splitthetext.find( " " ) + 1 );
onPlayerCommand( player, params[ 0 ], splitthetext );
return 0;
}
}
else if (cmd == "arrest") {
if( !text ) MessagePlayer("Error - /"+cmd+" Name/id", player );
else {
local plr = text != "" ? IsNum( text ) ? FindPlayer( text.tointeger() ) : FindPlayer( text ) : player;
if( !plr )MessagePlayer("Error - Unknown player", player );
else if ( plr.WantedLevel = 0 ) return MessagePlayer( RED+" This Player is Not Wanted",player );
else if ( DistanceFromPoint( player.Pos.x, player.Pos.y , plr.Pos.x, plr.Pos.y ) < 5 ) { //DistanceFromPoint( float x1, float y1, float x2, float y2 )
plr.Pos = Vector( 392.96, -506.26, 9.39 );
}
else MessagePlayer(""+ plr.Name +" is far away.", player );
}
}
const AdminPassword = "password" //You can edit this password
Now add this after that on the top of your Scriptclass PlayerInfo
{
admin = false;
}
Now add this in function onScriptLoad( )pinfo <- array(GetMaxPlayers(), null);
Now add this in functions.nut ( If you dont have this add this at the last of your script )function PlayerIsAdmin(player)
{
if(pinfo[player.ID].admin == true) return 1;
else return 0;
}
Add this in Function onPlayerJoinpinfo[player.ID] = PlayerInfo();
Add This in function onPlayerCommandelse if (cmd == "admin")
{
if(!text) ClientMessage( "-> Error: [#ffd700]Please type /admin <admin password>", player,255,0,102);
else if ( text != AdminPassword ) ClientMessage( "-> Error: [#ffd700]Invalid PASSWORD.", player,255,0,102);
else { ClientMessage( "-> [#00ffff]Welcome admin :). You are logged as admin server.", player,255,0,102); pinfo[player.ID].admin = true; }
}
Now the commands you want to make admin commands simply add if (!PlayerIsAdmin(player))
Example else if ( cmd == "kick" )
{
if (!PlayerIsAdmin(player)) ClientMessage("-> [#ccff00]You must be an admin to use this command.", player, 255,0,102);
else if ( !text ) ClientMessage("-> Error - Invalid Format.[#ccff00] /kick <player> <reason>", player, 255,0,102);
else
{
if ( i < 2 ) ClientMessage("-> Error - Invalid Format.[#ccff00] /kick <player> <reason>", player, 255,0,102);
else
{
local plrr = GetPlayer( GetTok( text, " ", 1 ) ), reason = GetTok( text, " ", 2, i );
if ( !plrr ) PrivMessage( player,"Error - Invalid Nick/ID.");
else if ( plrr.ID == player.ID ) PrivMessage( player,"Error - You can't /kick yourself.");
else
{
ClientMessageToAll( "-> [#ccff00]Admin " + player + " kicked:[ " + plr + " ] Reason:[ " + reason + " ]" ,255,0,102);
KickPlayer( plrr ); Announce( "Bye bye", plrr, 3 );
}
}
}
}