Author Topic: Spheres error  (Read 1154 times)

Rodrigo

  • Newbie
  • *
  • Posts: 10
  • Karma: +8/-1
  • Professional Dodo Pilot
    • View Profile
Spheres error
« 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.  :)

Thijn

  • Tester
  • Sr. Member
  • ****
  • Posts: 531
  • Karma: +27/-16
    • View Profile
Re: Spheres error
« Reply #1 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;
}

Rodrigo

  • Newbie
  • *
  • Posts: 10
  • Karma: +8/-1
  • Professional Dodo Pilot
    • View Profile
Re: Spheres error
« Reply #2 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! ;)
« Last Edit: December 17, 2012, 11:08:39 pm by Rodrigo »

 

© Liberty Unleashed Team.