Index | FAQ | Search | Memberlist | Usergroups | Profile | Log in to check your private messages | Log in | Register

Basic non monster npc mapping entitie.

| Inside3d Forums Forum Index -> QuakeC Programming

View previous topic :: View next topic
Author | Message
--- | ---
ceriux Joined: 06 Sep 2008 Posts: 969 Location: Florida, USA |

Posted: Wed Nov 25, 2009 10:42 pm Post subject: Basic non monster npc mapping entitie. |

ok im making a mapping entitie which has a model, loops 1 animation and when used displays a menu. all iv really gotten to work so far is displaying the menu... which is why i posting here. ill post up the code on here and also a source. (it includes the .qc files, 1 map and one model.)
ok first things first these are the menu's. this is how you implement them:
ok first make a new .qc file called NPC_MENUS.qc. paste this in it.

Code:
void() Menus = { if (!self.npc_menu) return; if (self.npc_menu = 1)
centerprint(self, "Hello! I am a test NPC\n Press 1 to exit\n");
};
void(float inp) Select =
{
if (!self.npc_menu)
return;
if (self.npc_menu == 1)
{
if (inp == 1)
{
self.npc_menu = 0;
self.impulse =0;
}
}
Menus();
};

this is where what every npc says or the tasks they give are made this isnt the only part of this menu. next we have to go to client.qc
and go to the bottom of playerpostthink.
and paste this at the bottom.

Code:
Select();

that should be it for now. next move onto weapons.qc
and go down to impulsecommands.
change it to look as follows here makes it to where when a menu is up you use the select impulses for choices and dialog in the "menus" each menu can be different with my menu while still usings the same impulse commands as the others.
change impulsecommands to look like this.

Code:
/* ============ ImpulseCommands ============ */
void() ImpulseCommands =
{
if (self.npc_menu < 1) // if menu's are on use second impulse commands
{
if (self.impulse >= 1 && self.impulse <= 8)
W_ChangeWeapon ();
if (self.impulse == 9)
CheatCommand ();
if (self.impulse == 10)
CycleWeaponCommand ();
if (self.impulse == 11)
ServerflagsCommand ();
if (self.impulse == 12)
CycleWeaponReverseCommand ();
if (self.impulse == 255)
QuadCheat ();
self.impulse = 0;
}
else // If they don't have a class do this
{
SecondImpulse(); // call special impulse commands below
}
};
void() SecondImpulse =
{
if (self.impulse == 1)
Select(1);
};

and we're finished with this part of the code. next ill show you how i made the actual mapping entitie.
make a new .qc file named NPC.qc this is where i will make all of my new npcs as well for now just paste this here.

Code:
void() npc_idle = { if (time == time + 1) { if (self.frame == 0)
{
self.frame = self.frame + 1;
if (self.frame == 5)
self.frame = 1;
}
}
};
void() npc_test =
{
precache_model ("progs/npc1.mdl");
self.solid = SOLID_BBOX;
setmodel (self, "progs/npc1.mdl");
//self.frame = 1;
npc_idle();
droptofloor();
if (other.impulse = 13)
{
other.npc_menu = 1;
}
};

this should be all you need. ill post the actual source below.
http://www.filefront.com/14997851/npcqc.zip
thank you to anyone who helps.
_________________
QuakeDB - Quake ModDB Group

Back to top |

ceriux Joined: 06 Sep 2008 Posts: 969 Location: Florida, USA |

Posted: Fri Nov 27, 2009 2:43 am Post subject: |

can someone please reply to this ... thanks... _________________ QuakeDB - Quake ModDB Group

Back to top |

Dr. Shadowborg Inside3D Staff Joined: 16 Oct 2004 Posts: 726 |

Posted: Fri Nov 27, 2009 3:39 am Post subject: |

Kinda busy, putting finishing touches on hse1m1.bsp but I'll try to make time to check this out tomorrow. _________________ "Roboto suggests Plasma Bazooka."

Back to top |

ceriux Joined: 06 Sep 2008 Posts: 969 Location: Florida, USA |

Posted: Fri Nov 27, 2009 3:52 am Post subject: |

thank you for at least trying to take a look when you can. _________________ QuakeDB - Quake ModDB Group

Back to top |

Dr. Shadowborg Inside3D Staff Joined: 16 Oct 2004 Posts: 726 |

Posted: Fri Nov 27, 2009 4:35 am Post subject: |

Just skimming, haven't actually tried it yet, but two recommendations: 1. Change postthink call to Select(); to something like Select(0); this will fix compiler warnings about not enough parms being provided. 2. Add a self.menu_finished_time or some such so that you don't spam centerprints too frequently. This will make it more multi / coop friendly. (I use a value of about 0.2 in Hellsmash which is roughly about the time it takes for a centerprint to disappear in winquake.)
_________________
"Roboto suggests Plasma Bazooka."

Back to top |

Dr. Shadowborg Inside3D Staff Joined: 16 Oct 2004 Posts: 726 |

Posted: Fri Nov 27, 2009 8:32 pm Post subject: |

Heh, didn't realize you were asking for help with this until I downloaded the file and tried it. Anyhow, here's the source code with a compiled progs.dat to go with it. Just drop it right into your "base" folder that was contained in your original zip. I've done the best I can to properly comment the code in there so you can hopefully follow what I've done. (Also, a lot of the comments are just me being ass, disregard those / delete them, etc.)
http://tlb.quakedev.com/files/drs_npcqc_fix0red.zip
Features:
* Use impulse 13 to interact. (I'm assuming this is your normal use key anyway)
* NPC will turn to face the player who's interacting with it. (Yes other players can steal his attention.)
* If you turn to not face him, aren't visible to him, or are outside of a radius of 120 units, he will quit interacting with you. (or if you press 1.)
Cons:
You will need to modify him a bit if you want him to do stuff like HL Scientists / Barneys. (follow you, fight monsters, etc.) 'course, this should go without saying.
Enjoy!
_________________
"Roboto suggests Plasma Bazooka."

Back to top |

ceriux Joined: 06 Sep 2008 Posts: 969 Location: Florida, USA |

Posted: Fri Nov 27, 2009 10:55 pm Post subject: |

awesome thank you so much! _________________ QuakeDB - Quake ModDB Group

Back to top |

ceriux Joined: 06 Sep 2008 Posts: 969 Location: Florida, USA |

Posted: Sat Nov 28, 2009 12:00 am Post subject: |

iv noticed that the npc_use automatically calls menu 1 is there a way i can make it call self.menu == self.menu; ? because the way i was setting it up is i was going to make the menu different for each npc. that way i could just copy the exisiting npc code and modify the menu to match each npcs dialog. that way i could easily make some only say things others call a shop menu and others give out quests simply by calling a different menu depending on the npc?
edit : could i give each npc its own number like self.npc_num = 1 so in npc_use i could set it to self.menu == self.npc_num;
?
_________________
QuakeDB - Quake ModDB Group

Back to top |

frag.machine Joined: 25 Nov 2006 Posts: 728 |

Posted: Sat Nov 28, 2009 12:14 am Post subject: |

I'd suggest you to put all npc dialogs in a text file and use FRIK_FILE to read it. Much less code to keep and more flexible to add new quests, for example. _________________ frag.machine - Q2K4 Project http://fragmachine.quakedev.com/

Back to top |

ceriux Joined: 06 Sep 2008 Posts: 969 Location: Florida, USA |

Posted: Sat Nov 28, 2009 12:42 am Post subject: |

i would, i dont know how to implement frikfile i wish that someone would make some kind of a small walkthrough or something on at least the basics of it. _________________ QuakeDB - Quake ModDB Group

Back to top |

Dr. Shadowborg Inside3D Staff Joined: 16 Oct 2004 Posts: 726 |

Posted: Sat Nov 28, 2009 1:46 am Post subject: |

You don't actually HAVE to resort to using an engine mod to do this. If you do it right you could do it so that it's internal to the map entity. Re: Different menus can be done as simply as changing this bit in npc_use(); from this:

Code:
// if we hits an npc, then yays, we can talk to him! self.npc_menu = 1;

to this:

Code:
// if we hits an npc, then yays, we can talk to him! self.npc_menu = trace_ent.npc_menu;

and then setting the map entity's npc_menu field to whatever you want.
_________________
"Roboto suggests Plasma Bazooka."

Back to top |

ceriux Joined: 06 Sep 2008 Posts: 969 Location: Florida, USA |

Posted: Sat Nov 28, 2009 2:37 am Post subject: |

nice thank you VERY much. _________________ QuakeDB - Quake ModDB Group

Back to top |

ceriux Joined: 06 Sep 2008 Posts: 969 Location: Florida, USA |

Posted: Tue Feb 09, 2010 7:18 am Post subject: |

i uploaded the source to this on moddb. just waiting for it to be verified . once it has been you can always find it here: http://www.moddb.com/groups/quakedb/downloads/npc-with-use-code-in-qc-src-files _________________ QuakeDB - Quake ModDB Group

Back to top |

Display posts from previous:

| Inside3d Forums Forum Index -> QuakeC Programming | All times are GMT
Page 1 of 1

Jump to:

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2004 phpBB Group