I'm So Confused With The Monster Team/faction Code
#3495 posted by ranger on 2024/12/14 06:42:12
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?
#3496 posted by ranger on 2024/12/14 12:20:42
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
#3497 posted by metlslime on 2024/12/14 23:16:37
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
#3498 posted by ranger on 2024/12/15 18:52:32
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
#3499 posted by metlslime on 2024/12/17 11:56:21
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
#3500 posted by ranger on 2024/12/17 18:29:36
oh so cannot adjust attn for explosion sound?
wanted explosion sound range to go further
Dynamically Spawn/replace Items?
#3501 posted by ranger on 2024/12/17 18:34:29
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
#3502 posted by Preach on 2024/12/19 16:41:40
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
#3503 posted by ranger on 2024/12/22 11:58:49
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
#3504 posted by ranger on 2024/12/22 15:58:31
(trying to spawn new items/models dynamically in maps)
host error
pf precache can only be done in spawn functions?
Palette And More
#3505 posted by Preach on 2024/12/22 18:53:40
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
#3506 posted by ranger on 2024/12/22 19:56:15
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);
};
#3507 posted by ranger on 2024/12/22 19:59:56
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
#3508 posted by Preach on 2024/12/22 23:01:23
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
#3509 posted by ranger on 2024/12/23 06:39:20
"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
#3510 posted by ranger on 2024/12/23 08:12:30
nvm I got the prevent faction infighting in - based on the area that you mentioned before in combat.qc/T_Damage
FindTarget
#3511 posted by ranger on 2024/12/23 15:34:31
I tried adding this , and different monsters in different factions do fight, but strangely only when they first took damage from the player
//>>> If no player found, look for monsters
if (!client)
{
//client = find(world, flags, FL_MONSTER);
client = find(world, classname, "monster_*");
while (client)
{
if (client != self && MonsterCheckEnemy(client))
{
r = range(client);
if (r != RANGE_FAR && visible(client) &&
(r == RANGE_NEAR || infront(client)))
{
break;
}
}
//client = find(client, flags, FL_MONSTER);
client = find(world, classname, "monster_*");
}
}
No Wildcards
#3512 posted by Preach on 2024/12/26 12:46:54
I had to wait for a chance to research this. Can now confirm that “find” does NOT support wildcards, so your code is still not ever finding monsters. Unsure how you are ever getting spontaneous fights but it isn’t via the planned route. Here’s a function that will help, it’s a hand-rolled search for a flag that fits your commented out line of code.
entity (entity start) findNextMonster = {
local entity e;
e = start;
while ( (e = nextent(e)) ) {
if( e.flags & FL_MONSTER) {
return e;
}
return world;
}
}
It might be better to build a bit more structure around it if you want something akin to checkclient, like a global that stores the candidate monster, which is rotated once a frame in StartFrame(). And don’t forget that checkclient does a visibility check which is up to you to handle on the monster side.
Thanks! It Is Working Now!
#3513 posted by ranger on 2024/12/26 19:29:06
But sadly i'm getting a very bizarre unrelated bug?
Host_Error:PR_ExecuteProgram: Null Function
I even restored the original unedited monster code and it's still having the error?
Nvm I Figured It Out It Was An Properly Coded Animation
#3514 posted by ranger on 2024/12/26 20:18:23
Regarding Monster AI
#3515 posted by ranger on 2024/12/26 20:30:09
I was wondering how to improve it?
like even simple pathfinding? (funnily enough the Vore bomb has better cornering than the actual vore/monsters)
or being able to go up and down reasonable heights?
and how to change the angle before the monster can shoot? because seems grunt can shoot the player before his barrel is even pointed straight at the player?
and how to change the max & min "tilt" angles for monsters? because want some monsters to not be able to shoot at enemies at are at too steep angles
(this is what i have so far but honestly i don't really know what i am doing - very new at this)
---
float CheckMonsterJump(entity self)
{
vector start, end;
// Check ground below
start = self.origin;
end = start;
end_z = end_z - 64; // Adjust drop height check
traceline(start, end, TRUE, self);
if (trace_fraction == 1)
return FALSE; // Too high to drop
if (trace_fraction < 1)
{
// Safe to drop - within acceptable height
if ((start_z - trace_endpos_z) <= 64)
{
self.flags = self.flags - (self.flags & FL_ONGROUND);
self.velocity_z = -300; // Adjust drop speed
return TRUE;
}
}
// Check for jumpable height
start = self.origin;
end = start;
end_z = end_z + 32; // Jump check height
traceline(start, end, TRUE, self);
if (trace_fraction == 1)
{
self.velocity_z = 300; // Jump velocity
return TRUE;
}
return FALSE;
}
float TryAlternativePath(entity self)
{
vector dir, right, left, start, end;
float right_clear, left_clear;
// Get perpendicular directions
dir = normalize(self.enemy.origin - self.origin);
right = '0 0 0';
right_x = dir_y;
right_y = -dir_x;
left = -right;
// Check right path
start = self.origin;
end = start + (right * 128); // Adjust side check distance
traceline(start, end, TRUE, self);
right_clear = trace_fraction;
// Check left path
end = start + (left * 128);
traceline(start, end, TRUE, self);
left_clear = trace_fraction;
if (right_clear > left_clear)
{
self.ideal_yaw = vectoyaw(right);
return TRUE;
}
else if (left_clear > right_clear)
{
self.ideal_yaw = vectoyaw(left);
return TRUE;
}
return FALSE;
}
|