[Include] actor_plus » Useful functions/callbacks for actors
#1

actor_plus
v5.0.2

Hey.
This is a simple include which give you some functions to manipulate actors and interact with them more easily. This include differentiates dynamic actors from static actors. You must specify this when using the functions below. By the way, if you don't have streamer ; you doesn't have to specify if the actor is dynamic or not.
I recommed to have YSI (from ******) library for better performance (the include use y_iterate and y_timers when they are included before). Also using streamer and dynamic actors can improve performance too.

I'll copy/paste the «documentation» which already on GitHub. I recommend to read it, the presentation is more clear.
https://github.com/Dayrion/actor_plu...ster/README.md

Description
An include with a bunch of useful functions and callback for actors. Functions returning 1 on success, 2 for specific success, 0 on failure or cellmin for specific failure. Please, check the wiki for more specific informations.

Documentation

Constant
Can not be redefined
  • MULTIPLE_TARGET_FOUND: Returned by GetNearestActorForPlayer or GetNearestActorByCoord when multiple actors are found and when return_multiple_target is set to true
  • DEFAULT_ACTOR_VALUE: Using this one instead of any other value result taking the value from the actor.
  • DEFAULT_CHECKING_TIME: Used to detect OnPlayerTargetActor.
  • ALL_VALUES_INCLUDED: If ALL_VALUES_INCLUDED is returned by a function, it means it will appear at every stage (like interior or virtual world).
  • DEFAULT_ACTOR_REPLACEMENT: Time before an actor is being re-placed at his old position.
  • AP_DEBUG_ENABLED: If some debugs printed messages are needed
  • MAX_ANIMATION_LIBRARY_LENGTH: Maximum animation library length name
  • MAX_ANIMATION_NAME_LENGTH: Maximum animation length name
  • DEFAULT_IS_DYNAMIC_PARAMETER: Set to true if streamer is included otherwise, it set to false
Can be redefined
  • DEFAULT_ACTOR_DRAW_DISTANCE: Distance that label is displayed | (type: float)
  • MAX_ACTOR_LABEL_LENGTH: Max length for a text in a label | (type: integer)
  • DEFAULT_ACTOR_COLOR: Default actor color text | (type: hexadecimal)
  • DEFAULT_ACTOR_COLOR_NAME: Default actor color name | (type: hexadecimal)
  • DONT_DETECT_OPTA: You can define it before the include to deactivated OnPlayerTargetActor detection (which using timer) | (type: N/A)
  • DEFAULT_TEXT_RANGE_DETECTION: This allows you to change the distance at which the actor (for OnPlayerTextNearActor only) is detected | (type: float)

