Basic non monster npc mapping entitie.
Moderator: InsideQC Admins
13 posts
• Page 1 of 1
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.
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.
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.
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.
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.
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: Select all
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 all
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: Select all
/*
============
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: Select all
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.
-

ceriux - Posts: 2223
- Joined: Sat Sep 06, 2008 3:30 pm
- Location: Indiana, USA
Kinda busy, putting finishing touches on hse1m1.bsp but I'll try to make time to check this out tomorrow.
-

Dr. Shadowborg - InsideQC Staff
- Posts: 1110
- Joined: Sat Oct 16, 2004 3:34 pm
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.)
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.)
-

Dr. Shadowborg - InsideQC Staff
- Posts: 1110
- Joined: Sat Oct 16, 2004 3:34 pm
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!
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!
-

Dr. Shadowborg - InsideQC Staff
- Posts: 1110
- Joined: Sat Oct 16, 2004 3:34 pm
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;
?
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;
?
-

ceriux - Posts: 2223
- Joined: Sat Sep 06, 2008 3:30 pm
- Location: Indiana, USA
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.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC
(LordHavoc)
-

frag.machine - Posts: 2090
- Joined: Sat Nov 25, 2006 1:49 pm
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:
to this:
and then setting the map entity's npc_menu field to whatever you want.
Re: Different menus can be done as simply as changing this bit in npc_use(); from this:
- Code: Select all
// if we hits an npc, then yays, we can talk to him!
self.npc_menu = 1;
to this:
- Code: Select all
// 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.
-

Dr. Shadowborg - InsideQC Staff
- Posts: 1110
- Joined: Sat Oct 16, 2004 3:34 pm
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/dow ... -src-files
-

ceriux - Posts: 2223
- Joined: Sat Sep 06, 2008 3:30 pm
- Location: Indiana, USA
13 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest