Scripts / NPC run away help.

Author
Message
Catongokart
8
Years of Service
User Offline
Joined: 22nd Jan 2016
Location:
Posted: 23rd Jan 2016 00:07
Hello everyone. Sorry if this is not the place for this. I'm really bad at coding from scratch, but I find I can solve most of my issues with just modifying the stock code from GG. Im working on a research project. The game I'm trying to make will only be see by the participants of the study. What I need is some way to make NPCs that run away when shots are fired.
I thought I could be done with something resembling these lines but instead of making the npc go aggro, I want them to run away in fear.

-- Add this enemy as a point of aggro, alerting anyone near to join the fight
ai_aggro_entity = e
ai_aggro_x = g_Entity[e]['x']
ai_aggro_z = g_Entity[e]['z']
else
-- We cant see the player, but perhaps we are near someone that can
if ai_aggro_entity ~= nil then
tDistX = g_Entity[e]['x'] - ai_aggro_x
tDistZ = g_Entity[e]['z'] - ai_aggro_z

Sorry again if this is not where I need to ask for help.
PM
3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 23rd Jan 2016 12:32
Add this script to the NPC you want to run away.



In action



If you also want the NPC taking cover behind walls or something like this, look for script named "ai_take_cover.lua"
in smallG 's thread, their scripts can help you a lot.

3com
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics

PM
Pirate Myke
Forum Support
13
Years of Service
User Offline
Joined: 31st May 2010
Location: El Dorado, California
Posted: 23rd Jan 2016 17:26
Thank you 3com.
Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz, 2400 Mhz, 4 Core(s), 4 Logical Processor(s), 8gb RAM, Nvidia gtx660, Windows 7 Pro 64bit

HarryWever
3D Media Maker
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location: below Sea level
Posted: 23rd Jan 2016 19:11
Very nice 3com,

and did you really shoot that poor man in the back?

Harry
Harry
PM
3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 24th Jan 2016 10:30
Thanks guys.

Quote: "and did you really shoot that poor man in the back?"

That guy takes me walking around all the map.

3com
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics

PM
Catongokart
8
Years of Service
User Offline
Joined: 22nd Jan 2016
Location:
Posted: 29th Jan 2016 18:45
This is Amazing! Thank you 3com. You are a life saver. I'm I will be using this for research I am conducting at a university. If the findings get published I will make sure to gather your contact info and get you credit.
PM
3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 29th Jan 2016 19:32
You are welcome.

3com
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics

PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 29th Jan 2016 21:44
doesnt that just make them always run in 1 direction? i.e. the top right of the map, because you are always increasing the x and z values, you should use something like this to detect where the player is in relation and adjust accordingly


and why are you calling AIEntityStop(EntObjNo) and LookAtPlayer(e) while he's running away? that will cause the weird stop/start you see when they're running away.
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, AMD R9 200 series , directx 11
3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 30th Jan 2016 15:03
You're right, if you constantly control the position of the player, you can position the character accordingly.
So the script can be improved, but it belonged to the second part, remember he is a student and is investigating, well as to investigate, and while we will help as much as we can.

Quote: "and why are you calling AIEntityStop(EntObjNo) and LookAtPlayer(e) while he's running away? that will cause the weird stop/start you see when they're running away."


For this reason the effect of the character who can not walk normally, due he is hurt.
Sometimes I got the caracter stop suddenly and look at me, like saying, " ok, it is suffient, what do you want for me !", unfortunatelly I dont got for the video purpouse.

And besides where you are when I need you?
Just kidding mate, I know you're out a few days, good luck in whatever you're doing.

3com
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics

PM

Login to post a reply

Server time is: 2024-05-03 08:20:48
Your offset time is: 2024-05-03 08:20:48