[Tutorial] Actors!(0.3.7 RC6)
#1

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);
Parameters:
  • 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.
And destroying an actor is just as easy:
pawn Code:
native DestroyActor(actorid);
With the only parameter being the ID of the actor as returned by CreateActor.

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)
Return Values:
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);
Misc functions

(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.
Misc callbacks
  • 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);
The only difference between this and the standard function is the "damaged_actorid" parameter.

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:
    Originally Posted by Kalcor
    View Post
    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'ts

Why can't...
Q: I interact with an actor's interior?
A:
Quote:
Originally Posted by Kalcor
View Post
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.
Q: I make actor's walk around?
A:
Quote:
Originally Posted by Kalcor
View Post
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.
Health functions!(final version only)

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);
You can use SetActorInvulnerable to omit an actor from taking damage. You can also now use IsValidActor similarly to IsPlayerConnected, or IsValidVehicle to validate the actor ID as being in use. The rest of the functions work the same as the player version, so no special explanations will be required.

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.
Reply
#2

Hohohohoho, That's really usefull for me REP+
Reply
#3

Quote:
Originally Posted by LMaxCo
View Post
Hohohohoho, That's really usefull for me REP+
Thanks!
Reply
#4

Thanks, usefull tutorial <3
Reply
#5

Very nice , but can I apply recordings to actors.
Reply
#6

Remove the RC* from your post, there's no RC anymore as it is released.
Reply
#7

Ah...i hope this stops getting the same questions in each topic over and over again.
Reply
#8

Okay...so about the streaming i want to understand correctly

Lets say a player is streamed in for the actor..and the actor has an animation like dead on the floor

will another player that streams in after that see the actor on the floor too if anim parameter set to true ?

(sorry i cant test it myself right now)
Reply
#9

Does it work on SAMP 0.3.7 RC4-2?
Reply
#10

Quote:
Originally Posted by Alpay0098
View Post
Does it work on SAMP 0.3.7 RC4-2?
Actors are added in RC6, so no.
There is official 0.3.7 version, why are you using RC4-2?
Reply
#11

How should I destroy actor by the HP's?
Reply
#12

pawn Code:
SetActorHealthEx(actorid, Float:health)
{
    if(health <= 0)
    {
        DestroyActor(actorid);
    }
    else SetActorHealth(actorid, health);
}
Reply
#13

Useful tutorial <3
Reply
#14

v nice tut, btw u forgot to add [url "]" in ur sign
Reply
#15

This is actually pretty useful, thanks man, REP+
Reply
#16

Update: it appears Kalcor has sneaked in a update to the actor system in with some simple health functions, along with IsValidActor. I have updated the tutorial with them but after checking the R3 include they seem to be missing, so I guess they're only present in the official release.
Reply
#17

I have to disagree with "I make actor's walk around?".
Because I managed to sync actors between players and make them walk around, they don't exists in areas where there are no players, but there is always actor near player, spawned actor have only one player to be synced with until that player leave certain radius of actor

Same thing as rockstar™ managed it in GTA IV and GTA V
Reply
#18

Good work!
Reply
#19

Is it possible to make them like peds, for example walking like in singleplayer and so players can kill them?
Reply
#20

Quote:
Originally Posted by Saddin
View Post
Is it possible to make them like peds, for example walking like in singleplayer and so players can kill them?
Everyone is asking the same question. Use NPCs for that. Actors are here so we can create static "NPC" which doesn't walk around.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)