How to Add Props Sytem

Started by Luckshya, Jun 14, 2015, 10:13 AM

Previous topic - Next topic

Luckshya

#15
i added this stuff to create prop system

added this cmd to create pickup and add prop.
Is it correct cmd


else if ( cmd == "addprop" )
 {
 if ( GetLevel( player ) >= 4 )
 {
 if ( player.IsSpawned )
 {
 if ( text )
 {
 local TextSplit = split( text, " " );
       
 local Name = TextSplit[ 0 ], Cost = TextSplit[ 1 ];
       
 local x = player.Pos.x, y = player.Pos.y, z = player.Pos.z;
       
 QuerySQL( db, "INSERT INTO Properties ( Name, Cost, Owner, Shared, Pos ) values ( '" + Name + "', '" + Cost + "', 'None', 'None', '" + x + " " + y + " " + z + "' )" );
       
 local Pos = Vector( x.tofloat(), y.tofloat(), z.tofloat() );
       
 CreatePickup( 407, Pos );
       
 MessgaePlayer( "New Property - Name: " + Name + ", Cost: " + Cost, player );
 }
 else MessgaePlayer( "Usage: /c " + cmd + " <prop name> <cost>", player );
 }
 else MessgaePlayer( "Error - You haven't spawned.", player );
 }
 else MessgaePlayer( "Error - You need to be at least level 4.", player );
 }


in functions.nut

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 == "None" ) 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 == "None" ) 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;

   
}
And also added in main.nut

function onPickupPickedUp( player, pickup )
{   
    pickup.RespawnTime = 2;
   if ( pickup.Model == 407 )
   {
       local q = QuerySQL( db, "SELECT * FROM Props WHERE rowid='" + pickup.ID + "'" );
      if ( q )
      {
      MessagePlayer( "===> " + GetSQLColumnData( q, 0 ) + " <===", player );
      MessagePlayer( "ID:[ " + pickup.ID + " ] Cost:[ $" + GetSQLColumnData( q, 1 ) + " ] Owner:[ " + GetSQLColumnData( q, 2 ) + " ] Share:[ " + GetSQLColumnData( q, 3 ) + " ]", player );
      MessagePlayer( "Forsale:[ " + CheckForsale( pickup.ID ) + " ]", player );
       }
   }
}

and i creted pickup using /addprop and after this i run this by adding this u see above it runs but when i use /addprop it adds the pickup and also all wht i saved goes to db.
and also when after creating pickup before closing server it does not show anything whn i stand on pickup and when restart server  pickup does not come.

and when i added this in main.nut

//Load All Props...
   NewTimer( "LoadProps", 500, 1 );
   NewTimer( "LoadPickups", 700, 1 );
It shows this error

http://i.imgur.com/HJhkLxM.png

jayant

Whats line 224 ? I think you are not having LoadPickups function in your script and due to do that it is saying callback timer not exist.
Add this function in your functions.nut -
function LoadPickups()
{
CreatePickup(431, Vector( -922.4399,-418.1992,56.0882));
}

Luckshya

Hey my some problems solved.
Tnx Jayant
But now my problem is tht whn i create pickup at tht time all info comes.
But whn i restart, pickup remains but whn i stand on pickup info not coming before restarting info is coming.
Pls see up if there r any errors

jayant

Add some pickups, close the server and then check your database for your pickups,maybe the aren't saving in the database...The above function onPickupPickedUp( player, pickup ) should work.

Luckshya

Hey they r saving in db
pls chk     (pickuppickedup)
and i think function Load props is wrong pls jayant chk
or /addprop cmd is corrupted
pls chk

Luckshya

Hey my addprop is corrupted pls can u give me /addprop cmd

MacTavish

tada use it

else if ( cmd == "addprop" )
 {
 if ( GetLevel( player ) >= 4 )
 {
 if ( player.IsSpawned )
 {
 if ( text )
 {
 local TextSplit = split( text, " " );
       
 local Name = TextSplit[ 0 ], Cost = TextSplit[ 1 ];
       
 local x = player.Pos.x, y = player.Pos.y, z = player.Pos.z;
       
 QuerySQL( db, "INSERT INTO Properties ( Name, Cost, Owner, Shared, Pos ) values ( '" + Name + "', '" + Cost + "', 'None', 'None', '" + x + " " + y + " " + z + "' )" );
       
 local Pos = Vector( x.tofloat(), y.tofloat(), z.tofloat() );
       
 CreatePickup( 407, Pos );
       
 MessagePlayer( "New Property - Name: " + Name + ", Cost: " + Cost, player );
 }
 else MessagePlayer( "Usage: /c " + cmd + " <prop name> <cost>", player );
 }
 else MessagePlayer( "Error - You haven't spawned.", player );
 }
 else MessagePlayer( "Error - You need to be at least level 4.", player );
 }

You wrote wrong it is Message not Messgae

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

Luckshya

Hey tht i done succesfully thnx for ur help!!!! ;D
But now if i type /buyprop it is in db but in game it says the propery does not exist. :-\
Can u pls chk wht is wrong with this. :'(

 else if ( cmd == "buyprop" )
{
local q = QuerySQL( db, "SELECT Owner, Cost, Name FROM Props WHERE rowid LIKE '" + text + "'" );

if ( status[player.ID].IsReg )
{
if ( status[player.ID].IsLogged )
{
if ( text )
{
if ( !GetSQLColumnData( q, 1 ) ) MessagePlayer( "Error - Property does not exist.", player );
else
{
if ( player.Cash( player ) >= GetSQLColumnData( q, 1 ).tointeger() )
{
if ( GetSQLColumnData( q, 0 ) != "None" ) MessagePlayer( "Error - This property is already owned.", player );
else
{
QuerySQL( db, "UPDATE Properties SET Owner = '" + player.Name + "' WHERE rowid = '" + text + "'" );
MessagePlayer( "You have just purchased a property!", player );
MessagePlayer( "Name: " + GetSQLColumnData( q, 2 ) + ", ID: " + text, player );
MessagePlayer( "You can now use the following commands: !sellprop, !shareprop, !delshareprop, !myprops", player );
SetCash( player, player.Cash( player ) - GetSQLColumnData( q, 1 ).tointeger() );
}
}
else MessagePlayer( "Error - You need $" + GetSQLColumnData( q, 1 ) + " to buy this prop.", player );
}
}
else MessagePlayer( "Usage: /" + cmd + " <property ID>", player );
}
else MessagePlayer( "Error - You are not logged in.", player );
}
else MessagePlayer( "Error - You haven't registered your nickname.", player );
}

Luckshya

Hey see whn i use /addprop and make 1 pickup before restartt, info comes correctly but when i make 2 pickups and restart, 1st pickup added does not show anything and the second pickup shows the info saved for 1st pickup. and all continuing like 1st pickup nothing, 2nd pickup of 1st and 2nd pickup shows of third like this it shows pls chk above replies is there any error.

This is the sequence in my db.

http://i.imgur.com/Yy0xdKS.png