SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 01/05/2015, 01:37 AM   #1
Abagail
High-roller
 
Join Date: Dec 2013
Location: GetPlayerPos(playerid, pos); Scripter/Mapper.
Posts: 3,438
Reputation: 409
Default Actors!(0.3.7 RC6)

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:
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:
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.

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.

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.

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.
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.

Last edited by Abagail; 22/08/2016 at 09:26 PM.
Abagail is offline   Reply With Quote
Old 01/05/2015, 01:43 AM   #2
LMaxCo
Big Clucker
 
Join Date: Dec 2014
Location: SA-MP Forums - Powered by VBulletin.
Posts: 158
Reputation: 11
Default Re: Actors!(0.3.7 RC6)

Hohohohoho, That's really usefull for me REP+
LMaxCo is offline   Reply With Quote
Old 01/05/2015, 01:48 AM   #3
Abagail
High-roller
 
Join Date: Dec 2013
Location: GetPlayerPos(playerid, pos); Scripter/Mapper.
Posts: 3,438
Reputation: 409
Default Re: Actors!(0.3.7 RC6)

Quote:
Originally Posted by LMaxCo View Post
Hohohohoho, That's really usefull for me REP+
Thanks!
Abagail is offline   Reply With Quote
Old 01/05/2015, 09:25 AM   #4
AzaMx
Huge Clucker
 
AzaMx's Avatar
 
Join Date: Aug 2014
Location: moon
Posts: 369
Reputation: 49
Default Re: Actors!(0.3.7 RC6)

Thanks, usefull tutorial <3
AzaMx is offline   Reply With Quote
Old 01/05/2015, 09:26 AM   #5
hamzajaved780
Big Clucker
 
hamzajaved780's Avatar
 
Join Date: Jan 2015
Location: Karachi
Posts: 179
Reputation: 14
Default Re: Actors!(0.3.7 RC6)

Very nice , but can I apply recordings to actors.
__________________
hamzajaved780 is offline   Reply With Quote
Old 01/05/2015, 09:30 AM   #6
Tamer
High-roller
 
Tamer's Avatar
 
Join Date: Nov 2011
Location: Turkey
Posts: 1,200
Reputation: 169
Default Re: Actors!(0.3.7 RC6)

Remove the RC* from your post, there's no RC anymore as it is released.
__________________
The three stages of truth:

- Ridicule.
- Violent opposition.
- Acceptance.


Quote:
The greatest hypnotist on the planet Earth is an oblong box in the corner of the room. It is constantly telling us what to believe is real. If you can persuade people that what they see with their eyes is what there is to see you've got them. you know because they'll laugh in your face of an explanation that portrays the biggest picture of what's happening... and they have.
Tamer is offline   Reply With Quote
Old 01/05/2015, 09:31 AM   #7
AIped
Gangsta
 
AIped's Avatar
 
Join Date: Feb 2011
Location: Netherlands
Posts: 788
Reputation: 46
Default Re: Actors!(0.3.7 RC6)

Ah...i hope this stops getting the same questions in each topic over and over again.
__________________
Want some traffic?

http://forum.sa-mp.com/showthread.php?t=587634
AIped is offline   Reply With Quote
Old 01/05/2015, 09:46 AM   #8
AIped
Gangsta
 
AIped's Avatar
 
Join Date: Feb 2011
Location: Netherlands
Posts: 788
Reputation: 46
Default Re: Actors!(0.3.7 RC6)

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)
__________________
Want some traffic?

http://forum.sa-mp.com/showthread.php?t=587634
AIped is offline   Reply With Quote
Old 01/05/2015, 10:53 AM   #9
Alpay0098
Huge Clucker
 
Alpay0098's Avatar
 
Join Date: Oct 2014
Location: Behind ya :o
Posts: 290
Reputation: 20
Default Re: Actors!(0.3.7 RC6)

Does it work on SAMP 0.3.7 RC4-2?
Alpay0098 is offline   Reply With Quote
Old 01/05/2015, 10:55 AM   #10
Dragony92
Banned
 
Join Date: Feb 2011
Location: Belgrade, Serbia
Posts: 587
Reputation: 60
Default Re: Actors!(0.3.7 RC6)

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?
Dragony92 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Actors ATomas Scripting Help 17 30/04/2015 05:55 PM
Any voice actors? Lucky™ Everything and Nothing 4 22/01/2015 01:02 PM
NPC < Bots vs Actors > RSX General 6 25/09/2010 08:38 PM
Looking for actors for a SA:MP Movie. Sabotage Screenshots and Videos 0 20/08/2010 08:29 AM
The Desert [Looking for actors] eXtreme72 Screenshots and Videos 43 22/11/2008 03:26 PM


All times are GMT. The time now is 09:32 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.