Liberty Unleashed

Scripting => Script Help => Topic started by: Rodrigo on December 17, 2012, 02:41:51 pm

Title: Spheres error
Post by: Rodrigo on December 17, 2012, 02:41:51 pm
So I wanted to create a command usable only when the player was standing on a determined sphere. I tried this:
Code: [Select]
function onPlayerCommand( player, cmd, text )
{
if ( cmd == "buy" )
{
if ( ( player.Pos == sphere.Pos ) && ( sphere.ID == 0 ) )
{
Message( "Success!" );
}

else Message( "Error! Not on sphere!" );
}
        return 1;
}
Wherever I use the command, it gives me an "getVarInfo: Could not retrieve UserData" error in this line:
Code: [Select]
if ( ( player.Pos == sphere.Pos ) && (sphere.ID == 0 ) )If anyone could help, it would be greatly appreciated.  :)
Title: Re: Spheres error
Post by: Thijn on December 17, 2012, 03:51:05 pm
The error is coming from sphere.Pos. Where did you define sphere?
You'll have to define that using FindSphere.

If you want the function to work for sphere with ID 0 try this:
Code: [Select]
function onPlayerCommand( player, cmd, text )
{
if ( cmd == "buy" )
{
local sphere = FindSphere( 0 );
if ( ( sphere ) && ( player.Pos == sphere.Pos ) ) //Make sure to check if sphere is valid, or you would get errors as well
{
Message( "Success!" );
}
else Message( "Error! Not on sphere!" );
}

return 1;
}
Title: Re: Spheres error
Post by: Rodrigo on December 17, 2012, 05:54:22 pm
Thanks for helping, the command works now, but wherever I enter it it displays the "Error! Not on sphere!" message. I tried standing on the sphere, out of it, even tried standing on the other sphere I have in the server, but always the Error message. ???
Correct me if I'm wrong, but maybe it's just too hard to stay at the exact x, y, z position of the sphere center?

Edit: A friend helped me get it working. :) Here is the fixed script:
Code: [Select]
function onPlayerCommand( player, cmd, text )
{
if ( cmd == "buy" )
{
local mySphere = FindSphere( 0 );
if ( ( mySphere ) && ( GetDistance( mySphere.Pos, player.Pos ) < 4.0 ) )
{
Message( "Success!" );
}
else Message( "Error! Not on sphere!" );
}

return 1;
}
Thanks for taking the time to help me though! ;)