Liberty Unleashed

Scripting => Script Help => Topic started by: Merkel on December 28, 2013, 09:59:43 pm

Title: Get Pickup pos and spawn from db
Post by: Merkel on December 28, 2013, 09:59:43 pm
Hi,

I have a problem getting the position and spawn the pickups for the properties. When the server call the function, the pickups in the server doesn't spawn. It does not give me any errors.

Here the function:

Code: [Select]
function LoadProps()
{
if ( CountProps() != 0 )
{
    local q = sqlite_query( db, "SELECT * FROM Properties WHERE ID='%'" ), pos;
    while ( sqlite_column_data( q, 0 ) )
    {
local coords = sqlite_column_data( q, 5 );

CreatePickup( 1361, Vector( GetTok( coords, " ", 1 ).tofloat(), GetTok( coords, " ", 2 ).tofloat(), GetTok( coords, " ", 3 ).tofloat() ) );
sqlite_next_row( q );
    }
sqlite_free( q );
}
}

I'm newbie in SQLite...
Title: Re: Get Pickup pos and spawn from db
Post by: Vortrex on December 28, 2013, 10:46:43 pm
Without an error, it's harder to determine the source.

However, I think your query might not be right. The WHERE clause shouldn't exist if you are trying to pull all the records from a table. Also, you may need to include field names in your query to help manage what is selected. Just use something like this:
Code: [Select]
"SELECT ID,Coords FROM Properties"
And column data 0 will be your ID, and column data 1 will be your coordinates.

EDIT: I messed up the bold thing in my original post.
Title: Re: Get Pickup pos and spawn from db
Post by: Merkel on December 29, 2013, 10:42:20 am
Without an error, it's harder to determine the source.

However, I think your query might not be right. The WHERE clause shouldn't exist if you are trying to pull all the records from a table. Also, you may need to include field names in your query to help manage what is selected. Just use something like this:
Code: [Select]
"SELECT ID,Coords FROM Properties"
And column data 0 will be your ID, and column data 1 will be your coordinates.

The problem is not in this function, is in "CountProps"...
When the server call this function (CountProps), fails,I have seen with "print", the server does not come over there

Code: [Select]
function CountProps()
{
    local a = 0, q = sqlite_query( db, "SELECT ID FROM Properties" );
while ( sqlite_column_data( q, 0 ) )
{
a++;
sqlite_next_row( q );
}
return a; 
sqlite_free( q );
}

ADMIN EDIT: Stop insulting!
USER EDIT: Insulting what ? LOL
Title: Re: Get Pickup pos and spawn from db
Post by: Vortrex on December 29, 2013, 02:31:51 pm
If the problem is in a different function, why didn't you post that function in the first place?

Also, try this query instead:
Code: [Select]
SELECT count(*) FROM Properties
That should give you a number of rows. Use this data like any other query, like so:
Code: [Select]
sqlite_column_data( q , 0 )
Title: Re: Get Pickup pos and spawn from db
Post by: Merkel on December 29, 2013, 07:39:17 pm


-- Topic closed --

Thanks to Vortrex to help me.