General functions
PHP код:
native RespawnActor(actoridbool:isdynamic DEFAULT_IS_DYNAMIC_PARAMETER);
native SetActorSkin(actoridskinidbool:isdynamic DEFAULT_IS_DYNAMIC_PARAMETER);
native IsActorDead(actoridbool:isdynamic DEFAULT_IS_DYNAMIC_PARAMETER);
native GetActorSkin(actoridbool:isdynamic DEFAULT_IS_DYNAMIC_PARAMETER);
native ActorPlaySound(actoridsoundidFloat:xFloat:yFloat:zFloat:max_rangebool:isdynamic DEFAULT_IS_DYNAMIC_PARAMETER);
native SetActorName(actorid, const actor_name[], bool:displaybool:contain_id falsebool:isdynamic DEFAULT_IS_DYNAMIC_PARAMETER);
native GetActorName(actoridactor_name[], length sizeof(actor_name), bool:isdynamic DEFAULT_IS_DYNAMIC_PARAMETER);
native ToggleActorName(actoridbool:togglebool:isdynamic DEFAULT_IS_DYNAMIC_PARAMETER);
native GetActorTextLabel(actoridtext[], length sizeof(text), bool:isdynamic DEFAULT_IS_DYNAMIC_PARAMETER);
native GetActorLabelColor(actoridbool:ToRGB falsebool:isdynamic DEFAULT_IS_DYNAMIC_PARAMETER); // output -> RGBA
native GetActorNameColor(actoridbool:ToRGB falsebool:isdynamic DEFAULT_IS_DYNAMIC_PARAMETER); // output -> RGBA
native SetActorLabelColor(actoridcolorbool:isdynamic DEFAULT_IS_DYNAMIC_PARAMETER);
native SetActorNameColor(actoridcolorbool:isdynamic DEFAULT_IS_DYNAMIC_PARAMETER);
native ActorHasAttachedLabel(actorid, &bool:name_displayed false, &bool:text_displayed falsebool:isdynamic DEFAULT_IS_DYNAMIC_PARAMETER);
native UpdateAttachedActor3DTextLabel(actorid, const text[], colorbool:isdynamic DEFAULT_IS_DYNAMIC_PARAMETER);
native DestroyActor3DTextLabel(actoridbool:isdynamic DEFAULT_IS_DYNAMIC_PARAMETER);
native SetActorChatBubble(actoridtext[], colorFloat:drawdistanceexpiretimebool:isdynamic DEFAULT_IS_DYNAMIC_PARAMETER); 
Functions - Streamer dependency
PHP код:
native Attach3DTextLabelToActor(actorid, const text[], bool:isdynamiccolorFloat:OffsetXFloat:OffsetYFloat:OffsetZFloat:drawdistancetestlos 0worldid DEFAULT_ACTOR_VALUEinteriorid DEFAULT_ACTOR_VALUEplayerid DEFAULT_ACTOR_VALUEFloat:streamdistance STREAMER_3D_TEXT_LABEL_SDareaid DEFAULT_ACTOR_VALUEpriority 0bool:store_string true);
// Used to get the real internal actor id used by SA-MP
native GetInternalActorIDForPlayer(forplayeridactorid);
// In addition to the streamer
native GetDynamicActorInterior(actorid);
native SetDynamicActorInterior(actoridinteriorid);
native DestroyAllDynamicActors(serverwide);
native CountDynamicActors(serverwide);
native UpdateDynamicActorForPlayer(playerid);
native CountStreamedActorForPlayer(playeridserverwide);
native STREAMER_TAG_AREA GetDynamicActorArea(actorid);
native SetDynamicActorArea(actoridSTREAMER_TAG_AREA areaid);
native GetDynamicActorPriority(actorid);
native SetDynamicActorPriority(actoridpriority);
native GetInternalActorIdForPlayer(forplayeridactorid); 
Functions - Non-Streamer dependency
PHP код:
native Attach3DTextLabelToActor(actoridtext[], colorFloat:OffsetXFloat:OffsetYFloat:OffsetZFloat:drawdistancevirtualworld DEFAULT_ACTOR_VALUEtestlos 0bool:store_string true);
native SetActorInvulnerable(actoridinvulnerable true); // Force actor re-stream
native SetActorVirtualWorld(actoridvworld); // Force actor re-stream
native SetActorFacingAngle(actoridFloat:ang); // Force actor re-stream
native CountStaticActors(); 
Useful functions (none include needed)
PHP код:
native GetNearestActorForPlayer(playerid, &bool:isdynamic falsetype SEARCH_TYPE_ALLbool:return_multiple_target false);
native GetNearestActorByCoord(Float:xFloat:yFloat:z, &bool:isdynamic falsetype SEARCH_TYPE_ALLbool:return_multiple_target falseFloat:max_range INVALID_RANGE_ID);
native Float:GetActorDistanceFromPoint(actoridFloat:xFloat:yFloat:zbool:isdynamic DEFAULT_IS_DYNAMIC_PARAMETER);
native IsPlayerInRangeOfActor(playeridactoridFloat:range 2.0bool:isdynamic DEFAULT_IS_DYNAMIC_PARAMETER);
native IsPlayerAimingActor(playeridactoridbool:isdynamic DEFAULT_IS_DYNAMIC_PARAMETER);
native IsActorInPlayerFacingAngle(playeridactoridFloat:max_angle 90.0bool:isdynamic DEFAULT_IS_DYNAMIC_PARAMETER);
native GetActorSpawnInfo(actorid, &skinid, &Float:fX, &Float:fY, &Float:fZ, &Float:fAnglebool:isdynamic DEFAULT_IS_DYNAMIC_PARAMETER);
native GetActorAnimationName(actoridanimlib[], size_animlib sizeof(animlib), animname[], size_animname sizeof(animname)); // Static actors only
native GetActorAnimation(actoridanimlib[], size_animlib sizeof(animlib), animname[], size_animname sizeof(animname), &Float:fDelta, &loop, &lockx, &locky, &freeze, &time); // Static actors only
native ToggleActorAnimationLoop(actoridbool:toggle); // Static actors only
native bool:IsActorPlayingAnimation(actoridbool:isdynamic DEFAULT_IS_DYNAMIC_PARAMETER);
native CountAllActors(); 
Type of research:
  • SEARCH_TYPE_DYNAMIC: Search only for dynamics actors
  • SEARCH_TYPE_STATIC: Search only for statics actors
  • SEARCH_TYPE_ALL: Search for dynamics and statics actors

