01.05.2015, 00:37
(
Last edited by Abagail; 22/08/2016 at 08:26 PM.
)
Actors:
What is an actor?
An actor is basically a game generated pedestrian synced by a client. This is way less server-sided than let's say an NPC and as such can handle less but can have more. But what actors are good for is having a static job such as bar tending, serving casino chips, working at pizza parlors, etc. And the best thing is, they don't take up player slots !
Additionally, a streamer for actors has already been introduced by Emmet_ as found here allowing you even more than 1000(the default limit) actors!
Creating and destroying actors
Creating, and destroying actors is very easy to do. All you need to do is use the CreateActor function and the server will do the rest.
Simply:
pawn Code:
native CreateActor(modelid, Float: x, Float: y, Float: z, Float: Rotation);
- modelid - The model / skin to create the actor with.
- Float: x - The original X spawn coordinate.
- Float: y - The original Y spawn coordinate.
- Float: z - The original Y spawn coordinate.
- Float: Rotation - The original rotation / facing angle.
pawn Code:
native DestroyActor(actorid);
Applying Animations
Since actor's don't use player slots, there is a special function to apply / clear an animation for them.
The parameters are with the exception of the actorid(normally playerid) parameter symmetrical to the ApplyAnimation function.
pawn Code:
(actorid, animlib[], animname[], Float:fDelta, loop, lockx, locky, freeze, time)
1 - The animation was applied.
0 - The function failed to apply the animation
NOTE: In R3 if the loop flag is enabled (and the animation is still running), any players that stream in after the animation is initially applied will see the actor apply the animation(it only reapplies for them). This is not the case in R1 and R2.
Clearing Animations
Exactly like ApplyActorAnimation, ClearActorAnimations uses the same parameters as the original function with the exception of the actorid parameter.
pawn Code:
native ClearActorAnimations(actorid);
(List taken from SAMP wiki)
- SetActorPos: Set the position of an actor.
- GetActorPos: Get the position of an actor.
- SetActorFacingAngle: Set the facing angle of an actor.
- GetActorFacingAngle: Get the facing angle of an actor.
- SetActorVirtualWorld: Set the virtual world of an actor.
- ApplyActorAnimation: Apply an animation to an actor.
- ClearActorAnimations: Clear any animations that are applied to an actor.
- GetPlayerCameraTargetActor: Get the ID of the actor (if any) a player is looking at.
- IsActorStreamedIn: Checks if an actor is streamed in for a player.
- OnActorStreamIn: Called when an actor streams in for a player.
- OnActorStreamOut: Called when an actor streams out for a player.
- OnPlayerGiveDamageActor: Called when a player damages an actor.
pawn Code:
forward OnPlayerGiveDamageActor(playerid, damaged_actorid, Float:amount, weaponid, bodypart);
Things to consider
- In RC6-R1 DestroyActor() will not hide the actor's appearence from any streamed players until that player restreams in the according area. This is fixed in RC6-R2.
- In RC6-R1 and R2 animations will not be reapplied for players who stream in after the animation is applied. This is fixed in R3.
- You can't set / get an actor's interior as explained by Kalcor here:
Quote:The interior IDs are GTA's streaming worlds (client streamed). The virtual world IDs are SA-MP's streaming worlds (on the server).
It's much better to set each GTA interior in it's own virtual world on the server. That means when you teleport a player in to a GTA interior, you also change the player's virtual world to some arbitrary number. That means the same GTA interior can be reused over and over. Players using the same GTA interior in a different virtual world won't be able to see each other or any actors set to a different virtual world.
You don't need to alter the actor's GTA interior because players set to that interior will always see other players, NPCs and actors that are in the same interior as them.
Why can't...
Q: I interact with an actor's interior?
A:
Quote:
The interior IDs are GTA's streaming worlds (client streamed). The virtual world IDs are SA-MP's streaming worlds (on the server).
It's much better to set each GTA interior in it's own virtual world on the server. That means when you teleport a player in to a GTA interior, you also change the player's virtual world to some arbitrary number. That means the same GTA interior can be reused over and over. Players using the same GTA interior in a different virtual world won't be able to see each other or any actors set to a different virtual world. You don't need to alter the actor's GTA interior because players set to that interior will always see other players, NPCs and actors that are in the same interior as them. |
A:
Quote:
Actors can't just walk anywhere because the server isn't running the game. There is no way to know how long it takes to get from point A to point B if there are unknown obstructions blocking the path.
That's why NPCs ended up having to use recordings. The only alternative was have players (which are running the game) sync them, and even the players do not have all of the San Andreas map data loaded at any given time. It didn't seem like a good idea (in a game with 100's of players in the server) to have players responsible for syncing the actors. Players could easily mess with that data and disrupt the game. So I can't easily add a function to make actors run to a certain point because it would not sync in all cases -- and scripters here would be crying "bug, bug!" even though it's just a limitation of what SA-MP is working with. |
These functions although not documented officially in the RC / release thread were actually added in the official 0.3.7 release.
pawn Code:
native SetActorHealth(actorid, Float:health);
native GetActorHealth(actorid, &Float:health);
native SetActorInvulnerable(actorid, invulnerable = true);
native IsActorInvulnerable(actorid);
native IsValidActor(actorid);
Extended damage information!(final version only)
Within the final release, several components are introduced allowing us(while remaining rather simple) health and damage functions. However, it should be noted that the actors themselves are NOT able to produce any damage at all. Players are able to damage vulnerable actors. By default, Actors are invulnerable unless the function is specifically used.
I apologize for not explaining every function however I plan on expanding this as nessacary, and simply also because most of the functions have a matching function just without the word "actor" and replaced by "player" or another keyword.