News | Forum | People | FAQ | Links | Search | Register | Log in
Coding Help
This is a counterpart to the "Mapping Help" thread. If you need help with QuakeC coding, or questions about how to do some engine modification, this is the place for you! We've got a few coders here on the forum and hopefully someone knows the answer.
First | Previous | Next | Last
Preach Is Da Man! 
Gotta love it when Preach "preaches"! So much information in a couple hundred words. 
Monster Vs Monster 
Coming back to
1 - specific monsters are on another "team" and attack other monsters/players who are not on that "team"

In the first post we've adjusted the rules for REACTION in combat so that our teams don't fight amongst themselves. But getting them to pro-actively attack the other team on their own initiative is another story. I see two big problems

Problem 1: In regular quake, the task of searching for a client who the monster might be able to see and ruling them out if they are in a part of the map not visible from the monster's position is entirely offloaded to the engine. The function is called "checkclient" and it does the whole thing in one go.

Because it's in the engine, your mod can't change how it functions. So you'd have to write something new from scratch in QuakeC to replace it. The engine has access to additional data that QuakeC can't get at, and it exploits some of that data in checkclient - so you can't even create an exact copy in QuakeC as a baseline. It's a very tall order.

Supposing you solve problem 1, problem 2 is a more practical one. You create your map full of rooms, each populated by squads of monsters from team A facing a squad from team B. The player spawns in, and your new AI kicks in. Across the map, team A fights with team B, even when the player is nowhere nearby. A victorious team emerges in each fight, and for the player the only evidence of all this groundbreaking AI is a pile of corpses from team A, and some half-health monsters from team B.

This is probably not what you had in mind - more likely you were wanting the player to be present each time the teams fight so they can see and engage in the spectacle.

That's why I would recommend you CHEAT instead. Rather than creating brilliant AI, just script the fights a bit. Have an entity who looks for monsters with a specific targetname, and assigns them an enemy with the same targetname from the other team. Make sure you trigger this entity when the player is approaching the battlefield. And when a monster kills a monster with the same targetname, make it retrigger to pick them another target. 
Attenuation 
Also how can I edit ATTN_NONE ATTN_NORM ATTN_IDLE etc?

The good news is that while the values of
ATTN_NONE/ATTN_NORM/ATTN_IDLE/ATTN_STATIC make it look like there are just discrete values for attenuation, actually the final parameter to sound is a float, and you can supply any decimal starting at 0.0 and going up to (but not including) 4.0.

One of the confusing things is getting a handle on exactly how the scale works. It's actually a backwards scale - the higher the number, the smaller the distance that the sound travels. ATTN_NONE is the absence of attenuation, which means that the sound transmits across the entire level at full volume. If you still want a drop off, but slower than normal sounds, why not try a value of 0.5 instead of ATTN_NORM?

Tiny detail: ATTN_NORM and volume of 1.0 do have a magic benefit compared to other values, although it's a fairly minor one. They actually require less network bandwidth to transmit in a packet, because they are regarded as the "baseline" values, and the protocol only transmits variation from the baseline. In single player scenarios this doesn't make a difference, but it's an interesting quirk to note. 
Thx Preach 
For Monster Vs Monster teams I believe the Qreate mod added monster teams, and a few other misc mod did too?

"Across the map, team A fights with team B, even when the player is nowhere nearby. A victorious team emerges in each fight, and for the player the only evidence of all this groundbreaking AI is a pile of corpses from team A, and some half-health monsters from team B."
actually this is perfectly fine for my mod! 
Attenuation 
I presume the values are?
ATTN_NONE 0.0
ATTN_NORM 1.0
ATTN_IDLE 2.0
ATTN_STATIC 3.0

and is there a chart for how far Attenuation value affects sound range?

-

so to make sure
sound (self, CHAN_WEAPON, "enforcer/enfire.wav", 1.00, ATTN_NORM);

1.00 is the volume & I can change ATTN_NORM to a number?

so
sound (self, CHAN_WEAPON, "enforcer/enfire.wav", 0.50, 0.1);

means half volume but 10x the sound range?

and I can also use 0.01 for 100x the range? 
Teams Also 
Do I have to add .float monster_team to defs.qc?

and/or add monster.monster_team to each monster in the mod? 
Sounds Right 
Your code looks correct. I can't quantify exactly how much further the sound goes when you set attenuation to 0.1, but it will be a long way. Give it a try, and you can always adjust it later.

I'd recommend downloading the source code for Qreate and see how they did it. I mentioned that the built-in function in the Quake engine is called "checkclient", and the function which calls it in QuakeC is called "FindClient" found in the ai.qc file. If you look for that in the mod source, you should get some idea how they did it.