Per-players functions (Pawn RakNet dependency)
PHP код:
native HideActorForPlayer(forplayeridactoridhide_typebool:isdynamic DEFAULT_IS_DYNAMIC_PARAMETER);
native BringBackActorForPlayer(forplayeridactoridbool:isdynamic DEFAULT_IS_DYNAMIC_PARAMETER);
native SetActorHideTypeForPlayer(forplayeridactoridhide_typebool:isdynamic DEFAULT_IS_DYNAMIC_PARAMETER);
native RemoveAllHiddenActorForPlayer(playerid);
native ApplyActorAnimationForPlayer(forplayeridactoridrepeated_animationanimlib[], animname[], Float:fDeltalooplockxlockyfreezetimebool:isdynamic DEFAULT_IS_DYNAMIC_PARAMETER);
native ClearActorAnimationsForPlayer(forplayeridactoridbool:isdynamic DEFAULT_IS_DYNAMIC_PARAMETER);
native SetActorPosForPlayer(forplayeridactoridfake_position_typeFloat:xFloat:yFloat:zFloat:anglebool:isdynamic DEFAULT_IS_DYNAMIC_PARAMETER);
native BringBackActorPosForPlayer(forplayeridactoridbool:isdynamic DEFAULT_IS_DYNAMIC_PARAMETER); 
Player Flags
Hide type
  • HIDE_TYPE_NONE: Default value
  • HIDE_TYPE_ONE_TIME: The actor will be hidden one time and reappear when it be streamed
  • HIDE_TYPE_PERMANENT: The actor will be hidden until the script make it come back even if the player re-stream the actor

Repeated animation type
  • ANIMATION_PLAY_NONE: Default value
  • ANIMATION_PLAY_ONE_TIME: The actor will play an animation one time and stop it when it be streamed even if the animation is looped
  • ANIMATION_PLAY_PERMANENT: The actor will permently play the same animation. Restream the actor doesn't stop the process

Per players positions type
  • FAKE_POSITION_NONE: Default value
  • FAKE_POSITION_ONE_TIME: The actor will be placed, one time, at the specified coordinates. Re-stream the actor will place him at server sided coordinates
  • FAKE_POSITION_PERMANENT: The actor will be placed at specified coordinates. Re-stream it won't change anything the coordinates.

Callbacks
PHP код:
forward OnPlayerShotActor(playeridactoridweaponidbool:IsDynamicActor);
forward OnPlayerTargetActor(playeridactoridweaponid);
forward OnPlayerStopTargetActor(playeridactoridweaponid);
forward OnPlayerMakeDamageToActor(playeriddamaged_actoridFloat:amountweaponidbodypartbool:deathbool:IsDynamicActor);
forward OnActorDeath(actoridkilleridreasonbool:IsDynamicActor);
forward OnActorSpawn(actoridbool:IsDynamicActor);
forward OnPlayerStreamForActor(forplayeridactoridactor_flagsbool:IsDynamicActor); // Pawn RakNet dependency
forward OnActorVirtualWorldChange(actoridoldvwnewvwbool:IsDynamicActor);
forward OnPlayerTextNearActor(playeridactoridtext[], bool:IsDynamicActor);
forward OnDynamicActorInteriorChange(actoridoldinteriornewinteriorid); 
Explanations
  • OnPlayerShotActor: Called when a player shot an actor even if the actor is invulnerable
  • OnPlayerTargetActor: Called when a player stop aiming an actor.
  • OnPlayerStopTargetActor: Called when a player aim an actor.
  • OnPlayerMakeDamageToActor: Called when a player damage an actor with a firearm. bool:death is set to true when the actor will die after processing damage.
    Returning 0 to this call prevent applying damage to the actor.
  • OnActorDeath: Called when a actor die. Set actor's HP to 0 trigger this callback too.
  • OnActorSpawn: Called when a player spawn (is created).
  • OnPlayerStreamForActor: Called when a player stream IN an actor even if the actor is hidden for the player.
    Important: actor_flags should be used with different flags type defined below
  • OnActorVirtualWorldChange: Called when a virtualworld is set to an actor.
  • OnPlayerTextNearActor: Called when a player chat near an actor
  • OnDynamicActorInteriorChange: Called when an interior is set to a dynamic actor.
