Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: Xmair on Aug 25, 2015, 08:56 AM

Title: Function
Post by: Xmair on Aug 25, 2015, 08:56 AM
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?
Title: Re: Function
Post by: KAKAN on Aug 25, 2015, 09:04 AM
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;
}
Title: Re: Function
Post by: DizzasTeR on Aug 25, 2015, 09:13 AM
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" ); }
Title: Re: Function
Post by: Xmair on Aug 25, 2015, 10:34 AM
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)
Title: Re: Function
Post by: DizzasTeR on Aug 25, 2015, 11:50 AM
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 );
        }
    }
}
Title: Re: Function
Post by: KAKAN on Aug 25, 2015, 01:34 PM
Will the function i posted will work?
Title: Re: Function
Post by: DizzasTeR on Aug 25, 2015, 01:50 PM
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.
Title: Re: Function
Post by: KAKAN on Aug 25, 2015, 02:07 PM
Hmm, I didn't known about the inbuilt function. :P, Thanks for telling me ::)
Title: Re: Function
Post by: Xmair on Aug 27, 2015, 09:15 AM
Alright, Thanks.