How To: Make a perfect NPC
I will discuss how to make the perfect NPC.
It'll be broken down into two sections: 1. Setting up an NPC 2. Setting up a bot. Setting Up An NPC Steps: 1. Making the ent 2. Making it solid 3. Making it take damage 4. Setting its model 5. Animating 6. Making NPC think correctly 7. Giving it a weapon Ok, here we go. 1. First lets make a function: Code:
Then lets make the entity: Code:
We also need to give the entity an origin, and also make the player *jump*, just for testing purposes. Code:
2. Ok the player is out of the way. Lets make it solid. Code:
3. Its solid, but invinsible. Lets also make it take damage: Code:
The health IS the health of the entity, but you should set it higher then normal. Ents seem to have less HP somehow. 4. Setting the model is as easy as this: Code:
I know setting the classname is not setting the model, but you should set it with a similar classname. 5. Ok, now lets give it a default animation. Code:
6. Making it think is SLIGHTLY harder. First you have to register its think in plugin_init: Code:
Now then, we need to make the entity start thinking: In the create NPC function: Code:
It needs to think VERY fast, in order to out run the server frames. This wont cause a whole lot of lag, since it is mostly handled in the engine. Now then, the npc_think function will be called whenever it thinks. You can do all sorts of shit in here. For instance, you can check if the HP has gone down, and make it bleed, play the right animation, etc. Or, you could make it walk around by giving it velocity and changing the animation. Above all, you must call the think function again: Code:
Everything else you do in here is your business. I'll put up some examples later of how to make it walk or shoot. 7. I'll show you how to add a weapon as well: Code:
the P model is the PLAYER model, which will generally work. I used an HL default weapon because my model was HLDM. Now then, lets put it all together: Code:
This is a working test function. You can easily take alter it to make an NPC of your choosing. Have fun with it! Making A Bot Making a bot, or an NPC that can move easily and takes up a slot, is as simple as 1 2 3. 1. Follow the guide above 2. replace "create_entity("info_target"" with engfunc(EngFunc_CreateFakeClient,"Onna") 3. Set the model of the new bot using the mod specific functions. You can now: Use the FM engfunc command, EngFunc_RunPlayerMove to make them move Act as if they are a normal player. Very simple! Have fun with it - Mel |
What's an NPC? :oops:
|
Non-Playable-Character.
You can use them in plugins to make like, a gunshop owner, or a store owner. |
Oh, that's awesome! I'll be sure to use this. :D
|
Thanks Twilight Suzuka!!
This helped me out a lot! |
1 Attachment(s)
Could I set it to make the NPC 'killable', or at least make it take damage?
Edit: Look @ what I did with it, hehe.. |
Yes, you can! I'll figure it out and post it soon. I just prefer friendly NPC's, ones that you cant kill for TSXMOD.
There is also a way to make your NPC act like an actual player, I'll get into that later. The real thing was making the aniimations work, the rest of it is extra. Hell, I made a realistic Scientist that walked around pretty good. |
nice job
|
Quote:
|
Set his takedamage field, give him some max health and health, and I think that'll about do it. Now you have to figure out how to make him flinch when we gets shot and how to make him die. ;-)
|
All times are GMT -4. The time now is 17:13. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.