Download: https://github.com/Dayrion/actor_plu...actor_plus.inc
You need to use the latest version of Zeex's compiler because of implicit 4D arrays. You can find the download here: https://github.com/pawn-lang/compiler/releases
Zeex's compiler is an improved version of the actual compiler with a lot of bugfixs and new features (like 4D arrays).



My english is a mess, I apologize for that. Any tips, comments, whatever can make me go further will be appreciated.
Reply
#2

it's github not githud
Reply
#3

Quote:
Originally Posted by rfr
Посмотреть сообщение
it's github not githud
Every freaking time I do this mistake. -.-
Reply
#4

Awesome!
Reply
#5

Great job, but why you didn't stream the name ?
Reply
#6

Quote:
Originally Posted by GuyYahood1
Посмотреть сообщение
Awesome!
Thanks!
Quote:
Originally Posted by chneubeul
Посмотреть сообщение
Great job, but why you didn't stream the name ?
Thanks you. What do you mean? Labels (text/name) are streamed if you use streamer.
Reply
#7

I like the fact that you're using bit flags.
Reply
#8

Quote:
Originally Posted by ThePhenix
Посмотреть сообщение
I like the fact that you're using bit flags.
Eheh, thanks!
Reply
#9

https://github.com/Dayrion/actor_plu...r_plus.inc#L24
this will trigger an error while compiling with default pawncc since #warning is a zeex compiler directive
Reply
#10

I didn't realize you could do this.

Код:
enum _:E_TYPE_SEARCH(<<= 1)
{
	SEARCH_TYPE_DYNAMIC = 1,
	SEARCH_TYPE_STATIC,
	SEARCH_TYPE_ALL = SEARCH_TYPE_DYNAMIC | SEARCH_TYPE_STATIC
}
Код:
I was looking at a few things here and this doesn't make sense to me.

			if(type & SEARCH_TYPE_STATIC)
			{
				foreach(new i : Static_Actors)
				{
					if(!IsPlayerInRangeOfPoint(playerid, range, Static_Actors[i][eapPosX], Static_Actors[i][eapPosY], Static_Actors[i][eapPosZ]))
						continue;
					if(actorid != INVALID_ACTOR_ID)
						return MULTIPLE_TARGET_FOUND;
					actorid = i;
				}
			}
Why would you do that? That pretty much makes this function useless if there is two or more actors. It should at least have an optional parameter to do what you are doing otherwise update your code to find the closest actor and return it.
Reply
#11

Quote:
Originally Posted by Pottus
Посмотреть сообщение
I didn't realize you could do this.

Код:
enum _:E_TYPE_SEARCH(<<= 1)
{
	SEARCH_TYPE_DYNAMIC = 1,
	SEARCH_TYPE_STATIC,
	SEARCH_TYPE_ALL = SEARCH_TYPE_DYNAMIC | SEARCH_TYPE_STATIC
}
Код:
I was looking at a few things here and this doesn't make sense to me.

			if(type & SEARCH_TYPE_STATIC)
			{
				foreach(new i : Static_Actors)
				{
					if(!IsPlayerInRangeOfPoint(playerid, range, Static_Actors[i][eapPosX], Static_Actors[i][eapPosY], Static_Actors[i][eapPosZ]))
						continue;
					if(actorid != INVALID_ACTOR_ID)
						return MULTIPLE_TARGET_FOUND;
					actorid = i;
				}
			}
