Hiya!
Is there any function to check a player's distance from a pickup? If there is then please tell me, And if there's not a function like that, Than is there any example on how can I make it?
Actually you can make it, Now I'm at phone(currently), I'll give you the cmd when I'll be on laptop. Anyways here is the function, the cmd is pretty easy to make
function Distance(x1, y1, x2, y2)
{
local dist = sqrt(((x2 - x1)*(x2 - x1)) + ((y2 - y1)*(y2 - y1)));
return dist;
}
DistanceFromPoint( x1, y1, x2, y2 )
//Example usage for checking distance:
DistanceFromPoint( pickup.Pos.x, pickup.Pos.y, player.Pos.x, player.Pos.y ) < 5 { print( "Player is near pickup" ); }
Thank you. I still don't get how can I use it for a cmd. Example, If someone types /removepickup it should say you need to be near the pickup's ID.(I've the /removepickup, But I need to add the distance for it)
function onPlayerCommand( source, command, arguments )
{
if( command == "removepickup" )
{
if( !arguments ) return MessagePlayer( "[#FF0000]Usage: /removepickup [ID]", source );
else if( !IsNum( arguments ) ) return MessagePlayer( "[#FF0000]You mus use pickup ID.", source );
else
{
local i_pickup = FindPickup( arguments );
if( i_pickup )
{
if( DistanceFromPoint( i_pickup.Pos.x, i_pickup.Pos.y, source.Pos.x, source.Pos.y ) < 5 ) {
pickup.Remove( i_pickup );
MessagePlayer( "[#00FF00]Pickup removed.", source );
}
else return MessagePlayer( "[#FF0000]You must be near a pickup to use this command.", source );
}
else MessagePlayer( "[#FF0000]Pickup not found.", source );
}
}
}
Will the function i posted will work?
Quote from: KAKAN on Aug 25, 2015, 01:34 PMWill the function i posted will work?
.
Will work but why not use built-in function if you got them.
Hmm, I didn't known about the inbuilt function. :P, Thanks for telling me ::)
Alright, Thanks.