SA-MP Forums Archive
[Tutorial] How to use SetPlayerAttachedObject [Beginners] - 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)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] How to use SetPlayerAttachedObject [Beginners] (/showthread.php?tid=281448)

Pages: 1 2 3


How to use SetPlayerAttachedObject [Beginners] - =WoR=G4M3Ov3r - 06.09.2011

Using SetPlayerAttachedObject
Step 1 - Defining
Quote:

Warning: This function was removed in SA-MP 0.3c

PHP код:
SetPlayerAttachedObject(playeridindexmodelidboneFloat:fOffsetXFloat:fOffsetYFloat:fOffsetZFloat:fRotXFloat:fRotYFloat:fRotZFloat:fScaleXFloat:fScaleYFloat:fScaleZ); 
PHP код:
SetPlayerHoldingObject(playeridmodelbone); 
PHP код:
#define SetPlayerHoldingObject(%1,%2,%3,%4,%5,%6,%7,%8,%9) SetPlayerAttachedObject(%1,MAX_PLAYER_ATTACHED_OBJECTS-1,%2,%3,%4,%5,%6,%7,%8,%9)
#define StopPlayerHoldingObject(%1) RemovePlayerAttachedObject(%1,MAX_PLAYER_ATTACHED_OBJECTS-1)
#define IsPlayerHoldingObject(%1) IsPlayerAttachedObjectSlotUsed(%1,MAX_PLAYER_ATTACHED_OBJECTS-1) 
Step 2
PHP код:
SetPlayerAttachedObject(playeridindexmodelbone); 
Step 3 - Usage
For ZCMD:

PHP код:
CMD:redcone(playeridparams[])
{
           
SetPlayerAttachedObject(playerid,312386); // Bone 6 means Right handed
           
SendClientMessage(playeridCOLOR_GREEN"You are holding a Redcone.");
           return 
1;

For STRCMP:

PHP код:
public OnPlayerCommandText(playeridcmdtext[])
{
   if(!
strcmp(cmdtext"/redcone"true))
    {
        
SetPlayerAttachedObject(playerid312386);
        
SendClientMessage(playeridCOLOR_GREEN"You are holding a Redcone");
        return 
1;
     }
     return 
0;

Step 4 - Destroying it
PHP код:
RemovePlayerAttachedObject(playerid,index
PHP код:
IsPlayerAttachedObjectSlotUsed(playeridslot
PHP код:
public OnPlayerDeath(playeridkilleridreason)
{
    if(
IsPlayerAttachedObjectSlotUsed(playeridslot)) RemovePlayerAttachedObject(playeridslot);
    return 
1;

Model, and Bone

Whats bone ?
Note: A Maximum of 5 objects may be attached per player.

If there's anything i missed, or you got any problems, please post.

Credits: The SA-MP Wiki.


Re: How to use SetPlayerAttachedObject [Beginners] - Kitten - 06.09.2011

Nice tut , useful for newbies.


Re: How to use SetPlayerAttachedObject [Beginners] - =WoR=G4M3Ov3r - 06.09.2011

Quote:
Originally Posted by Kitten
Посмотреть сообщение
Nice tut , useful for newbies.
Yep, this is why i added [Beginners] in the name .


Re: How to use SetPlayerAttachedObject [Beginners] - =WoR=Bruno - 06.09.2011

Usefull ^^
Thanx


Re: How to use SetPlayerAttachedObject [Beginners] - =WoR=G4M3Ov3r - 06.09.2011

Quote:
Originally Posted by =WoR=Bruno
Посмотреть сообщение
Usefull ^^
Thanx
You're Welcome.


Re: How to use SetPlayerAttachedObject [Beginners] - Kush - 06.09.2011

Very nice, well done.


Re: How to use SetPlayerAttachedObject [Beginners] - Jack_Leslie - 06.09.2011

Quote:
Originally Posted by Basicz
Посмотреть сообщение
SUGGESTION : Use a loop to remove all attached objects, so it's code will be cleaner

So newbies will not copy paste it's code multiple times.
pawn Код:
public OnPlayerDeath( playerid, killerid, reason )
{
                                         // Comment below was taken from a_players.inc, we will use 0-4 this time.
                                         // 5 = 0-4
    for ( new i; i < 5; i ++ )  // Creates the variable 'i' and checks if it's value is lower than 5, if so, increase the value of ' i '
    {
        if ( IsPlayerAttachedObjectSlotUsed( playerid, i ) ) // If the attached slot ( it depends on the value of the 'i' variable ) of the player is used.
            RemovePlayerAttachedObject( playerid, i ); // Remove the attached object the player have, the slot is the value of the 'i' variable.
    }

    return 1;
}
SUGGESTION2 : Add the bones list. So beginners wouldn't have confused what is the bones ID

Код:
-- This is from the SA-MP wikia.

0 - Not usable (will crash the client)

1 - Spine

2 - Head

3 - Left upper arm

4 - Right upper arm

5 - Left hand

6 - Right hand

7 - Left thigh

8 - Right thigh

9 - Left foot

10 - Right foot

11 - Right calf

12 - Left calf

13 - Left forearm

14 - Right forearm

15 - Left clavicle

16 - Right clavicle

17 - Neck

18 - Jaw
Nice tutorial though, good for beginners.
Quote:

Model, and Bone

....


Re: How to use SetPlayerAttachedObject [Beginners] - FireCat - 06.09.2011

Not very well explained, sorry :/ (I'm not acting bitchy)

You could explain what each of these do:
pawn Код:
SetPlayerAttachedObject(playerid, index, modelid, bone, Float:fOffsetX, Float:fOffsetY, Float:fOffsetZ, Float:fRotX, Float:fRotY, Float:fRotZ, Float:fScaleX, Float:fScaleY, Float:fScaleZ);
What does this do, and what is the index for?:
pawn Код:
RemovePlayerAttachedObject(playerid,index)
So what is the slot for?
pawn Код:
IsPlayerAttachedObjectSlotUsed(playerid, slot)



Re: How to use SetPlayerAttachedObject [Beginners] - =WoR=G4M3Ov3r - 06.09.2011

Thanks guys, and

Quote:
Originally Posted by Basicz
Посмотреть сообщение
SUGGESTION : Use a loop to remove all attached objects, so it's code will be cleaner

So newbies will not copy paste it's code multiple times.
pawn Код:
public OnPlayerDeath( playerid, killerid, reason )
{
                                         // Comment below was taken from a_players.inc, we will use 0-4 this time.
                                         // 5 = 0-4
    for ( new i; i < 5; i ++ )  // Creates the variable 'i' and checks if it's value is lower than 5, if so, increase the value of ' i '
    {
        if ( IsPlayerAttachedObjectSlotUsed( playerid, i ) ) // If the attached slot ( it depends on the value of the 'i' variable ) of the player is used.
            RemovePlayerAttachedObject( playerid, i ); // Remove the attached object the player have, the slot is the value of the 'i' variable.
    }

    return 1;
}
SUGGESTION2 : Add the bones list. So beginners wouldn't have confused what is the bones ID

Код:
-- This is from the SA-MP wikia.

0 - Not usable (will crash the client)

1 - Spine

2 - Head

3 - Left upper arm

4 - Right upper arm

5 - Left hand

6 - Right hand

7 - Left thigh

8 - Right thigh

9 - Left foot

10 - Right foot

11 - Right calf

12 - Left calf

13 - Left forearm

14 - Right forearm

15 - Left clavicle

16 - Right clavicle

17 - Neck

18 - Jaw
Nice tutorial though, good for beginners.
I already put the model and bones with the link.

Quote:
Originally Posted by FireCat
Посмотреть сообщение
Not very well explained, sorry :/ (I'm not acting bitchy)

You could explain what each of these do:
pawn Код:
SetPlayerAttachedObject(playerid, index, modelid, bone, Float:fOffsetX, Float:fOffsetY, Float:fOffsetZ, Float:fRotX, Float:fRotY, Float:fRotZ, Float:fScaleX, Float:fScaleY, Float:fScaleZ);
What does this do, and what is the index for?:
pawn Код:
RemovePlayerAttachedObject(playerid,index)
So what is the slot for?
pawn Код:
IsPlayerAttachedObjectSlotUsed(playerid, slot)
Its obvious, since you can use the one like SetPlayerHoldingObject, you won't need me to explain what all of this does, For RemovePlayerAttachedObject, i didn't use index, i believe i said slot, and i already noted that you may only use 5 objects, which means 1-5 slots, you didn't read.


Re: How to use SetPlayerAttachedObject [Beginners] - Jafet_Macario - 06.09.2011

Nice.


Re: How to use SetPlayerAttachedObject [Beginners] - =WoR=G4M3Ov3r - 06.09.2011

Quote:
Originally Posted by Jafet_Macario
Посмотреть сообщение
Nice.
Thanks


Re: How to use SetPlayerAttachedObject [Beginners] - =WoR=G4M3Ov3r - 06.09.2011

Quote:
Originally Posted by Cimbe94
Посмотреть сообщение
Nice tutorial, usefull for beginners.
Yep, Thanks.


Re: How to use SetPlayerAttachedObject [Beginners] - [NoV]LaZ - 06.09.2011

Your strcmp command: strcmp returns 0 if the strings are the same, other than that you forgot to close the parenthesis for the if condition.


Re: How to use SetPlayerAttachedObject [Beginners] - =WoR=G4M3Ov3r - 06.09.2011

Quote:
Originally Posted by [NoV]LaZ
Посмотреть сообщение
Your strcmp command: strcmp returns 0 if the strings are the same, other than that you forgot to close the parenthesis for the if condition.
Yep, thanks for that, edited it, added the bracket, plus a return 0 in the end after the cmd.


Re: How to use SetPlayerAttachedObject [Beginners] - PhoenixB - 06.09.2011

Nice tutorial man, 10/10


Re: How to use SetPlayerAttachedObject [Beginners] - =WoR=G4M3Ov3r - 06.09.2011

Quote:
Originally Posted by PhoenixB
Посмотреть сообщение
Nice tutorial man, 10/10
Thanks man


Re: How to use SetPlayerAttachedObject [Beginners] - Gogon - 07.09.2011

Mantabbbbb


Re: How to use SetPlayerAttachedObject [Beginners] - =WoR=G4M3Ov3r - 07.09.2011

Quote:
Originally Posted by Gogon
Посмотреть сообщение
Mantabbbbb
Mantab ?, I don't understand Korean, please use English


Re: How to use SetPlayerAttachedObject [Beginners] - =WoR=Varth - 07.09.2011

Quote:
Originally Posted by Gogon
Посмотреть сообщение
Mantabbbbb
Quote:
Originally Posted by G4M3Ov3r
Посмотреть сообщение
Mantab ?, I don't understand Korean, please use English
Mantab = awesome.


Re: How to use SetPlayerAttachedObject [Beginners] - =WoR=G4M3Ov3r - 07.09.2011

Quote:
Originally Posted by varthshenon
Посмотреть сообщение
Mantab = awesome.
Oh, thanks then, lol.