Why would you do that? That pretty much makes this function useless if there is two or more actors. It should at least have an optional parameter to do what you are doing otherwise update your code to find the closest actor and return it.
- What's the problem with SEARCH_TYPE_ALL ?
- That's right. I added a parameter which allow the player to return MULTIPLE_TARGET_FOUND or the first actor in range.
Reply
#12

Update! actor_plus - beta v1.2.0 to beta v3.0.1
  • Major code restructurations [removing/adding code in v2.0.0 and v3.0.0]
  • Added per-players functions (Pawn RakNet dependency)
  • Added callbacks
  • A lot of bug fix
  • Updated documentation
Please, check the documentation (README.md) if you have any doubt or you want to know what was updated. Every propositions are welcome.
Thanks to @Jelly23 and @****** for the provided help! 😄
Reply
#13

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
- What's the problem with SEARCH_TYPE_ALL ?
- That's right. I added a parameter which allow the player to return MULTIPLE_TARGET_FOUND or the first actor in range.
It just seems to me you are trying to return too many possibilities in one function. That kind of information would be better with checking if any actors are actually in range. There is no need for MULTIPLE_TARGET_FOUND it doesn't make sense when the truth is you are simply lacking a fundamental function.

Код:
GetActorCountForPlayer();
The first actor is not always the closest actor which breaks the naming of your function.
Reply
#14

Quote:
Originally Posted by Pottus
Посмотреть сообщение
It just seems to me you are trying to return too many possibilities in one function. That kind of information would be better with checking if any actors are actually in range. There is no need for MULTIPLE_TARGET_FOUND it doesn't make sense when the truth is you are simply lacking a fundamental function.

Код:
GetActorCountForPlayer();
The first actor is not always the closest actor which breaks the naming of your function.
Well, that's why parameters are optional. I changed both functions by removing the range and changing its operation (the point where you was right ; my function has nothing to do with range). What do you think about it?
PHP код:
native GetNearestActorForPlayer(playerid, &bool:isdynamic falsetype SEARCH_TYPE_ALLbool:return_multiple_target false);
native GetNearestActorByCoord(Float:xFloat:yFloat:z, &bool:isdynamic falsetype SEARCH_TYPE_ALLbool:return_multiple_target false); 
Reply
#15

Looks more sensible now.
Reply
#16

Updating to 3.1.0

+ Added callbacks (OnPlayerTextNearActor - OnActorVirtualWorldChange - OnDynamicActorInteriorChange)
+ Major structuration code change
+ GetNearestActorForPlayer & GetNearestActorByCoord modifications
- Removing codes/comments

Include available here: https://github.com/Dayrion/actor_plu...actor_plus.inc
Reply
#17

OnActorVirtualWorldChange - OnDynamicActorInteriorChange

These callbacks seem a bit redundant because it is known when these functions are actually are used it would be silly to need to use a callback. What you should do is use CallRemoteFunction() instead so that other scripts are aware of the change.

Over all this is a 100 percent solid system.
Reply
#18

Quote:
Originally Posted by Pottus
Посмотреть сообщение
OnActorVirtualWorldChange - OnDynamicActorInteriorChange

These callbacks seem a bit redundant because it is known when these functions are actually are used it would be silly to need to use a callback. What you should do is use CallRemoteFunction() instead so that other scripts are aware of the change.

Over all this is a 100 percent solid system.
I knew it is redundant but who knows, someone can have a good idea ad make a good usage of this. Anyway, the CallRemoteFunction is a better idea which make this usefull.

Thanks you for your precious contribitious!
Reply
#19

Version 3.3.0 realesed. This is the first stable version. Any useful comments are still appreciated.
- https://github.com/Dayrion/actor_plu...actor_plus.inc

Quote:
Originally Posted by Spmn
Посмотреть сообщение
https://github.com/Dayrion/actor_plu...r_plus.inc#L24
this will trigger an error while compiling with default pawncc since #warning is a zeex compiler directive
The basic compiler is supported in this version. Thanks for your bug report.
Reply
#20

I have an excellent suggestion. Now that you have created this system you should create an actor builder filterscript using your own include as a base. This will lead to further development of not only a complementary filterscript but I am sure you will find new functions to aid in the development of a tool.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)