samp-incognito / samp-streamer-plugin

Streamer Plugin for SA-MP (San Andreas Multiplayer)
Apache License 2.0
231 stars 92 forks source link

AttachCameraToDynamicObject bug with moving object #212

Closed buridan1999 closed 7 years ago

buridan1999 commented 7 years ago

If object is moving, and I try to attach camera to this object, it only teleport camera to begining object coord, but doesn't move with object.

samp-incognito commented 7 years ago

Does AttachCameraToPlayerObject work with moving player objects?

IstuntmanI commented 7 years ago

I tested it:

#include <a_samp>
#include <zcmd>
#include <sscanf2>

new lObject = 0; // just a case test, no need for an array, idc

CMD:objstage( playerid, params[ ] )
{
    new lStage = 0;
    if( sscanf( params, "d", lStage ) )
        return SendClientMessage( playerid, -1, "/objstage [1 - Create Object | 2 - Move Object | 3 - Attach Camera | 4 - Detach Camera | 5 - Stop Object | 6 - Delete Object]" );

    switch( lStage )
    {
        case 1:
        {
            if( lObject )
            {
                DestroyPlayerObject( playerid, lObject );
                lObject = 0;
            }

            new Float:X, Float:Y, Float:Z;
            GetPlayerPos( playerid, X, Y, Z );
            lObject = CreatePlayerObject( playerid, 19522, X, Y + 5.0, Z, 0.0, 0.0, 0.0 );
        }

        case 2:
        {
            if( !lObject )
                return SendClientMessage( playerid, -1, "Object isn't spawned !" );

            new Float:X, Float:Y, Float:Z;
            GetPlayerObjectPos( playerid, lObject, X, Y, Z );
            MovePlayerObject( playerid, lObject, X, Y + 1000.0, Z, 2.0 );
        }

        case 3:
        {
            if( !lObject )
                return SendClientMessage( playerid, -1, "Object isn't spawned !" );

            AttachCameraToPlayerObject( playerid, lObject );
        }

        case 4: SetCameraBehindPlayer( playerid );
        case 5: StopPlayerObject( playerid, lObject );

        case 6:
        {
            if( !lObject )
                return SendClientMessage( playerid, -1, "Object isn't spawned !" );

            DestroyPlayerObject( playerid, lObject );
            lObject = 0;
        }

        default: SendClientMessage( playerid, -1, "Invalid stage !" );
    }

    return 1;
}

Doing /objstage 1, /objstage 2, /objstage 3 works perfectly. Stage 3 before stage 2 works fine too.

But I also tested what he said with this one:

*** Streamer Plugin v2.9.0 by Incognito loaded ***

#include <a_samp>
#include <zcmd>
#include <sscanf2>
#include <streamer>

new lObject = 0; // just a case test, no need for an array, idc

CMD:objstage( playerid, params[ ] )
{
    new lStage = 0;
    if( sscanf( params, "d", lStage ) )
        return SendClientMessage( playerid, -1, "/objstage [1 - Create Object | 2 - Move Object | 3 - Attach Camera | 4 - Detach Camera | 5 - Stop Object | 6 - Delete Object]" );

    switch( lStage )
    {
        case 1:
        {
            if( lObject )
            {
                DestroyDynamicObject( lObject );
                lObject = 0;
            }

            new Float:X, Float:Y, Float:Z;
            GetPlayerPos( playerid, X, Y, Z );
            lObject = CreateDynamicObject( 19522, X, Y + 5.0, Z, 0.0, 0.0, 0.0 );
        }

        case 2:
        {
            if( !lObject )
                return SendClientMessage( playerid, -1, "Object isn't spawned !" );

            new Float:X, Float:Y, Float:Z;
            GetDynamicObjectPos( lObject, X, Y, Z );
            MoveDynamicObject( lObject, X, Y + 1000.0, Z, 2.0 );
        }

        case 3:
        {
            if( !lObject )
                return SendClientMessage( playerid, -1, "Object isn't spawned !" );

            AttachCameraToDynamicObject( playerid, lObject );
        }

        case 4: SetCameraBehindPlayer( playerid );
        case 5: StopDynamicObject( lObject );

        case 6:
        {
            if( !lObject )
                return SendClientMessage( playerid, -1, "Object isn't spawned !" );

            DestroyDynamicObject( lObject );
            lObject = 0;
        }

        default: SendClientMessage( playerid, -1, "Invalid stage !" );
    }

    return 1;
}

Tested exactly the same, works correctly.

He probably has some mistake in his code.

rt-2 commented 7 years ago

I actually have a FPS with a camera attached to an object attached to a player. And it works. I remember having such issue, try updating YSF if you use it. rt-2

IstuntmanI commented 7 years ago

Any update ? Is it still happening to you ? Did you discover why it was bugged to you ? Can you provide a small code to reproduce it ?

samp-incognito commented 7 years ago

I'm guessing this is not a problem on the plugin's end. I'll close this for now.