Actors scripting spawning problem
#1

Hey, I'm a beginner scripter (like really beginner) and I started to mess around with actors lately. Now, I had some troubles and I did found a topic that talks about a similar problem here but the guy who made the topic has reported it as a bug, and I don't know if in my case it's a bug or it's just me being really stupid about it. So the problem is this;
I tried adding a few actors (6 I think?) in a club interior, and apply an animation to them (like dancing sitting etc) and I tried it a few times. In the first time, all the actors has appeared to me, but without any animation. Then, I looked in the forums and found a better way to spawn the actors, like,in the beginning I was just creating a variable for each actor, like this;
Код:
new DFCactor1;
new DFCactor2;
new DFCactor3;

public OnGameModeInit()
{
DFactor1= CreateActor(13,490.5765,-16.6661,1000.6797,12.1928);
if (!IsValidActor(DFactor1)) return DFactor1=CreateActor(13,490.5765,-16.6661,1000.6797,12.1928);
if (IsValidActor(DFactor1)) return ApplyActorAnimation(DFactor1,"DANCING","dance_loop",4.1,1,0,0,0,0);
// goes like this for every actor with different animations 
}
Now as I said before, I found a better way of creating the actors (at least that what they said), and did it like this;
Код:
enum actors{
DFactor1,
DFactor2,
DFactor3
}
new ActorID[actors];

public OnGameModeInit()
{
ActorID[FDactor1]=CreateActor(13,490.5765,-16.6661,1000.6797,12.1928);
if (!IsValidActor(ActorID[FDactor1])) return ActorID[FDactor1]=CreatActor(skinid,X,Y,Z,Xrotation);
if (IsValidActor(ActorID[FDactor1])) return ApplyActorAnimation(DFactor1,"DANCING","dance_loop",4.1,1,0,0,0,0);
// etc...
}
But then I tested it, and only the first actor has appeared in-game. Then, I reversed everything to as it was in the first time and it didn't spawn the actors too, it just spawned the first actor.

I don't know if the solution is that obvious and I'm being stupid or it's just a bug or something like that, but something doesn't work out here for me and I have no idea why. I would love to have some help from you and maybe gain a little bit of scripting knowledge as well.

NOTE: I did tried to post this topic on the "0.3.7 RC scripting" board but I couldn't do it for some reason
Reply
#2

Hi! I'm apologize in advance for my mistakes in eng language.

First thing what I want to tell you is that you can make the actors without unnecessary lines more than one. In PAWN language (similar like C++) exist something like array. Thanks to this fact you can make 10 actors with only one variable. For example:
Quote:

new ClubActors[50];

It's very simply and when you have to call some variables, you're going to write:
Quote:

ClubActors[0] = CreateActor(13,490.5765,-16.6661,1000.6797,12.192;
ClubActors[1] = CreateActor(13,490.5765,-16.6661,1000.6797,12.192;
ClubActors[2] = CreateActor(13,490.5765,-16.6661,1000.6797,12.192;
... etc.

Next step which you can to do is create a timer for player who's entering to interior. It's giving you a moment of time for create actors and apply on them animations.

For Example:
Quote:

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(newkeys == KEY_SPRINT) // Press sprint key
{
if(IsPlayerInRangeOfPoint(playerid, 2, x, y, z) // if someone is close doors etc.
{
SetPlayerInterior(playerid, 1);
SetPlayerPos(playerid, x, y, z);
SetPlayerFacingAngle(playerid, rot);
TogglePlayerControllable(playerid, false);
SetTimerEx("Unfreeze", 1000, false, "i", playerid);
}
}
return 1;
}

forward Unfreeze(playerid);
public Unfreeze(playerid)
{
TogglePlayerControllable(playerid, true);
}

It's work for me, try it and tell me if for you too.
Reply
#3

I know about arrays, I just wanted to name the actors so I'll know what actor do what. I'll try the timer though! (I'm using pickups for interiors by the way)

EDIT: Tried it, the actors still won't spawn, only the first one like before. I don't think it's related to the player's control, I think it just won't spawn it for some reason.
Reply
#4

Maybe put them all to one VirtualWorld? -https://sampwiki.blast.hk/wiki/SetActorVirtualWorld
Don't forget to SetPlayerVirtualWorld too. Try it and if it's still doesn't work, delete checking for InvalidActor, leave just CreateActor and ApplyAnimation
Reply
#5

Made them all in the same virtual world as well as the player and it still won't work. It's not the checking if the actor is valid because I've added the checking after the problem has appeared.
Reply
#6

PHP код:
new DFCactor[2];
public 
OnGameModeInit()
{
    
DFactor[00] = CreateActor(13490.5765, -16.66611000.679712.1928); // What does this actor do? (ex: shop clerk1)
    
DFactor[01] = CreateActor(13xyZa); // What does this actor do? (ex: shop clerk2)
    
    
for(new 0sizeof(DFCactor); i++)
    {
        
ApplyActorAnimation(DFCactor[i], "DANCING""dance_loop"4.110000);
    }
    return 
1;

You could do something like that, less code, more simple. Just replace "What does this actor do?" with whatever its role is so you can keep track.

And to save even more lines, like.. you could just use my custom function and just replace your code under OnGameModeInIt with the CreateActorEx

PHP код:
CreateActorEx(skinidFloat:XFloat:YFloat:ZFloat:Rotationvirtual_world 0vulnerable 0)
{
    new 
ActorEx CreateActor(skinidXYZRotation);
    
SetActorVirtualWorld(ActorExvirtual_world);
    
SetActorInvulnerable(ActorExvulnerable);
    return 
ActorEx;

As for the spawning issue, can you post your complete actor list of the ones that won't "show"
Reply
#7

It sounds as if, based on what changes you made to begin with, you have a "return" statement in your code. A return statement halts the sequential execution of that block of code at the return, therefore not executing the code after the return statement.
Reply
#8

Quote:
PHP код:
new DFCactor[2]; 
public 
OnGameModeInit() 

    
DFactor[00] = CreateActor(13490.5765, -16.66611000.679712.1928); // What does this actor do? (ex: shop clerk1) 
    
DFactor[01] = CreateActor(13xyZa); // What does this actor do? (ex: shop clerk2) 
     
    
for(new 0sizeof(DFCactor); i++) 
    { 
        
ApplyActorAnimation(DFCactor[i], "DANCING""dance_loop"4.110000); 
    } 
    return 
1

You could do something like that, less code, more simple. Just replace "What does this actor do?" with whatever its role is so you can keep track.

And to save even more lines, like.. you could just use my custom function and just replace your code under OnGameModeInIt with the CreateActorEx

PHP код:
CreateActorEx(skinidFloat:XFloat:YFloat:ZFloat:Rotationvirtual_world 0vulnerable 0

    new 
ActorEx CreateActor(skinidXYZRotation); 
    
SetActorVirtualWorld(ActorExvirtual_world); 
    
SetActorInvulnerable(ActorExvulnerable); 
    return 
ActorEx

As for the spawning issue, can you post your complete actor list of the ones that won't "show"

Yeah now when I think of it it will be easier to just add comments, so I will just use a big array for all the actors. And well, here's the code I got currently: (before I'll just make it a big array.)
PHP код:
new ActorClubDF1;
new 
ActorClubDF2;
new 
ActorClubDF3;
new 
ActorClubDF4;
new 
ActorBT;
new 
ActorBSmok;
new 
ActorSB;
new 
ActorBGuard;
new 
ActorBVIP1;
new 
ActorBVIP2;
public 
OnGameModeInit()
{
     
ActorClubDF1 CreateActor(13,490.5765,-16.6661,1000.6797,12.1928);
     if(!
IsValidActor(ActorClubDF1)) return ActorClubDF1 =CreateActor(13,490.5765,-16.6661,1000.6797,12.1928);
     if (
IsValidActor(ActorClubDF1)) return ApplyActorAnimation(ActorClubDF1,"DANCING","dance_loop",4.1,1,0,0,0,0);
     
ActorClubDF2 CreateActor(12,486.7554,-16.1958,1000.6797,112.2097);
     if (!
IsValidActor(ActorClubDF2)) return ActorClubDF2 =CreateActor(12,486.7554,-16.1958,1000.6797,112.2097);
     if (
IsValidActor(ActorClubDF2)) return ApplyActorAnimation(ActorClubDF2,"DANCING","dance_loop",4.1,1,0,0,0,0);
     
ActorClubDF3 CreateActor(40,486.8140,-13.5157,1000.6797,330.1222);
     if (!
IsValidActor(ActorClubDF3)) return ActorClubDF3 CreateActor(40,486.8140,-13.5157,1000.6797,330.1222);
     if (
IsValidActor(ActorClubDF3)) return ApplyActorAnimation(ActorClubDF3,"DANCING","dance_loop",4.1,1,0,0,0,0);
     
ActorClubDF4 CreateActor(98,489.2302,-11.6520,1000.6797,346.3948);
     if (!
IsValidActor(ActorClubDF4)) return ActorClubDF4 CreateActor(98,489.2302,-11.6520,1000.6797,346.3948);
     if (
IsValidActor(ActorClubDF4)) return ApplyActorAnimation(ActorClubDF4,"DANCING","dance_loop",4.1,1,0,0,0,0);
     
ActorBT CreateActor(194,501.7032,-20.4166,1000.6797,86.8270);
     if (!
IsValidActor(ActorBT)) return ActorBT =CreateActor(194,501.7032,-20.4166,1000.6797,86.8270);
     
ActorBSmok CreateActor(47,506.6170,-4.7541,1000.6797,93.5925);
     if (!
IsValidActor(ActorBSmok)) return ActorBSmok CreateActor(47,506.6170,-4.7541,1000.6797,93.5925);
     if (
IsValidActor(ActorBSmok)) return      ApplyActorAnimation(ActorBSmok,"SMOKING","F_smklean_loop",4.1,1,0,0,0,3000);
     
ActorSB CreateActor(67,499.9749,-16.8377,1001,178.4166);
     if (!
IsValidActor(ActorSB)) return ActorSB =CreateActor(67,499.9749,-16.8377,1001,178.4166);
     
ActorBGuard CreateActor(164,491.1101,-24.5151,1000.6797,6.9407);
     if (!
IsValidActor(ActorBGuard)) return ActorBGuard =CreateActor(164,491.1101,-24.5151,1000.6797,6.9407);
     
ActorBVIP1 CreateActor(214,486.7241,-21.5209,1003.1094,357.3969);
     if (!
IsValidActor(ActorBVIP1)) return ActorBVIP1CreateActor(214,486.7241,-21.5209,1003.1094,357.3969);
     
ActorBVIP2 CreateActor(216,482.7236,-25.4783,1003.1094,359.3814);
     if (!
IsValidActor(ActorBVIP2)) return ActorBVIP2 CreateActor(216,482.7236,-25.4783,1003.1094,359.3814);
     if (
IsValidActor(ActorBVIP2)) return ApplyAnimation(ActorBVIP2,"BAR","dnk_stndF_loop",4.0,1,0,0,0,0);
    
    return 
1;

Quote:

It sounds as if, based on what changes you made to begin with, you have a "return" statement in your code. A return statement halts the sequential execution of that block of code at the return, therefore not executing the code after the return statement.

I haven't really understand what you meant exactly, do you mean I have placed a return statement too early in the code? Or am I missing one somewhere? (I think you meant I have placed a return statement too early what I really don't think I have done.)
Reply
#9

Bump
Reply
#10

Bump 2'nd \
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)