SA-MP Forums Archive
DetachObjcetFromPlayer - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: DetachObjcetFromPlayer (/showthread.php?tid=604997)



DetachObjcetFromPlayer - NeXoR - 13.04.2016

Is it possible to disable AttachObjectToPlayer without DestroyObject ?


Re: DetachObjcetFromPlayer - Sew_Sumi - 13.04.2016

https://sampwiki.blast.hk/wiki/GetObjectPos and https://sampwiki.blast.hk/wiki/GetObjectRot

then

DestroyObject and CreateObject maybe.


If this works, and it doesn't look too bad, you could make a function of it.


Re: DetachObjcetFromPlayer - Godey - 13.04.2016

-> CreateObject
-> Attach it to the player
-> Delete the created object (it makes sense, because when the object is deleted, it will automatically un-attach it)


Re: DetachObjcetFromPlayer - Sew_Sumi - 13.04.2016

Quote:
Originally Posted by Godey
View Post
-> CreateObject
-> Attach it to the player
-> Delete the created object (it makes sense, because when the object is deleted, it will automatically un-attach it)
He's wanting to keep the object, hence the not using deleteobject.


Re: DetachObjcetFromPlayer - NeXoR - 13.04.2016

Quote:
Originally Posted by Sew_Sumi
View Post
He's wanting to keep the object, hence the not using deleteobject.
Exactly


Re: DetachObjcetFromPlayer - Godey - 13.04.2016

What do you even mean exactly? Dettach from the player and do what with the object?


Re: DetachObjcetFromPlayer - Sew_Sumi - 13.04.2016

Quote:
Originally Posted by Godey
View Post
What do you even mean exactly? Detach from the player and do what with the object?
Wants it to detatch...


As in walk somewhere with it attached, then when he "detaches" for the object to stay there...



C'mon... You've been doing so well in answering all those threads (I been seeing) then this?


Make a function, doing what I said... GetObjectPos GetObjectRot, then DeleteObject, and CreateObject. Just so it appears to stay in the same spot. Could do CreateObject then DeleteObject so it visually doesn't glitch.


Re: DetachObjcetFromPlayer - Godey - 13.04.2016

Well in that case, your right..
-> Create object
-> Attach to Player
-> Delete object ( Before deleting, GetObjectPos & GetObjectRot )
-> Create new object ( Use coords & rotation which have stored use those 2 functions)

Thank you for being so observant


Re: DetachObjcetFromPlayer - NeXoR - 13.04.2016

Quote:
Originally Posted by Godey
View Post
Well in that case, your right..
-> Create object
-> Attach to Player
-> Delete object ( Before deleting, GetObjectPos & GetObjectRot )
-> Create new object ( Use coords & rotation which have stored use those 2 functions)

Thank you for being so observant
Quote:
Originally Posted by Sew_Sumi
View Post
Wants it to detatch...


As in walk somewhere with it attached, then when he "detaches" for the object to stay there...



C'mon... You've been doing so well in answering all those threads (I been seeing) then this?


Make a function, doing what I said... GetObjectPos GetObjectRot, then DeleteObject, and CreateObject. Just so it appears to stay in the same spot. Could do CreateObject then DeleteObject so it visually doesn't glitch.
Well, It returns to the spawn position
Pics:




Code:
PHP Code:
else if(!strcmp(params"stop"true))
    {
        new 
Float:XFloat:YFloat:ZFloat:RXFloat:RYFloat:RZ;
        if(!
UsingStretcher[playerid]) return SendClientMessage(playeridCOLOR_GREY"You are not using any stretcher.");
        if(!
MovingStretcher[playerid]) return SendClientMessage(playeridCOLOR_GREY"You are not moving your stretcher.");
        
MovingStretcher[playerid] = 0;
         
GetObjectPos(StretcherObj[playerid], XYZ);
         
GetObjectRot(StretcherObj[playerid], RXRYRZ);
        
DestroyObject(StretcherObj[playerid]);
        
StretcherObj[playerid] = CreateObject(2146XYZRXRYRZ100.0);
        
SendClientMessage(playeridCOLOR_LIGHTRED"You have stopped moving your stretcher.");
        return 
1;
    } 



Re: DetachObjcetFromPlayer - Godey - 13.04.2016

DrawDistance is optional, try without it:
Code:
StretcherObj[playerid] = CreateObject(2146, X, Y, Z, RX, RY, RZ);
If this doesn't work instead of GetObjectPos, try GetPlayerPos..


Re: DetachObjcetFromPlayer - NeXoR - 13.04.2016

Quote:
Originally Posted by Godey
View Post
DrawDistance is optional, try without it:
Code:
StretcherObj[playerid] = CreateObject(2146, X, Y, Z, RX, RY, RZ);
If this doesn't work instead of GetObjectPos, try GetPlayerPos..
First time it spawned above me, Then I changed the X and Z offset to match the AttachObjectToPlayer
Code
PHP Code:
GetPlayerPos(playeridXYZ);
         
GetObjectRot(StretcherObj[playerid], RXRYRZ);
        
DestroyObject(StretcherObj[playerid]);
        
-= 1.00-= 0.50;
        
StretcherObj[playerid] = CreateObject(2146XYZRXRYRZ100.0); 
But the stretcher spawns behind me (without rotation), How can I store the rotation ?


Re: DetachObjcetFromPlayer - Godey - 13.04.2016

Actually you can't,
now you have 2 options
[1]: Bear with random rotation
[2]: Try to fix GetObjectPos


Re: DetachObjcetFromPlayer - NeXoR - 13.04.2016

Quote:
Originally Posted by Godey
View Post
Actually you can't,
now you have 2 options
[1]: Bear with random rotation
[2]: Try to fix GetObjectPos
Got a clue how to do Number 2 ?


Re: DetachObjcetFromPlayer - Sew_Sumi - 13.04.2016

This could be something to do with crouching, offsets and a few other bits but this is good progress regardless.


Re: DetachObjcetFromPlayer - NeXoR - 13.04.2016

Quote:
Originally Posted by Sew_Sumi
View Post
This could be something to do with crouching, offsets and a few other bits but this is good progress regardless.
Should I just use SetPlayerAttachedObject ?


Re: DetachObjcetFromPlayer - Sew_Sumi - 13.04.2016

There should be a way of doing this, maybe you should use a blank script, and test a heap to see how you can make this work. Another maybe, to not attach the object to the player, but have the object follow the player using MoveObject and use GetPlayerPos, GetPlayerVelocity and all those bits.


You've got a good plan, and it has been done before, but yea, it's going to take some tweaking.


Re: DetachObjcetFromPlayer - NeXoR - 13.04.2016

Quote:
Originally Posted by Sew_Sumi
View Post
There should be a way of doing this, maybe you should use a blank script, and test a heap to see how you can make this work. Another maybe, to not attach the object to the player, but have the object follow the player using MoveObject and use GetPlayerPos, GetPlayerVelocity and all those bits.


You've got a good plan, and it has been done before, but yea, it's going to take some tweaking.
I'll try out the MoveObject, thanks for the motivation xD

Which callback should I use ? OnPlayerUpdate ?


Re: DetachObjcetFromPlayer - Sew_Sumi - 13.04.2016

Try a timer, more than OnPlayerUpdate. Being that it's a stretcher system it's not like everyone is going to use a stretcher at the same time, you could use OnPlayerUpdate by using it correctly, but for testing purposes, stick to a timer so it doesn't conflict too badly.

Just keep an eye on lag and how the stretcher appears.