Adding field definitions to the bottom of defs.qc is a good choice. You should only define a field once. It can be used from that point onwards in the compilation. defs.qc is a particularly good choice because it's usually the FIRST file to be compiled, so all your code will be able to see the definition. 
Compiler For QC? 
noob question, but how do i compile the QC code to progs.dat? 
Resources 
The short version:
https://quakewiki.org/wiki/Compiling_QuakeC
The slightly longer version with an example to try out and check you got it working:
https://www.quaddicted.com/webarchive/minion.planetquake.gamespy.com/tutorial/tutor7.htm

The two differ in which compiler they recommend. I agree with the recommendation in at the first link, FTEQCC is the better of the options. 
I'm So Confused With The Monster Team/faction Code 
this is what I have/did - in monsters.qc (and does this also solve infighting?)


void() AssignFaction =
{
if (self.classname == "monster_ogre" || self.classname == "monster_fiend") {
self.faction = "Goliath";
} else if (self.classname == "monster_knight" || self.classname == "monster_dog" || self.classname == "monster_hell_knight") {
self.faction = "Juggernaut";
} else if (self.classname == "monster_shambler" || self.classname == "monster_wizard" || self.classname == "monster_zombie") {
self.faction = "Atlantean";
} else if (self.classname == "monster_enforcer" || self.classname == "monster_soldier1") {
self.faction = "Goliath"; // Adding Enforcer and Soldier to Goliath
} else if (self.classname == "monster_demon1" || self.classname == "monster_scrag") {
self.faction = "Juggernaut"; // Adding Demon1 and Scrag to Juggernaut
} else if (self.classname == "monster_tarbaby" || self.classname == "monster_shalrath2") {
self.faction = "Atlantean";
}
// If a monster isn't listed, it won't have a faction.

// Default faction if none assigned above (optional)
if (self.faction == "")
self.faction = "Neutral"; // Or choose a default team
};

void () monster_use =
{
// ... (Existing code for health and target checks)

// Team Check
if (activator.classname != "player" && activator.faction != self.faction && activator.faction != "Neutral" && self.faction != "Neutral")
{
self.enemy = activator;
self.nextthink = time + 0.1;
self.think = FoundTarget; // Make sure FoundTarget is defined
return;
}

// ... (Existing code for player attack)
}; 
Also How Does Dynamic Light Work? 
I can't find how the rocket emits light?

(trying to use as a reference to see how to attach dynamic light to objects using qc)

but there's no reference to any "light" in weapons.qc? 
@ranger 
That one is actually hard-coded in the engine, any model file with EF_ROCKET flag will get a rocket smoke trail and have a dynamic light attached to it. The flag can be set in model editors like qME.

But a glow can also be added in QC, for example enforcer lasers are implemented that way. Check out LaunchLaser in enforcer.qc for an example. 
@metlslime 
seems I cannot find the setting in qc for the weapons/r_exp3.wav?

there's only a BecomeExplosion, but I don't see any sound attached..... 
@ranger 
weapons/r_exp3.wav seems to be directly called by some explosions in QC. But for rockets, it's hard-coded in the engine as part of TE_EXPLOSION 
@metlslime 
oh so cannot adjust attn for explosion sound?

wanted explosion sound range to go further 
Dynamically Spawn/replace Items? 
I saw some mods do this IIRC but it seems complex because quake has a "compiler order" it seems?

I can't have health kits spawn nearby enemies because it would say monster_zombie() is unknown but i cann't move monster_zombie.qc higher up in the "compiler order" because it then has multiple errors?

basically I want the game to have a chance of dynamically spawning nearby zombies at health kits - and it should by realtime/so works with any map 
Forward Declaration 
What you need is a forward declaration of void monster_zombie().

https://en.wikipedia.org/wiki/Forward_declaration

Then you can keep zombie.qc lower in the compiler order and use it with healthkits.

For your explosion, you could maybe opt into the mission pack features and use TE_EXPLOSION2 which I think is silent so you can pair it with your own sound. Otherwise there's a hack posted by a scoundrel called Preach in the previous pages of this thread
https://www.celephais.net/board/view_thread.php?id=60097&start=1911&end=1935 
@Preach 
is TE_EXPLOSION2 and such values, hardcoded?

got it, I see "Burst Of Particles"

is there a code number guide for palette colors? or I gotta count them manually?

--
also something is up with ATTN_STATIC and such for sounds? I tried setting the attn value for a sound to like 5 or 10 but seems no effect? the sound seems to still travel very far? but if i set it to ATTN_STATIC the range is reduced 
Also This Is A Persistant Bug I'm Getting 
(trying to spawn new items/models dynamically in maps)

host error

pf precache can only be done in spawn functions? 
Palette And More 
https://quakewiki.org/wiki/Quake_palette

