Hello guys my first post and my first snippet!
//* Add this on pickuppickedup *//
function onPickupPickedUp( player, pickup )
{
pickup.RespawnTime = 2;
if ( pickup.Model == 407 )
{
local q = QuerySQL( db, "SELECT * FROM Props WHERE rowid='" + pickup.ID + "'" );
if ( q )
{
ePrivMessage( "===> " + GetSQLColumnData( q, 0 ) + " <===", player );
ePrivMessage( "ID:[ " + pickup.ID + " ] Cost:[ $" + GetSQLColumnData( q, 1 ) + " ] Owner:[ " + GetSQLColumnData( q, 2 ) + " ] Share:[ " + GetSQLColumnData( q, 3 ) + " ]", player );
ePrivMessage( "Forsale:[ " + CheckForsale( pickup.ID ) + " ]", player );
}
}
}
//* Connects the database *//
db <- ConnectSQL( "Files/DataBase.db" );
/* Add this on function createtables*/
function CreateTables()
{
QuerySQL( db, "CREATE TABLE IF NOT EXISTS Props ( ID NUMERIC, Name VARCHAR(32), Cost VARCHAR(25), Owner TEXT, Shared TEXT, Pos VARCHAR(25) )" );
}
/* Functions of Props */
function LoadProps()
{
try{
if ( CountProps() != 0 )
{
local q = QuerySQL( db, "SELECT * FROM Props WHERE rowid LIKE '%'" ), pos;
while( GetSQLColumnData( q, 0 ) )
{
local coords = GetSQLColumnData( q, 4 );
local pos = split( coords, " " );
local x = pos[0], y = pos[1], z = pos[2];
CreatePickup( 407, Vector( x.tofloat(), y.tofloat(), z.tofloat() ) );
GetSQLNextRow( q );
}
FreeSQLQuery(q);
}
}
catch(e) print( "function LoadProps() error: " + e );
}
function CountProps()
{
local a = 0, q = QuerySQL( db, "SELECT * FROM Props" );
while ( GetSQLColumnData( q, 0 ) )
{
a ++;
GetSQLNextRow( q );
}
return a;
FreeSQLQuery( q );
}
//This Function is used to Return "yes" or "No" for the Prop Info like: ** pm >> Forsale:[ No ]...
function CheckForsale( id )
{
local q = QuerySQL( db, "SELECT * FROM Props WHERE rowid='" + id + "'" );
local owner = GetSQLColumnData( q, 2 );
if ( owner == "Vice-City" ) return "Yes";
else return "No";
}
//This one is to check if a prop is for sale or not...
function IsPropForSale( id )
{
local q = QuerySQL( db, "SELECT Owner FROM Props WHERE rowid='" + id + "'" );
local owner = GetSQLColumnData( q, 2 );
if ( owner == "Vice-City" ) return 1;
else return 0;
}
function IsPropShared( id )
{
local q = QuerySQL( db, "SELECT Owner FROM Props WHERE rowid='" + id + "'" );
local share = GetSQLColumnData( q, 3 );
if ( share == "None" ) return 0;
else return 1;
}
//Some Functions below are just used in /myprops. They aren't used more then 1 time to avoid to many Queries..
function GetPropOwner( id )
{
local get = GetSQLColumnData( QuerySQL( db, "SELECT Owner FROM Props WHERE rowid='" + id + "'" ), 0 );
if ( get ) return get;
else return 0;
}
function GetPropName( id )
{
local get = GetSQLColumnData( QuerySQL( db, "SELECT Name FROM Props WHERE rowid='" + id + "'" ), 0 );
if ( get ) return get;
else return 0;
}
function GetPropShare( id )
{
local get = GetSQLColumnData( QuerySQL( db, "SELECT Shared FROM Props WHERE rowid='" + id + "'" ), 0 );
if ( get ) return get;
else return 0;
}
function GetPropCost( id )
{
local get = GetSQLColumnData( QuerySQL( db, "SELECT Cost FROM Props WHERE rowid='" + id + "'" ), 0 );
if ( get ) return get;
else return 0;
}
function GetPropPos( id )
{
local get = GetSQLColumnData( QuerySQL( db, "SELECT Pos FROM Props WHERE rowid='" + id + "'" ), 0 );
if ( get ) return get;
else return 0;
}
function PropExists( id )
{
if ( id <= CountProps() ) return 1;
else return 0;
}
function IsPropOwnerOrSharer( id, player )
{
local q = QuerySQL( db, "SELECT * FROM Props WHERE rowid='" + id + "'" );
local owner = GetSQLColumnData( q, 2 ), shared = GetSQLColumnData( q, 3 );
if ( ( owner == player.Name ) || ( shared == player.Name ) ) return 1;
else return 0;
}
/* Now commands */
else if ( cmd == "buyprop" )
{
local q = QuerySQL( db, "SELECT * FROM Props WHERE rowid LIKE '" + text + "'" );
local id = player.ID
if ( !status[ id ].IsReg ) ePrivMessage( "[Error] - You're Not Registered..", player );
else if ( !status[ id ].IsLogged ) ePrivMessage( "[Error] - You're Not logged in..", player );
else if ( !player.IsSpawned ) ePrivMessage( "[Error] - You haven't spawned yet..", player );
else if ( !text ) ePrivMessage( "[Syntax] - !" + cmd + " <ID>", player );
else if ( !IsNum( text ) ) ePrivMessage( "[Error] - ID must be Number..", player );
else if ( !PropExists( GetTok( text, " ", 1 ).tointeger() ) ) ePrivMessage( "[Error] - Invalid Prop ID", player );
else if ( player.Cash < GetSQLColumnData( q, 1 ).tointeger() ) ePrivMessage( "[Error] - You need " + GetSQLColumnData( q, 1 ) + " to Buy this Property!", player );
else if ( GetPropOwner( text ) != "Vice-City" ) ePrivMessage( "[Error] - The Prop is not for sale!", player );
else
{
DecCash( player, GetSQLColumnData( q, 1 ).tointeger() );
QuerySQL( db, "UPDATE Props SET Owner='" + player.Name + "' WHERE rowid = '" + text + "'" );
rMessage( "** " + player.Name + " Bought Property:[ " + GetSQLColumnData( q, 1 ) + " ] ID:[ " + text + " ]" );
Announce( "~h~Property Purchased!", player, 0 );
}
}
else if ( cmd == "gotoprop" )
{
local q = QuerySQL( db, "SELECT * FROM Props WHERE rowid LIKE '" + text + "'" );
local id = player.ID
if ( !status[ id ].IsReg ) ePrivMessage( "[Error] - You're Not Registered..", player );
else if ( !status[ id ].IsLogged ) ePrivMessage( "[Error] - You're Not logged in..", player );
else if ( !player.IsSpawned ) ePrivMessage( "[Error] - You haven't spawned yet..", player );
else if ( !text ) ePrivMessage( "[Syntax] - !" + cmd + " <ID>", player );
else if ( !IsNum( text ) ) ePrivMessage( "[Error] - ID must be Number..", player );
else if ( !PropExists( GetTok( text, " ", 1 ).tointeger() ) ) ePrivMessage( "[Error] - Invalid Prop ID", player );
else if ( !IsPropOwnerOrSharer( text, player ) ) ePrivMessage( "[Error] - You do not own this property..", player );
else
{
local splitPos = split( GetSQLColumnData( q, 4 ), " " );
local x = splitPos[0], y = splitPos[1], z = splitPos[2];
player.Pos = Vector( x.tofloat(), y.tofloat(), z.tofloat() );
ePrivMessage( "Teleported to you Property:[ " + GetSQLColumnData( q, 0 ) + " ]", player );
}
}
else if ( cmd == "sellprop" )
{
local q = QuerySQL( db, "SELECT * FROM Props WHERE rowid LIKE '" + text + "'" );
local id = player.ID
if ( !status[ id ].IsReg ) ePrivMessage( "[Error] - You're Not Registered..", player );
else if ( !status[ id ].IsLogged ) ePrivMessage( "[Error] - You're Not logged in..", player );
else if ( !player.IsSpawned ) ePrivMessage( "[Error] - You haven't spawned yet..", player );
else if ( !text ) ePrivMessage( "[Syntax] - !" + cmd + " <ID>", player );
else if ( !IsNum( text ) ) ePrivMessage( "[Error] - ID must be Number..", player );
else if ( !PropExists( GetTok( text, " ", 1 ).tointeger() ) ) ePrivMessage( "[Error] - Invalid Prop ID", player );
else if ( GetSQLColumnData( q, 2 ) != player.Name ) ePrivMessage( "[Error] - You don't own this Property", player );
else
{
QuerySQL( db, "UPDATE Props SET Owner='Vice-City' WHERE rowid = '" + text + "'" );
rMessage( "** " + player.Name + " Sold Property:[ " + GetSQLColumnData( q, 1 ) + " ] ID:[ " + text + " ]" );
Announce( "~h~Property Sold!", player, 0 );
IncCash( player, GetSQLColumnData( q, 1 ).tointeger() );
}
}
else if ( cmd == "shareprop" )
{
local q = QuerySQL( db, "SELECT * FROM Props WHERE rowid LIKE '" + GetTok( text, " ", 1 ).tointeger() + "'" );
local id = player.ID
if ( !status[ id ].IsReg ) ePrivMessage( "[Error] - You're Not Registered..", player );
else if ( !status[ id ].IsLogged ) ePrivMessage( "[Error] - You're Not logged in..", player );
else if ( !player.IsSpawned ) ePrivMessage( "[Error] - You haven't spawned yet..", player );
else if ( NumTok( text, " " ) < 2 ) ePrivMessage( "[Syntax] - !" + cmd + " <ID> <Nick>", player );
else if ( !IsNum( GetTok( text, " ", 1 ) ) ) ePrivMessage( "[Error] - ID must be Number..", player );
else if ( !PropExists( GetTok( text, " ", 1 ).tointeger() ) ) ePrivMessage( "[Error] - Invalid Prop ID", player );
else if ( GetSQLColumnData( q, 2 ) != player.Name ) ePrivMessage( "[Error] - You don't own this Property", player );
else
{
local plr = GetPlayer( GetTok( text, " ", 2 ) );
if ( !plr ) ePrivMessage( "[Error] - Invalid Nick / ID", player );
else
{
QuerySQL( db, "UPDATE Props SET Shared='" + plr.Name + "' WHERE rowid='" + GetTok( text, " ", 1 ) + "'" );
ePrivMessage( "You shared your Prop:[ " + GetSQLColumnData( q, 0 ) + " ] with: " + plr.Name + ".", player );
ePrivMessage( "Player " + player.Name + " shared Prop ID:[ " + GetTok( text, " ", 1 ) + " ] with you.", plr );
}
}
}
else if ( cmd == "delshareprop" )
{
local q = QuerySQL( db, "SELECT * FROM Props WHERE rowid LIKE '" + text + "'" );
local id = player.ID
if ( !status[ id ].IsReg ) ePrivMessage( "[Error] - You're Not Registered..", player );
else if ( !status[ id ].IsLogged ) ePrivMessage( "[Error] - You're Not logged in..", player );
else if ( !player.IsSpawned ) ePrivMessage( "[Error] - You haven't spawned yet..", player );
else if ( !text ) ePrivMessage( "[Syntax] - !" + cmd + " <ID>", player );
else if ( !IsNum( text ) ) ePrivMessage( "[Error] - ID must be Number..", player );
else if ( !PropExists( GetTok( text, " ", 1 ).tointeger() ) ) ePrivMessage( "[Error] - Invalid Prop ID", player );
else if ( GetSQLColumnData( q, 2 ) != player.Name ) ePrivMessage( "[Error] - You don't own this Property", player );
else
{
QuerySQL( db, "UPDATE Props SET Share='None' WHERE rowid='" + GetTok( text, " ", 2 ) + "'" );
ePrivMessage( "You deleted " + GetSQLColumnData( q, 4 ) + " as a Sharer!", player );
}
}
else if ( cmd == "myprops" )
{
local q = QuerySQL( db, "SELECT * FROM Props WHERE Owner='" + player.Name + "'" );
local id = player.ID
if ( !status[ id ].IsReg ) ePrivMessage( "[Error] - You're Not Registered..", player );
else if ( !status[ id ].IsLogged ) ePrivMessage( "[Error] - You're Not logged in..", player );
else if ( !GetSQLColumnData( q, 2 ) ) ePrivMessage( "[Error] - You don't own a property..", player );
else
{
local i = 1, b = false, c = CountProps();
while( i <= c )
{
if ( GetPropOwner( i ) == player.Name )
{
if ( b ) b = b + " - " + GetPropName( i ) + " [ID: " + i + ")";
else b = GetPropName( i ) + " [ID: " + i + " ]";
}
i ++;
}
if ( !b ) ePrivMessage( "You don't own a property..", player );
else ePrivMessage( "Your Properties:[ " + b + " ]", player );
}
}
else if ( cmd == "myshareprops" )
{
local q = QuerySQL( db, "SELECT * FROM Props WHERE Shared='" + player.Name + "'" );
local id = player.ID
if ( !status[ id ].IsReg ) ePrivMessage( "[Error] - You're Not Registered..", player );
else if ( !status[ id ].IsLogged ) ePrivMessage( "[Error] - You're Not logged in..", player );
else if ( !GetSQLColumnData( q, 3 ) ) ePrivMessage( "[Error] - You don't Share a property..", player );
else
{
local i = 1, b = false, c = CountProps();
while( i <= c )
{
if ( GetPropShare( i ) == player.Name )
{
if ( b ) b = b + " " + GetPropName( i ) + " [ID: " + i + ")";
else b = GetPropName( i ) + " [ID: " + i + " ]";
}
i ++;
}
if ( !b ) ePrivMessage( "You don't Share a property..", player );
else ePrivMessage( "Your Shared Properties:[ " + b + " ]", player );
}
}
And in Database add your own Properties I will not make a database here too.
lol