13.04.2014, 01:02
(
Last edited by Corekt; 25/04/2014 at 07:24 AM.
)
AOX
IntroductionAttached Object Ex is an extension of the player attached object functions that allows you to retrieve and set data for player attached objects, and even move them like the MoveObject function. It introduces Temporary Attached objects, which allows you to attach objects for a certain amount of time without having to keep track of indexes*. It also contains fixes for a few annoyances such as attached objects covering your view when zooming with a Sniper and attached objects remaining attached upon timing out and reconnecting.
Download
http://pastebin.com/WmfPGSCn
Include this before any other include that uses the functions SetPlayerAttachedObject or RemovePlayerAttachedObject
Temporary Attached Objects
This include introduces Temporary Attached Objects, which are attached objects designed to be automatically removed after a certain time. An example usage of this would be attaching particle objects that disappear after a few seconds.
Usage
pawn Code:
SetPlayerTempAttachedObject(playerid, time, modelid, boneid, Float:fOffsetX, Float:fOffsetY, Float:fOffsetZ, Float:fRotX, Float:fRotY, Float:fRotZ, Float:fScaleX, Float:fScaleY, Float:fScaleZ, materialcolor1, materialcolor2);
There is also one callback.
Callbacks
pawn Code:
forward OnTempAttachedObjectDestroy(playerid, index);
Data Functions
pawn Code:
// Returns the unique per-player-slot ID of the attached object (not the model ID)
GetPlayerAttachedObjectID(playerid, index);
// Returns the Bone ID of the attached object
GetPlayerAttachedObjectBone(playerid, index);
// Returns the Model ID of the attached object
GetPlayerAttachedObjectModel(playerid, index);
// Stores the offset values of the attached object, passed by reference
GetPlayerAttachedObjectOffset(playerid, index, &Float:fOffsetX, &Float:fOffsetY, &Float:fOffsetZ);
// Stores the rotation values of the attached object, passed by reference
GetPlayerAttachedObjectRot(playerid, index, &Float:fRotX, &Float:fRotY, &Float:fRotZ);
// Stores the scale values of the attached object, passed by reference
GetPlayerAttachedObjectScale(playerid, index, &Float:fScaleX, &Float:fScaleY, &Float:fScaleZ);
// Stores the material color values of the attached object, passed by reference
GetPlayerAttachedObjectColor(playerid, index, &materialcolor1, &materialcolor2);
To manually remove a temporary attached object, you can use the normal RemovePlayerAttachedObject function. However if you want the removal to also call OnTempAttachedObjectDestroy, you can use:
pawn Code:
// "aoid" is not optional and must always be -1
RemovePlayerTempAttachedObject(playerid, index, aoid);
Other Functions
pawn Code:
// Returns true if the attached object in the index is a temporary attached object
IsPlayerAttachedObjectTemp(playerid, index);
// Returns the first open attached object index for a player (works for normal attached objects too)
GetFreePlayerAttachedObjectSlot(playerid);
// Returns the number of temporary attached objects a player has
GetTempAttachedObjectCount(playerid);
// Returns the total number of attached objects a player has (normal and temporary)
GetAttachedObjectCount(playerid);
// Returns the index of the oldest temporary attached object
GetOldestTempAttachedObject(playerid);
// Returns the index of the most recently added temporary attached object
GetNewestTempAttachedObject(playerid);
// Set the bone ID of the attached object
SetPlayerAttachedObjectBone(playerid, index, bone);
// Set the model ID of the attached object
SetPlayerAttachedObjectModel(playerid, index, modelid);
// Set the offset coordinates of the attached object (won't work for attached objects that are currently moving)
SetPlayerAttachedObjectOffset(playerid, index, Float:fOffsetX, Float:fOffsetY, Float:fOffsetZ);
// Set the rotation of the attached object (won't work for attached objects that are currently moving)
SetPlayerAttachedObjectRot(playerid, index, Float:fRotX, Float:fRotY, Float:fRotZ);
// Set the scale of the attached object
SetPlayerAttachedObjectScale(playerid, index, Float:fScaleX, Float:fScaleY, Float:fScaleZ);
// Set the material color of the attached object
SetPlayerAttachedObjectColor(playerid, index, materialcolor1, materialcolor2);
Moving Attached Objects
Much like moving objects, you are now able to move player attached objects! It works for both player attached objects and temporary attached objects. Simply use the function below.
Usage
pawn Code:
MovePlayerAttachedObject(playerid, index, Float:OffsetX, Float:OffsetY, Float:OffsetZ, Float:Speed);
Callback
pawn Code:
// Called when the attached object stops moving. Does not handle returns.
OnPlayerAttachedObjectMoved(playerid, index);
pawn Code:
// Returns true if the attached object is currently moving
IsPlayerAttachedObjectMoving(playerid, index);
// Gets the tick rate for moving attached objects
AOX_GetTickRate();
// Sets the tick rate for moving attached objects
AOX_SetTickRate(tickrate);
The default tick rate is 15. For smoother movement but possibly worse server performance, set the tick rate lower. For more choppy movement but possibly better server performance, set the tick rate higher. Although I haven't tested this yet, different tick rates may affect the speed of the moving attached object.
There are several things that can interrupt a moving attached object. These include removing the attached object manually, having it removed automatically if it's a temporary attached object, aiming a sniper with the weapon zoom fix, and replacing it with a completely new attached object. These limited conditions mean that you can do some pretty interesting things with a moving attached object, like change its model ID or scale values while it's moving.
Weapon Zoom Fix
If you've played on a server with attached objects, you may have noticed how when aiming with a Sniper, the objects sometimes obstruct your view. With this include, aiming with a Sniper, Rocket Launcher, Heat Seeker, or Camera will now remove temporary attached objects and restore them after you stop aiming. It will be noticeable by all players when your attached objects are removed. This feature is optional, and if you want you can disable it entirely with this function:
pawn Code:
// Toggles the Weapon Zoom Fix on or off (1 or 0)
ToggleRemoveAOWeaponZoom(playerid, toggle);
// Example Usage
public OnPlayerConnect(playerid)
{
// Disable upon player connect
ToggleRemoveAOWeaponZoom(playerid, 0);
return 1;
}
pawn Code:
// Toggles the Weapon Zoom Fix for normal attached objects on or off (1 or 0)
ToggleRemoveNormAOWeaponZoom(playerid, toggle);
// Example Usage
public OnPlayerConnect(playerid)
{
ToggleRemoveNormAOWeaponZoom(playerid, 1);
return 1;
}
http://www.youtube.com/watch?v=OEoGg...ature=youtu.be
Here's an example video showing how the Weapon Zoom Fix works.
Notes
- * If all attached object slots are filled, the oldest temporary attached object will be replaced. If all attached object slots are filled by normal attached objects, the temporary attached object won't be added.
- Temporary Attached Objects are compatible with normal attached objects, and you can have both of them attached to you at the same time without conflicts.
- Specifying -1 for the "time" parameter of SetPlayerTempAttachedObject will make the temporary attached object never expire
- Timing out and reconnecting will no longer keep the attached objects and now destroys them upon connecting.
- The default tick rate for moving player attached objects is 15.