Attenuation values wrap around when you hit the limit, so 1 = 5 = 9 etc. Don’t go above 4.

You can only precache at the first frame. You might need to rewrite the spawn function as multiple functions. One function to just precache things, one to actually create the entity without precache. The latter can be run at any time. But you must run the precache function on the initial frame somehow any time you might run the spawn function. 
About Factions Revisted 
my quakec code not working? seems no effect ingame - all monsters still are all teams with each other against the player. (I even added AssignFaction() to every monster and confirmed the monsters are on the correct teams ingame)


in monsters.qc

void () monster_use =
{
if (self.enemy)
return;
if (self.health <= 0)
return;
if (activator.flags & FL_NOTARGET)
return;
//if (activator.classname != "player")
// return;

if (activator.classname != "player" &&
activator.faction != self.faction &&
activator.faction != FACTION_NEUTRAL &&
self.faction != FACTION_NEUTRAL)
{
self.enemy = activator;
self.nextthink = time + 0.1;
self.think = FoundTarget;
return;
}

self.enemy = activator;
self.nextthink = time + 0.1;
self.think = FoundTarget;

};

void() AssignFaction =
{
if (self.classname == "monster_shambler" )
{
self.faction = FACTION_A; //1

}
else if (self.classname == "monster_army" )
{
self.faction = FACTION_B; //2

}
else if (self.classname == "monster_tarbaby")
{
self.faction = FACTION_C; //3

}
else if (self.classname == "monster_dragon")
{
self.faction = FACTION_D; //4

}

// Default faction if none assigned above
if (!self.faction)
self.faction = FACTION_NEUTRAL; //0
}


in ai.qc

float(entity targ) MonsterCheckEnemy =
{
// Invalid or dead targets
if (!targ || targ.health <= 0)
return FALSE;

// Always target players
if (targ.classname == "player")
return TRUE;

// Don't target same faction
if (targ.faction == self.faction)
return FALSE;

// Neutral faction doesn't fight anyone except players
if (targ.faction == FACTION_NEUTRAL || self.faction == FACTION_NEUTRAL)
return FALSE;

// Different factions will fight
return TRUE;
};


float () FindTarget =
{
local entity client;
local float r;

if ((sight_entity_time >= (time - 0.10)) && !(self.spawnflags & 3))
{
client = sight_entity;
if (client.enemy == self.enemy)
return (FALSE);
}
else
{
if ((active_probes != FALSE) && (random () < 0.50))
{
beef = find (world, classname, "hologram");
if ((beef != world) && (beef.holo_owner.flags != (beef.holo_owner.flags | FL_NOTARGET)))
client = beef;
else
client = checkclient ();
}
else
client = checkclient ();
if (!client)
return (FALSE);
}
if (client == self.enemy)
return (FALSE);
if (client.flags & FL_NOTARGET)
return (FALSE);

// Add faction check
//if (client.faction == self.faction || client.faction == FACTION_NEUTRAL || self.faction == FACTION_NEUTRAL)
// return (FALSE);
if (!MonsterCheckEnemy(client))
return FALSE;

r = range (client);
if ((r == RANGE_FAR)) //out of range
return (FALSE);
if (!visible (client))
return (FALSE);
if (r == RANGE_NEAR)
{
if ((client.show_hostile < time) && !infront (client))
return (FALSE);
}
else if (r == RANGE_MID) //combat range max
{
if (!infront (client))
return (FALSE);
}
self.enemy = client;
if ((self.enemy.classname != "player") && (self.enemy.classname != "hologram"))
{
self.enemy = self.enemy.enemy;
if (self.enemy.classname != "player")
{
self.enemy = world;
return (FALSE);
}
}
FoundTarget ();
return (TRUE);
}; 
 
To clarify all that code doesn't seem to work...

ingame monsters on the same side will infight if accidentally hit by teammates,
and will not automatically attack other monsters in other factions 
Application 
Your MonsterCheckEnemy needs to be running in T_Damage to have an effect on infighting. And there’s nothing in your FindTarget that ever makes “client” a monster, because checkclient only yields players. So there’s no chance of fighting breaking out spontaneously. 
@Preach 
"Your MonsterCheckEnemy needs to be running in T_Damage to have an effect on infighting. "

"And there’s nothing in your FindTarget that ever makes “client” a monster, because checkclient only yields players. So there’s no chance of fighting breaking out spontaneously. "

Can you explain these 2 points in more detail? or provide code snippets? I'm still new to this 
T_Damage 
nvm I got the prevent faction infighting in - based on the area that you mentioned before in combat.qc/T_Damage 
First | Previous | Next | Last
You must be logged in to post in this thread.
Website copyright © 2002-2024 John Fitzgibbons. All posts are copyright their respective authors.