How to use SetPlayerAttachedObject [Beginners] -
=WoR=G4M3Ov3r - 06.09.2011
Using SetPlayerAttachedObject
- In this Tutorial, I will be showing you guys how to use SetPlayerAttachedObject, using this code is easy, but as it shows in the wiki, you might get confused, so this is the right way to use it.
Step 1 - Defining
- As you all know, in the previous SA-MP versions, we had SetPlayerHoldingObject, Now it was removed from SAMP version 0.3c, as stated in the wiki.
Quote:
Warning: This function was removed in SA-MP 0.3c
|
- The current way of using SetPlayerAttachedObject is this way:
PHP код:
SetPlayerAttachedObject(playerid, index, modelid, bone, Float:fOffsetX, Float:fOffsetY, Float:fOffsetZ, Float:fRotX, Float:fRotY, Float:fRotZ, Float:fScaleX, Float:fScaleY, Float:fScaleZ);
- In order to use it like SetPlayerHoldingObject
PHP код:
SetPlayerHoldingObject(playerid, model, bone);
- You will need the following defines, posted on the top of your script, under the includes.
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
- After defining it, it'll be able to be used this way:
PHP код:
SetPlayerAttachedObject(playerid, index, model, bone);
Step 3 - Usage
- Now you want to use it in a CMD of yours, For example a Redcone, I'll be giving an example of using it with ZCMD, and STRCMP.
For ZCMD:
PHP код:
CMD:redcone(playerid, params[])
{
SetPlayerAttachedObject(playerid,3, 1238, 6); // Bone 6 means Right handed
SendClientMessage(playerid, COLOR_GREEN, "You are holding a Redcone.");
return 1;
}
For STRCMP:
PHP код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if(!strcmp(cmdtext, "/redcone", true))
{
SetPlayerAttachedObject(playerid, 3, 1238, 6);
SendClientMessage(playerid, COLOR_GREEN, "You are holding a Redcone");
return 1;
}
return 0;
}
Step 4 - Destroying it
- You can destroy the object, by simply using RemovePlayerAttachedObject, And you will need IsPlayerAttachedObjectSlotUsed.
PHP код:
RemovePlayerAttachedObject(playerid,index)
- Index here, refers to "slot", just like IsPlayerAttachedObjectSlotUsed.
PHP код:
IsPlayerAttachedObjectSlotUsed(playerid, slot)
- For Example, when you die, the item shouldn't be attached to the player anymore, use it this way:
PHP код:
public OnPlayerDeath(playerid, killerid, reason)
{
if(IsPlayerAttachedObjectSlotUsed(playerid, slot)) RemovePlayerAttachedObject(playerid, slot);
return 1;
}
Model, and
Bone
Whats bone ?
- bone is the part of the body you want to attach the object to.
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.
|
....
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.