[HELP]How to make a NPC do an Animation ---CLOSED---
#1

---CLOSED---
Reply
#2

Any errors?
Reply
#3

Quote:
Originally Posted by AndrewP
Any errors?
No, the NPC won't do the animation that's all.
Reply
#4

Quote:
Originally Posted by Seif_
ApplyAnimation(playerid,"PED","IDLE_CHAT",2.1,1,1, 1,1,0);
I'm gonna try putting it like that, but i doubt it will do anything.
Although i hope it does
Reply
#5

Most of the time animations wont work on first attempt ..maybe if you set a small timer after it spawned
the animation should work.

Anyway, do it twice ..at onplayerspawn ..you already have and with a timer

Edit: it might have to do something with if the npc is streamed in or not.
Reply
#6

I've tryed the timer with the applyanimation there too, but still nothing?
i added this:
forward animtimer(playerid);

public animtimer(playerid)
{
ApplyAnimation(playerid,"PED","IDLE_CHAT",2.1,1,1, 1,1,0);
ApplyAnimation(playerid,"PED","IDLE_CHAT",2.1,1,1, 1,1,0);
}
public OnPlayerSpawn(playerid)
{
if(IsPlayerNPC(playerid))
{
new npcname[MAX_PLAYER_NAME];
GetPlayerName(playerid, npcname, sizeof(npcname));
if(!strcmp(npcname, "NPC", true))
{
ApplyAnimation(playerid,"PED","IDLE_CHAT",2.1,1,1, 1,1,0);
ApplyAnimation(playerid,"PED","IDLE_CHAT",2.1,1,1, 1,1,0);
SetTimer("animtimer", 1000, true);
return 1;
}
}
}
Do the NPC Animations work if they are in a building that was added and that it isn't on the floor?
Do they have to be on the ground for it to work?
I just thought of this because when i'm far away and my line of sight can't see the building, but can see the NPC he does the falling animation, but it doesn't really fall.
Reply
#7

hmm.. try this callback here ; https://sampwiki.blast.hk/wiki/NPC:OnPlayerStreamIn

its for the npc script, put a SendCommand under the Onplayerstreamedin.
Make the command itself in your gamemode.
The command must set the animation

so something like this here;

in the npc script
Код:
public OnPlayerStreamIn(playerid)
{
    SendCommand("/animate");
  return 1;
}
in normal script under onplayercommandtext;
Код:
	if(strcmp(cmdtext, "/animate", true, 10) == 0)
	{ 
ApplyAnimation..blablabla (the kind of animation you want
good luck!
Reply
#8

That Is Player Streamed idea might actually work, but if not, this is the solution I came up when I had trouble with Animations & NPCs when I searched a while back for it over the SA-MP Forums:

Animations for NPCs must be looped so the NPC does the animation over and over again, only then does it work... But with that information, I tried looping animations for only about 3-5 seconds which then stops but kept the animation for the NPC. That was on a NPC that didn't move or anything though

But there was a helpful topic on this somewhere on these forums about NPC Animations, just search it out
Reply
#9

You need to pre load the animations.

Top of script:
pawn Код:
new gPlayerUsingLoopingAnim[MAX_PLAYERS];
new gPlayerAnimLibsPreloaded[MAX_PLAYERS];
Somewhere else:
pawn Код:
LoopingAnim(playerid,animlib[],animname[], Float:Speed, looping, lockx, locky, lockz, lp)
{
  gPlayerUsingLoopingAnim[playerid] = 1;
  ApplyAnimation(playerid, animlib, animname, Speed, looping, lockx, locky, lockz, lp);
}

PreloadAnimLib(playerid, animlib[])
{
    ApplyAnimation(playerid,animlib,"null",0.0,0,0,0,0,0);
}
Add these to OnPlayerConnect:
pawn Код:
public OnPlayerConnect(playerid)
{
  gPlayerUsingLoopingAnim[playerid] = 0;
    gPlayerAnimLibsPreloaded[playerid] = 0;
  return 1;
}
Example OnPlayerSpawn:
pawn Код:
public OnPlayerSpawn(playerid)
{
  if(!gPlayerAnimLibsPreloaded[playerid]) {
        PreloadAnimLib(playerid,"DANCING");
        gPlayerAnimLibsPreloaded[playerid] = 1;
    }

  if(!IsPlayerNPC(playerid)) return 0;

    new playername[64];
    GetPlayerName(playerid,playername,64);

    if(!strcmp(playername,"Example",true)) {
    SetSpawnInfo( playerid, 0, 87, 1203.9446,16.5226,1000.9219, 344.9598, 0, 0, 0, 0, 0, 0 );
    ShowPlayerMarkers(0);
    LoopingAnim(playerid,"DANCING","DAN_Loop_A",4.1,1,1,1,1,0);
    }
  return 1;
}
Hope this helps.
Reply
#10

I've done everything there and everytime i try to spawn it crashes :'(
Heres pic:
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)