PDA

View Full Version : Droid NPC that follows the player?


Prime
06-14-2003, 03:55 PM
I am looking to create an SP NPC droid (r2 unit preferably) that follows the player. Is there an entry in the npcs.cfg file that I can use to create something like this? If there is nothing in there, is there another way I might be able to do it? Thanks for any help you can provide. :)

tFighterPilot
06-14-2003, 05:25 PM
I think you do it by a script.

jp-30
06-14-2003, 10:41 PM
It's been done in this thread;

http://www.lucasforums.com/showthread.php?s=&threadid=99244

Louis
06-14-2003, 10:46 PM
Well I'm kind of confused, is this for SP or MP? I guess you mean a SP droid following a player in MP? Well just got to jp's link.

razorace
06-15-2003, 12:38 AM
Originally posted by jp-30
It's been done in this thread;

http://www.lucasforums.com/showthread.php?s=&threadid=99244

He said SP. In addition, I don't think Code is as close to completion as you think.

To answer the question, it might be possible with some scripting but the SP part of the game is very limited in terms of things you can do with it.

Louis
06-15-2003, 01:13 AM
It is definately possible with scripting in SP. I know how to do it, I can tell this guy if he wants.

"He said SP." -- no, he didn't. He said a SP (adj) droid, he didn't specify if he wanted to do this in SP or MP, he just said the droid is from the SP game...so if he says he means he wants it in SP, then I can tell him how to do it.

Prime
06-15-2003, 01:29 AM
Thanks for the replies fellas.

Yep, I ment SP all around. Ideally, I just want a droid that follows the player around in SP. Can this be don't with any of the entries in the npcs.cfg file? Something that I could just copy and alter?

Louis
06-15-2003, 03:38 PM
No, the best way to do it is with scripting. I assume you know how to script if not let me know...I will reply back in a little while once I get to my scripting computer...

Louis
06-15-2003, 03:58 PM
OK, here's how you do it:

First, create your droid, near your info_player_start, or wherever you want the droid to start following the player. Next, make a trigger wherever you want the droid to start following your player(make a brush and texture it with the system/trigger texture), then add the key "usescript" and the value "yourscriptfolder/yourscript". Of course replace that with whatever folder you will use *within the script folder*, and then the name of the script itself, and without quotes. So in this example my script would be: base/scripts/mymap/followscript. Also, don't forget to add a targetname to your droid.

OK then next, just open up your followscript in BehaveEd and then do like this:

affect ( "droidtargetname", /*@AFFECT_TYPE*/ FLUSH )
{
set ( /*@SET_TYPES*/ "SET_BEHAVIOR_STATE", /*@BSTATE_STRINGS*/ "BS_FOLLOW_LEADER" );
set ( /*@SET_TYPES*/ "SET_LEADER", "kyle" );
}

I didn't test it, but that should do it.

If you want to stop the droid from following, just create another trigger and do something like this:

affect ( "droidtargetname", /*@AFFECT_TYPE*/ FLUSH )
{
set ( /*@SET_TYPES*/ "SET_LEADER", "NULL" );
}

EDIT: I forgot one thing, you can use this in your script:

set ( /*@SET_TYPES*/ "SET_FOLLOWDIST", 200.000 );

That way it will set how far he follows, in Raven's scripts they use 200.000 but you could use anything you want.

Louis
06-15-2003, 10:05 PM
Hah, I tested it, it didn't work. What you need to do is just edit the npcs.cfg and either change r2d2 entry or create a new one ( http://www.geocities.com/kengomaps/tutorials.html )...just change the playerTeam to player.

Prime
06-16-2003, 02:59 AM
Awesome. I'll give that a try. Thanks for taking the time to explain all that to me. It is much appreciated :)

lassev
06-16-2003, 09:40 AM
Originally posted by Louis
example my script would be: base/scripts/mymap/followscript. Also, don't forget to add a targetname to your droid.


I don't know about the rest of that post, considering if it should work or not, but at least the targetname should be NPC_targetname.

Scripting is always trying and then trying harder.

tFighterPilot
06-16-2003, 11:07 AM
Yeah, very important to make it npc_targetname and not targetname. I fell for this, it was irritating.

Louis
06-16-2003, 11:37 AM
Haha my mistake, the scripting that I showed you works perfectly as long as you remember to set a NPC_targetname to your NPC entity. Right now I have a droid following me with no editing of the npcs.cfg file, and I must say, I think it's easier and very easy to control.

Prime
06-16-2003, 11:13 PM
Originally posted by Louis
Hah, I tested it, it didn't work. What you need to do is just edit the npcs.cfg and either change r2d2 entry or create a new one ( http://www.geocities.com/kengomaps/tutorials.html )...just change the playerTeam to player. I tried doing this, and the droid pops up okay when I spawn it, but he has a gun sticking out of him. I changed the playerteam to player, and tried it with both "enemyteam neutral", and "enemyteam enemy", and the both had the gun problem. Is there way way I can get rid of the gun? Is there something else I need to edit in the NPCS.cfg? :confused:

Louis
06-16-2003, 11:54 PM
To get rid of the gun, affect the droid NPC with this:

set ( /*@SET_TYPES*/ "SET_WEAPON", /*@WEAPON_NAMES*/ "WP_NONE" );

Prime
06-17-2003, 12:05 AM
Originally posted by Louis
To get rid of the gun, affect the droid NPC with this:

set ( /*@SET_TYPES*/ "SET_WEAPON", /*@WEAPON_NAMES*/ "WP_NONE" ); I am pretty new to scripting. Where would I do something like this? Can this only be done with custom maps, or can I do it with a "npc spawnable" entity on any map? Thanks again for your help. :p

lassev
06-17-2003, 03:45 AM
How did you succeed in giving the r2 a gun in the first place? Hmm, interesting idea. I have one r5 with a very nice scripted behavior, but with no painscript at all... Maybe I could give it in a painscript some nice, big gun like a repeater, or something. Do you know if it can shoot with the gun?

Louis
06-17-2003, 11:42 AM
Well...yeah, I tested this myself, and he does have a gun. I guess if you set it to be on the player's side and not neutral, then it automatically get's the blaster. It kind of sticks out the front of it, so it actually looks like it's maybe part of him or something :p

If I ever have need of a droid, I will do it by scripting. The main reason I suggested not editing the npcs.cfg file is because that will cause other problems (plus, every R2 unit that you have will follow you, and I am not sure you want that!).

I explained how to do scripting briefly in my *long* post on this thread. However you may want to hop over to www.geocities.com/kengomaps/tutorials , there is a lot about scripting there.

A basic run down of what I would suggest doing is:

1. If you want to keep the R2 unit on the player's side and not neutral that's fine (i.e., you want to edit the npcs file)...just make sure you don't have any R2's you will not want to follow the player. In this case you will need a script anyway, because you have to get rid of the gun.

2. If you don't want to edit the npcs.cfg file, then follow the script in my first post, using BS_FOLLOW_LEADER.

So, assuming you have to write a script either way, decide which one you want to do (1 or 2). Then, you will want to open up BehavEd (in your GameData/Tools directory by default) and then start scripting. There are tons of scripting tutorials around, like I said before, so I am not going to write out the whole thing :)

The basic steps would be:

1. Make sure you have the key NPC_targetname and any value you want on your NPC entity, I am assuming droidtest for this example.

2. Create a new script in BehavEd or notepad (personally I don't like BehavEd and I perfer just scripting in Notepad, but you probably don't want to do that ;) ).

3. In your script, create an "affect" that will affect your droidtest (your NPC_targetname). This addresses your droid so it knows what NPC to change.

4. Next, create the things you want to actually affect the droid with. If you wish to just take away his gun for example, you would use a "set" command and SET_WEAPON then hit re-evaluate and then select WP_NONE. If you decided to not edit the npcs file, then you will need different scripting instead of the weapon example above. This is explained in my first post. (basically, you will need to set the BS [behavior state] to BS_FOLLOW_LEADER, set the leader as kyle, and then set how far you want the droid to follow with SET_FOLLOWDIST).

Hope that helps...you just have to decide how you want to do it. After you get used to scripting though, this will all become second nature.

Prime
06-17-2003, 10:06 PM
I'm hoping to have a spawnable R2 unit which works on the normal SP maps, as well as any custom maps. That's why I'm keen on having to set it up in NPCs.cfg, because then I can "npc spawn" it. By making an new entry, I can alter the default R2 without all the other R2s being screwed up. I guess scripting won't be able to handle this sort of thing? I sort of assumed that a script was associated with a specific map. Am I out of luck for something like this?

Once again, thanks for your great and helpful responses, Louis. You have certainly gone beyond the call of duty :)

lassev, my gun-totting R2 certainly does fire. I spawned a stormtrooper, and R2 took him out. Well, eventually. He couldn't hit the broad side of a barn :D

Louis
06-18-2003, 12:14 PM
You would fire your script with a trigger -- probably a trigger_once, meaning it can be fired only once in a map. So every time you spawned an R2 unit that you wanted to follow the player, then you would have to trigger the follow script to run. By created a new NPC entry for the R2 following unit, then you could spawn it any number of times and it would always follow you. Check out emon's tutorial at http://joediting.cjb.net/newnpcs.html -- so then you could create like r2d2follow NPC or something like that and it would always follow the player. I am not sure if you can disable weapons in the NPCS file, but maybe someone else could help me with that...maybe you could try weapon 0 or weapon none in the npc's definition.

BTW, no problem about doing this...I love scripting it's my favorite part, so not every day do you get to help someone with it since not many people use it, unfortunately. I am more fascinated by the scripting/npc/modding side of the SP world rather than actually mapping.

Prime
06-18-2003, 06:31 PM
Originally posted by Louis
You would fire your script with a trigger -- probably a trigger_once, meaning it can be fired only once in a map. So every time you spawned an R2 unit that you wanted to follow the player, then you would have to trigger the follow script to run. By created a new NPC entry for the R2 following unit, then you could spawn it any number of times and it would always follow you. Check out emon's tutorial at http://joediting.cjb.net/newnpcs.html -- so then you could create like r2d2follow NPC or something like that and it would always follow the player. I am not sure if you can disable weapons in the NPCS file, but maybe someone else could help me with that...maybe you could try weapon 0 or weapon none in the npc's definition. I have successfully made a new entry in the NPCS.cfg file to add my new droid. When I spawn him in-game, he follows the player around just like I want. The only problem that remains is the gun. If I can get rid of that, I am good to go. Could I create a script that could run from the console to turn the gun off? Then, I could bind a key to the script so that when I spawn the droid, it automatically turns off the gun. I don't know if this is possible or not.