Liberty Unleashed

Scripting => Script Help => Topic started by: Merkel on December 09, 2013, 10:50:47 pm

Title: Player and vehicle
Post by: Merkel on December 09, 2013, 10:50:47 pm
How I can put the player in the vehicle when I spawn the vehicle?

I tried this:

Code: [Select]
else if ( cmd == "v" || cmd == "veh" || cmd == "car" )
{
if ( plr.Spawned )
{
if ( arguments )
{
if ( IsNum( arguments ) )
{
local pTemp = split( arguments, " " ), ID = 90;
if ( IsNum( pTemp[ 0 ] ) ) ID = pTemp[ 0 ].tointeger();

if ( ( ID >= 90 ) && ( ID <= 150 ) )
{
local v = plr.Pos;
local pVehicle = CreateVehicle( ID, Vector( v.x, v.y, v.z ), plr.Angle );

pVehicle.OneTime = true;

local Fv = FindVehicle( pVehicle );
plr.Pos = Fv.Pos;
plr.EnterVehicle( DOOR_DRIVER, Fv );
}
}
else MessagePlayer( "Invalid arguments. Usage: /" + cmd + " < ID >", plr, 250, 0, 0 );
}
else MessagePlayer( "Invalid arguments. Usage: /" + cmd + " < ID >", plr, 250, 0, 0 );
}
else MessagePlayer( "You first need spawn.", plr, 250, 0, 0 );

return true;
}

But doesn't work.
Title: Re: Player and vehicle
Post by: Vortrex on December 10, 2013, 04:06:38 am
Hi Slayer. After reviewing the code you posted, I noticed a problem. When spawning the vehicle, you assigned its instance to the local variable 'pVehicle'.

Afterwards, you used the FindVehicle with its argument being a vehicle pointer already.

Try this:
Remove the line where you used FindVehicle.
Then, change the player.EnterVehicle to pVehicle instead of Fv.


Please let us know if this helps.



-------
Sorry, I am typing this on my phone at the moment so I apologize for any spelling or grammar errors.
Title: Re: Player and vehicle
Post by: Vortrex on December 10, 2013, 04:13:57 am
Sorry for double posting but I couldn't find the edit button on my phone.

Anyway, Slayer, I want to give you a helpful tip. When retrieving a player position (via Player.Pos), it already returns a Vector. You don't have to use the Vector function again (as long as the position stays the same) when calling CreateVehicle(). You can also use Player.Pos directly inside of CreateVehicle as well.

Offtopic: @VRocker, is it possible to make a mobile compatible website? I cannot use my PC right now and it would be helpful on the go.
Title: Re: Player and vehicle
Post by: Mido_Pop on December 10, 2013, 03:55:19 pm
Try This >>
Code: [Select]
function onPlayerCommand( plr, cmd, arguments )
{
       if ( cmd == "v" || cmd == "veh" || cmd == "car" )
{
if ( plr.Spawned )
{
if ( arguments )
{
if ( IsNum( arguments ) )
{
local pTemp = split( arguments, " " ), ID = 90;
if ( IsNum( pTemp[ 0 ] ) ) ID = pTemp[ 0 ].tointeger();

if ( ( ID >= 90 ) && ( ID <= 150 ) )
{
local v = plr.Pos;
local pVehicle = CreateVehicle( ID, Vector( v.x, v.y, v.z ), plr.Angle );

pVehicle.OneTime = true;

                                                local vehicle = GetClosestVehicle( plr );
                                                if ( vehicle )
                                                 {
                                                    plr.Vehicle = vehicle;
                                                 }

}
}
else MessagePlayer( "Invalid arguments. Usage: /" + cmd + " < ID >", plr, 250, 0, 0 );
}
else MessagePlayer( "Invalid arguments. Usage: /" + cmd + " < ID >", plr, 250, 0, 0 );
}
else MessagePlayer( "You first need spawn.", plr, 250, 0, 0 );

return true;
}
 


    return 1;
}
Title: Re: Player and vehicle
Post by: Vortrex on December 10, 2013, 05:43:56 pm
Mido, you are wasting resources on getting the closest vehicle, when it's not needed. What happens if the player spawns two vehicles by accident without moving? Which one would they enter then?

As I said in my previous post:
When using CreateVehicle, it returns a pointer to the vehicle. This is what you need to use to reference your vehicle. If it returns false, tell the player there was a problem.

Code: [Select]
local pVehicle = CreateVehicle( ID, plr.Pos, plr.Angle );
if( pVehicle )
{
    plr.Vehicle = pVehicle;
}

EDIT: Forgot a semicolon. Them damn pesky things.
Title: Re: Player and vehicle
Post by: Thijn on December 19, 2013, 10:49:26 am
Offtopic: @VRocker, is it possible to make a mobile compatible website? I cannot use my PC right now and it would be helpful on the go.

Wap2: http://forum.liberty-unleashed.co.uk? (http://forum.liberty-unleashed.co.uk?)wap2
Tapatalk: http://www.tapatalk.com/ (http://www.tapatalk.com/)
Tapatalk isn't free, but there's always a way.. Which is illegal on this forum so no more info for you!
Title: Re: Player and vehicle
Post by: Merkel on December 27, 2013, 03:27:40 pm
Hi Slayer. After reviewing the code you posted, I noticed a problem. When spawning the vehicle, you assigned its instance to the local variable 'pVehicle'.

Afterwards, you used the FindVehicle with its argument being a vehicle pointer already.

Try this:
Remove the line where you used FindVehicle.
Then, change the player.EnterVehicle to pVehicle instead of Fv.


Please let us know if this helps.



-------
Sorry, I am typing this on my phone at the moment so I apologize for any spelling or grammar errors.

Thanks, but doesn't work.

Sorry for double posting but I couldn't find the edit button on my phone.

Anyway, Slayer, I want to give you a helpful tip. When retrieving a player position (via Player.Pos), it already returns a Vector. You don't have to use the Vector function again (as long as the position stays the same) when calling CreateVehicle(). You can also use Player.Pos directly inside of CreateVehicle as well.

Offtopic: @VRocker, is it possible to make a mobile compatible website? I cannot use my PC right now and it would be helpful on the go.

I know... lol.

Try This >>
Code: [Select]
function onPlayerCommand( plr, cmd, arguments )
{
       if ( cmd == "v" || cmd == "veh" || cmd == "car" )
{
if ( plr.Spawned )
{
if ( arguments )
{
if ( IsNum( arguments ) )
{
local pTemp = split( arguments, " " ), ID = 90;
if ( IsNum( pTemp[ 0 ] ) ) ID = pTemp[ 0 ].tointeger();

if ( ( ID >= 90 ) && ( ID <= 150 ) )
{
local v = plr.Pos;
local pVehicle = CreateVehicle( ID, Vector( v.x, v.y, v.z ), plr.Angle );

pVehicle.OneTime = true;

                                                local vehicle = GetClosestVehicle( plr );
                                                if ( vehicle )
                                                 {
                                                    plr.Vehicle = vehicle;
                                                 }

}
}
else MessagePlayer( "Invalid arguments. Usage: /" + cmd + " < ID >", plr, 250, 0, 0 );
}
else MessagePlayer( "Invalid arguments. Usage: /" + cmd + " < ID >", plr, 250, 0, 0 );
}
else MessagePlayer( "You first need spawn.", plr, 250, 0, 0 );

return true;
}
 


    return 1;
}

And, thanks Mido_Pop, work 100%   :o
Title: Re: Player and vehicle
Post by: Mido_Pop on December 27, 2013, 05:02:20 pm
You Are Welcome  ;D