Attaching object to vehicle
#1

I'm trying to attach a pizzabox object to the vehicle everytime you enter the vehicle and then destroying it once you've exitted it(it's hard to enter the vehicle once there's an object in the way).

The object is not being placed when they enter the vehicle, why?


When they enter the vehicle: (onplayerstatechange)
pawn Код:
new vehicleid =  GetPlayerVehicleID(playerid);
AttachObjectToVehicle(objectid2, vehicleid, 0, -1, 0.5, -1.6, 0.0, 0.0);
When they exit the vehicle: (onplayerexitvehicle)
pawn Код:
DestroyObject(objectid2);
Reply
#2

Quote:
Originally Posted by Knekt
Посмотреть сообщение
I'm trying to attach a pizzabox object to the vehicle everytime you enter the vehicle and then destroying it once you've exitted it(it's hard to enter the vehicle once there's an object in the way).

The object is not being placed when they enter the vehicle, why?


When they enter the vehicle: (onplayerstatechange)
pawn Код:
new vehicleid =  GetPlayerVehicleID(playerid);
AttachObjectToVehicle(objectid2, vehicleid, 0, -1, 0.5, -1.6, 0.0, 0.0);
When they exit the vehicle: (onplayerexitvehicle)
pawn Код:
DestroyObject(objectid2);
You would need to check if they entered the vehicle (OnPlayerStateChange), then get their vehicleid, and if it's the id of the car you want, attach object to vehicle, but im pretty sure you'd need to createobject first.
Reply
#3

And where is 'objectid2' coming from?
Reply
#4

I obviously have created an object ongamemodeinit, that's not the question.

I'm getting the vehicle using: ?
Код:
new vehicleid =  GetPlayerVehicleID(playerid);
Reply
#5

Quote:
Originally Posted by Knekt
Посмотреть сообщение
I obviously have created an object ongamemodeinit, that's not the question.

I'm getting the vehicle using: ?
Код:
new vehicleid =  GetPlayerVehicleID(playerid);
Yes
Reply
#6

Yeah that's what I mentioned in the thread, it's not placing an object on the bike anyways.
Since people assume I didn't use createobject, here's the code:
The issue is: Object is not being placed even though the co-ordinates are correct.
pawn Код:
//on top
new objectid2;

//gamemodeinit
objectid2 = CreateObject(1582, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);

//onplayerstatechange
new vehicleid =  GetPlayerVehicleID(playerid);
if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
{
       AttachObjectToVehicle(objectid2, vehicleid, 0, -1, 0.5, -1.6, 0.0, 0.0);
}

//onplayerexitvehicle
DestroyObject(objectid2); //Destroys pizza on bike
Reply
#7

Well... if you're creating an object under OnGameModeInit (Only gets called once...), and destroying it every time a player exits a vehicle (which can be called thousands of times...), don't you think you're going to run into trouble?

So... my question WAS of importance to this issue, thank you very much...
pawn Код:
new objectid2[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
    objectid2[playerid] = INVALID_OBJECT_ID;
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    //Stuff here
    new vehicleid =  GetPlayerVehicleID(playerid);
    if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
    {
        objectid2[playerid] = CreateObject(1582, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
        AttachObjectToVehicle(objectid2[playerid], vehicleid, 0, -1, 0.5, -1.6, 0.0, 0.0);
    }
    if(oldstate == PLAYER_STATE_DRIVER && newstate == PLAYER_STATE_ONFOOT)
    {
        DestroyObject(objectid2[playerid]);
        objectid2[playerid] = INVALID_OBJECT_ID;
    }
    //More stuff here...
    return 1;
}
Simple...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)