Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**************************************************************************
- Copyright 2013 Ian Goodwin
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- *//////////////////////////////////////////////////////////////////////////
- /*
- native CreateArrow(Float: x, Float: y, Float: z, Float: target_x, Float: target_y, Float: stream_dist = DEFAULT_ARROW_DRAW_DISTANCE);
- native PointArrowAtPoint(arrowid, Float: x, Float: y);
- native DestroyArrow(arrowid);
- native SetArrowPos(arrowid, Float: x, Float: y, Float: z);
- native GetArrowPos(arrowid, &Float: x, &Float: y, &Float: z);
- native GetArrowRot(arrowid, &Float: rx, &Float: ry, &Float: rz);
- native PointArrowAtPlayer(arrowid, playerid);
- native PointArrowAtVehicle(arrowid, vehicleid);
- native PointArrowAtObject(arrowid, objectid);
- native SetArrowColor(arrowid, argb_color);
- */
- #define INVALID_ARROW_ID -1
- #define ARW_OBJECT_ID (1318)
- #define ARW_Z_ROT_OFFSET (90.0)
- #define DEFAULT_ARROW_DRAW_DISTANCE (200.0)
- #define MAX_ARROWS 100
- #if !defined ARROW_NO_STREAMER
- #tryinclude <streamer>
- #if !defined CreateDynamicObject
- #error streamer include not found, have you got streamer.inc in your includes folder?
- #endif
- #endif
- new gArrowObjectID[MAX_ARROWS] = { INVALID_ARROW_ID, ... };
- forward Float:arw_PointToPoint(Float:X, Float:Y, Float:PointX, Float:PointY);
- /*
- Function:
- CreateArrow
- Description:
- Creates an arrow at the given point, pointing to a target location.
- Param(s):
- x, y, z - Position to create the arrow.
- target_x, tagtet_y - Position to point the arrow at
- stream_dist - stream distance for the arrow (default DEFAULT_ARROW_DRAW_DISTANCE)
- Returns:
- Arrowid for the newly created arrow. (returned by CreateObject or CreateDynamicObject
- */
- stock CreateArrow(Float: x, Float: y, Float: z, Float: target_x, Float: target_y, Float: stream_dist = DEFAULT_ARROW_DRAW_DISTANCE)
- {
- for(new i = 0; i < MAX_ARROWS; i++)
- {
- #if !defined ARROW_NO_STREAMER
- gArrowObjectID[i] = CreateDynamicObject( ARW_OBJECT_ID, x, y, z,
- 0.0, -90, arw_PointToPoint(x, y, target_x, target_y)+ARW_Z_ROT_OFFSET,
- .streamdistance = stream_dist);
- return i;
- #else
- gArrowObjectID[i] = CreateObject( ARW_OBJECT_ID, x, y, z,
- 0.0, -90, arw_PointToPoint(x, y, target_x, target_y)+ARW_Z_ROT_OFFSET, stream_dist );
- return i;
- #endif
- }
- printf("Error: Arrow.inc::CreateArrow()::Tried to create too many arrows");
- return INVALID_ARROW_ID;
- }
- /*
- Function:
- DestroyArrow
- Description:
- Destroys the given arrow.
- Param(s):
- arrowid - The arrowid returned by "CreateArrow" function
- Returns:
- Value returned by CreateObject or CreateDynamicObject
- */
- stock DestroyArrow(arrowid)
- {
- if(gArrowObjectID[arrowid] != INVALID_ARROW_ID)
- {
- #if !defined ARROW_NO_STREAMER
- DestroyDynamicObject( gArrowObjectID[arrowid] );
- gArrowObjectID[arrowid] = INVALID_ARROW_ID;
- return 1;
- #else
- DestroyObject( gArrowObjectID[arrowid] );
- gArrowObjectID[arrowid] = INVALID_ARROW_ID;
- return 1;
- #endif
- }
- printf("Error: Arrow.inc::DestoyArrow()::Tried access invalid arrow Arrowid: %i", arrowid);
- return INVALID_ARROW_ID;
- }
- /*
- Function:
- SetArrowPos
- Description:
- Sets a new position for the given arrow.
- Param(s):
- arrowid - The arrowid returned by "CreateArrow" function.
- x, y, z - The new position for the arrow to be placed.
- Returns:
- Value returned by SetObjectPos or SetDynamicObjectPos
- */
- stock SetArrowPos(arrowid, Float: x, Float: y, Float: z)
- {
- if(gArrowObjectID[arrowid] != INVALID_ARROW_ID)
- {
- #if !defined ARROW_NO_STREAMER
- return SetDynamicObjectPos( gArrowObjectID[arrowid], x, y, z );
- #else
- return SetObjectPos( gArrowObjectID[arrowid], x, y, z );
- #endif
- }
- printf("Error: Arrow.inc::SetArrowPos()::Tried access invalid arrow Arrowid: %i", arrowid);
- return INVALID_ARROW_ID;
- }
- /*
- Function:
- GetArrowPos
- Description:
- Gets the current position for the given arrow.
- Param(s):
- arrowid - The arrowid returned by "CreateArrow" function.
- x, y, z - Variables to store the position of the arrow, passed by reference.
- Returns:
- Value returned by GetObjectPos or GetDynamicObjectPos
- */
- stock GetArrowPos(arrowid, &Float: x, &Float: y, &Float: z)
- {
- if(gArrowObjectID[arrowid] != INVALID_ARROW_ID)
- {
- #if !defined ARROW_NO_STREAMER
- return GetDynamicObjectPos( gArrowObjectID[arrowid], x, y, z );
- #else
- return GetObjectPos( gArrowObjectID[arrowid], x, y, z );
- #endif
- }
- printf("Error: Arrow.inc::GetArrowPos()::Tried access invalid arrow Arrowid: %i", arrowid);
- return INVALID_ARROW_ID;
- }
- /*
- Function:
- GetArrowRot
- Description:
- Gets the current rotation for the given arrow.
- Param(s):
- arrowid - The arrowid returned by "CreateArrow" function.
- x, y, z - Variables to store the rotation of the arrow, passed by reference.
- Returns:
- Value returned by GetObjectRot or GetDynamicObjectRot
- */
- stock GetArrowRot(arrowid, &Float: rx, &Float: ry, &Float: rz)
- {
- if(gArrowObjectID[arrowid] != INVALID_ARROW_ID)
- {
- #if !defined ARROW_NO_STREAMER
- return GetDynamicObjectRot( gArrowObjectID[arrowid], rx, ry, rz );
- #else
- return GetObjectRot( gArrowObjectID[arrowid], rx, ry, rz );
- #endif
- }
- printf("Error: Arrow.inc::GetArrowRot()::Tried access invalid arrow Arrowid: %i", arrowid);
- return INVALID_ARROW_ID;
- }
- /*
- Function:
- SetArrowColor
- Description:
- Sets a new color for the arrow
- Param(s):
- arrowid - The arrowid returned by "CreateArrow" function.
- argb_color - New color for the arrow, NOTE: ARGB format not RGBA
- Returns:
- Value returned by SetObjectMaterial or SetDynamicObjectMaterial
- */
- stock SetArrowColor(arrowid, argb_color)
- {
- if(gArrowObjectID[arrowid] != INVALID_ARROW_ID)
- {
- #if !defined ARROW_NO_STREAMER
- return SetDynamicObjectMaterial(gArrowObjectID[arrowid], 0, -1, "none", "none", argb_color);
- #else
- return SetObjectMaterial(gArrowObjectID[arrowid], 0, -1, "none", "none", argb_color);
- #endif
- }
- printf("Error: Arrow.inc::SetArrowColor()::Tried access invalid arrow Arrowid: %i", arrowid);
- return INVALID_ARROW_ID;
- }
- /*
- Function:
- PointArrowAtPlayer
- Description:
- Points the given arrow at the given playerid
- Param(s):
- arrowid - The arrowid returned by "CreateArrow" function.
- playerid - ID of the player to point at.
- Returns:
- 1 if playerid is connected.
- 0 otherwise.
- */
- stock PointArrowAtPlayer(arrowid, playerid)
- {
- if(gArrowObjectID[arrowid] != INVALID_ARROW_ID)
- {
- new
- Float: fTargetX, Float: fTargetY, Float: fTargetZ
- ;
- if( GetPlayerPos(playerid, fTargetX, fTargetY, fTargetZ) )
- {
- PointArrowAtPoint(gArrowObjectID[arrowid], fTargetX, fTargetY);
- return 1;
- }
- return 0;
- }
- printf("Error: Arrow.inc::PointArrowAtPlayer()::Tried access invalid arrow Arrowid: %i", arrowid);
- return INVALID_ARROW_ID;
- }
- /*
- Function:
- PointArrowAtVehicle
- Description:
- Points the given arrow at the given vehicle
- Param(s):
- arrowid - The arrowid returned by "CreateArrow" function.
- vehicleid - ID of the vehicle to point at.
- Returns:
- 1 if vehicleid is found.
- 0 otherwise.
- */
- stock PointArrowAtVehicle(arrowid, vehicleid)
- {
- if(gArrowObjectID[arrowid] != INVALID_ARROW_ID)
- {
- new
- Float: fTargetX, Float: fTargetY, Float: fTargetZ
- ;
- if( GetVehiclePos(vehicleid, fTargetX, fTargetY, fTargetZ) )
- {
- PointArrowAtPoint(gArrowObjectID[arrowid], fTargetX, fTargetY);
- return 1;
- }
- return 0;
- }
- printf("Error: Arrow.inc::PointArrowAtVehicle()::Tried access invalid arrow Arrowid: %i", arrowid);
- return INVALID_ARROW_ID;
- }
- /*
- Function:
- PointArrowAtObject
- Description:
- Points the given arrow at the given object
- Param(s):
- arrowid - The arrowid returned by "CreateArrow" function.
- objectid - ID of the object to point at.
- Returns:
- 1 if objectid is found.
- 0 otherwise.
- */
- stock PointArrowAtObject(arrowid, objectid)
- {
- if(gArrowObjectID[arrowid] != INVALID_ARROW_ID)
- {
- new
- Float: fTargetX, Float: fTargetY, Float: fTargetZ
- ;
- #if !defined ARROW_NO_STREAMER
- if( GetDynamicObjectPos(objectid, fTargetX, fTargetY, fTargetZ) )
- {
- PointArrowAtPoint(gArrowObjectID[arrowid], fTargetX, fTargetY);
- return 1;
- }
- #else
- if( GetObjectPos(objectid, fTargetX, fTargetY, fTargetZ) )
- {
- PointArrowAtPoint(gArrowObjectID[arrowid], fTargetX, fTargetY);
- return 1;
- }
- #endif
- return 0;
- }
- printf("Error: Arrow.inc::PointArrowAtObject()::Tried access invalid arrow Arrowid: %i", arrowid);
- return INVALID_ARROW_ID;
- }
- /*
- Function:
- PointArrowAtPoint
- Description:
- Points the given arrow at the given point
- Param(s):
- arrowid - The arrowid returned by "CreateArrow" function.
- x, y - The point, to point the arrow at
- Returns:
- This function does not return a value
- */
- stock PointArrowAtPoint(arrowid, Float: x, Float: y)
- {
- if(gArrowObjectID[arrowid] != INVALID_ARROW_ID)
- {
- new Float: fArrX, Float: fArrY, Float: fArrZ;
- #if !defined ARROW_NO_STREAMER
- GetDynamicObjectPos(gArrowObjectID[arrowid], fArrX, fArrY, fArrZ);
- return SetDynamicObjectRot(gArrowObjectID[arrowid], 0.0, -90.00000, arw_PointToPoint(fArrX, fArrY, x, y)+ARW_Z_ROT_OFFSET);
- #else
- GetObjectPos(gArrowObjectID[arrowid], fArrX, fArrY, fArrZ);
- return SetObjectRot(gArrowObjectID[arrowid], 0.0, -90.00000, arw_PointToPoint(fArrX, fArrY, x, y)+ARW_Z_ROT_OFFSET);
- #endif
- }
- printf("Error: Arrow.inc::PointArrowAtPoint()::Tried access invalid arrow Arrowid: %i", arrowid);
- return INVALID_ARROW_ID;
- }
- stock Float:arw_PointToPoint(Float:X, Float:Y, Float:PointX, Float:PointY)
- {
- new Float:fAngle;
- if(X > PointX && Y > PointY)
- fAngle = floatabs(atan2(floatsub(PointX, X), floatsub(PointY, Y)));
- if(X > PointX && Y <= PointY)
- fAngle = floatadd(floatabs(atan2(floatsub(Y, PointY), floatsub(PointX, X))), 270.0);
- if(X <= PointX && Y > PointY)
- fAngle = floatadd(floatabs(atan2(floatsub(PointY, Y), floatsub(X, PointX))), 90.0);
- if(X <= PointX && Y <= PointY)
- fAngle = floatadd(floatabs(atan2(floatsub(X, PointX), floatsub(Y, PointY))), 180.0);
- return fAngle >= 360.0 ? floatsub(fAngle, 360.0) : fAngle;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement