• Setting non-player Model Animations?
    7 replies, posted
  • Avatar of SharpCoder
  • Hello, I am trying to spawn a non-player object (I have tried both [B]npc_citizen[/B] and [B]prop_physics[/B]), and the goal is to force it into an animation. For my specific purposes, I need the object (which happens to be a player/npc model) to enter the "sitchair1" animation (which I know the model in question has). [I]Question[/I] How can I spawn an object of type (NPC/prop_physics), adorned with a player/NPC model, and forced into an animation? Here is a code snippet of what I am currently trying to use. It may be useful to note that, no matter what I do, the NPC (when I tried this with entity type: npc_citizen), just stands around instead of entering an animation. [B]LUA Snippet[/B] [lua] local npcModel = ents.Create("npc_citizen") npcModel:SetPos(npcModelPos); npcModel:Spawn(); npcModel:SetModel("models/humans/suits2/male_09.mdl"); local sit = npcModel:LookupSequence("sitchair1") or npcModel:LookupSequence("headcrabbed"); if ( sit == nil or sit <= 0 ) then print("Didn't find animation"); else print("Found animation!"); end npcModel:SetSequence( sit ); [/lua] Thank you for your time, I appreciate any suggestions!
  • Avatar of ArmageddonScr
  • In my testing I haven't gotten SetSequence to work serverside, try running it on the client if you haven't
  • Avatar of SharpCoder
  • [QUOTE=ArmageddonScr;35228007]In my testing I haven't gotten SetSequence to work serverside, try running it on the client if you haven't[/QUOTE] :D Well damn... That certainly fixed it! :D Thank you so much. I spent way longer than I should have trying to get that working. Thank you!!!!!!
  • Avatar of SharpCoder
  • [QUOTE=gonzalolog;35231879]So...it works only on clientside???[/QUOTE] Yessir. What I ended up doing was making a client side concommand that searches for my specific entity model and forces it into an animation. When needed, I have the server call this concommand on the specific player(s) though you could design any number of other ways to accomplish this.
  • Avatar of SharpCoder
  • [QUOTE=ArmageddonScr;35235035]A more professional way to do that would be usermessages[/QUOTE] Yeah that is far more elegant. In fact, I tried doing that at first but my target-entity was becoming nullified somehow when I attempted to pass it through a usermessage. I thought it might be due to the fact that the entity was created server-side, and thus the reference was not applicable client side. I haven't worked extensively with complex objects via: usermessages though, so I am not entirely sure what the issue was.
  • Avatar of ArmageddonScr
  • I'm 80% sure it was because the client didn't know the entity existed yet. Creating a timer.Simple(0 would have fixed it