Author Topic: Player and vehicle  (Read 3672 times)

Merkel

  • Jr. Member
  • **
  • Posts: 89
  • Karma: +4/-10
    • View Profile
Player and vehicle
« 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.
« Last Edit: December 09, 2013, 10:52:55 pm by Slayer »
Westwood Studios

The best studios company in strategy videogames.

Vortrex

  • Full Member
  • ***
  • Posts: 267
  • Karma: +54/-74
    • View Profile
Re: Player and vehicle
« Reply #1 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.

Vortrex

  • Full Member
  • ***
  • Posts: 267
  • Karma: +54/-74
    • View Profile
Re: Player and vehicle
« Reply #2 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.

Mido_Pop

  • Full Member
  • ***
  • Posts: 168
  • Karma: +6/-20
  • The_Pops ( War )
    • View Profile
Re: Player and vehicle
« Reply #3 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;
}



Vortrex

  • Full Member
  • ***
  • Posts: 267
  • Karma: +54/-74
    • View Profile
Re: Player and vehicle
« Reply #4 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.
« Last Edit: December 10, 2013, 05:46:41 pm by Vortrex »

Thijn

  • Tester
  • Sr. Member
  • ****
  • Posts: 531
  • Karma: +27/-16
    • View Profile
Re: Player and vehicle
« Reply #5 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?wap2
Tapatalk: 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!

Merkel

  • Jr. Member
  • **
  • Posts: 89
  • Karma: +4/-10
    • View Profile
Re: Player and vehicle
« Reply #6 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
Westwood Studios

The best studios company in strategy videogames.

Mido_Pop

  • Full Member
  • ***
  • Posts: 168
  • Karma: +6/-20
  • The_Pops ( War )
    • View Profile
Re: Player and vehicle
« Reply #7 on: December 27, 2013, 05:02:20 pm »
You Are Welcome  ;D



 

© Liberty Unleashed Team.