Faction System
by Jorge Luis Gandulfo · 04/26/2004 (10:28 am) · 24 comments
Download Code File
Well i did this a few days ago basing my work on this resourcewww.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=4943 from Sam Guffey.
I changed it a bit and make a Faction System, wich will be very easy to use in scripts.
Also i modified the CrossHairGui with name www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=5577 to fit the new faction system and show [player name, faction] instead of [player name] only.
k here it goes, hope you have plenty of time :)
btw i just copied the order of Sam Article to write this one, hope he doesn't get mad.
# in (class ShapeBase) below (Aprox line 740)..
bool mChargeEnergy;
# add..
# find (enum ShapeBaseMasks) (Aprox line 970)..
# re-number
SoundMaskN = Parent::NextFreeMask << 8,
#to
SoundMaskN = Parent::NextFreeMask << 9,
#then, above it add..
# next, below.. (Aprox line 1000)..
bool onNewDataBlock(GameBaseData* dptr);
# add..
# In (ShapeBase::ShapeBase) (aprox line 610)..
# below..
mLastRenderDistance = 0;
# add..
# In (ShapeBase::packUpdate) (aprox line 3000)
# above..
if (stream->writeFlag(mask & DamageMask))
# add..
# In (ShapeBase::unpackUpdate) (aprox line 3125)..
# below..
Parent::unpackUpdate(con, stream);
mLastRenderFrame = sLastRenderFrame; // make sure we get a process after the event...
if(!stream->readFlag())
return;
# add..
# below.. (ShapeBase::setSkinName) (aprox line 3571)
# add these functions..
K up to now you have a working faction system, wich you can configure up here creating new factions or faction status.
To implement this in scripting..
# in (GameConnection::createPlayer)
# at the very bottom add..
Where 0 is the faction you choosen, can be a variable that came from another script.
now we are gonna modify my crosshairgui the one in the resource i told you before.. just in case www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=5577
Apply that resource and then modify this lines if you want a crosshair to display faction.
somewhere near line 161 you will find this lines of code
#bellow
if(obj->getShapeName())
{
hasObject = true;
dmgLevel = obj->getDamageValue();
#add
now you have the coolest guiCrosshair in town :)
PD: The img below sux i know, just go up and check the code files :)
Well i did this a few days ago basing my work on this resourcewww.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=4943 from Sam Guffey.
I changed it a bit and make a Faction System, wich will be very easy to use in scripts.
Also i modified the CrossHairGui with name www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=5577 to fit the new faction system and show [player name, faction] instead of [player name] only.
k here it goes, hope you have plenty of time :)
btw i just copied the order of Sam Article to write this one, hope he doesn't get mad.
Quote:shapebase.h modifications
# in (class ShapeBase) below (Aprox line 740)..
bool mChargeEnergy;
# add..
F32 mFactionId;
# find (enum ShapeBaseMasks) (Aprox line 970)..
# re-number
SoundMaskN = Parent::NextFreeMask << 8,
#to
SoundMaskN = Parent::NextFreeMask << 9,
#then, above it add..
FactionMask = Parent::NextFreeMask << 8,
# next, below.. (Aprox line 1000)..
bool onNewDataBlock(GameBaseData* dptr);
# add..
// FactionSystem
F32 getFactionId() { return mFactionId; }
void setFactionId(F32 faction);
S32 getFactionStatus(F32 FactionBase, F32 FactionTarget);
const char* getFactionName(F32 FactionBase);Quote:shapeBase.cc modifications
# In (ShapeBase::ShapeBase) (aprox line 610)..
# below..
mLastRenderDistance = 0;
# add..
mFactionId = 0;
# In (ShapeBase::packUpdate) (aprox line 3000)
# above..
if (stream->writeFlag(mask & DamageMask))
# add..
if(stream->writeFlag(mask & FactionMask)) {
stream->write(mFactionId);
}# In (ShapeBase::unpackUpdate) (aprox line 3125)..
# below..
Parent::unpackUpdate(con, stream);
mLastRenderFrame = sLastRenderFrame; // make sure we get a process after the event...
if(!stream->readFlag())
return;
# add..
if(stream->readFlag()) {
stream->read(&mFactionId);
}# below.. (ShapeBase::setSkinName) (aprox line 3571)
# add these functions..
void ShapeBase::setFactionId(F32 factionId)
{
if(factionId < 0)
factionId = 0;
mFactionId = factionId;
setMaskBits(FactionMask);
}
const char* ShapeBase::getFactionName(F32 FactionBase)
{
switch ((S32)FactionBase)
{
case 0: //Mercenaries
{
return "Mercs";
}
break;
case 1: //Faction1
{
return "Faction1";
}
break;
case 2: //Faction2
{
return "Faction2";
}
break;
}
return "";
}
S32 ShapeBase::getFactionStatus(F32 FactionBase, F32 FactionTarget)
{
switch ((S32)FactionBase)
{
case 0: //Mercs
{
return 0; //Neutral
}
break;
case 1: //Faction1
{
switch ((S32)FactionTarget)
{
case 0: //Mercs
{
return 0; //Neutral
}
break;
case 1: //Faction1
{
return 1; //Allied
}
break;
case 2: //Faction2
{
return 2; //Enemy
}
break;
}
}
break;
case 2: //Faction2
{
switch ((S32)FactionTarget)
{
case 0: //Mercs
{
return 0; //Neutral
}
break;
case 1: //Faction1
{
return 2; //Enemy
}
break;
case 2: //Faction2
{
return 1; //Allied
}
break;
}
}
break;
}
return 0; //Neutral
}
ConsoleMethod( ShapeBase, setFactionId, void, 3, 3, "(float faction)")
{
object->setFactionId(dAtof(argv[2]));
}
ConsoleMethod( ShapeBase, getFactionId, F32, 2, 2, "(returns - factionId)")
{
return object->getFactionId();
}K up to now you have a working faction system, wich you can configure up here creating new factions or faction status.
To implement this in scripting..
Quote:game.cs modifications
# in (GameConnection::createPlayer)
# at the very bottom add..
%player.setFactionId(0);
Where 0 is the faction you choosen, can be a variable that came from another script.
Quote:***This is optional***
now we are gonna modify my crosshairgui the one in the resource i told you before.. just in case www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=5577
Apply that resource and then modify this lines if you want a crosshair to display faction.
Quote:guiCrossHairHud.cc modifications
somewhere near line 161 you will find this lines of code
#bellow
if(obj->getShapeName())
{
hasObject = true;
dmgLevel = obj->getDamageValue();
#add
S32 myId = control->getFactionId();
S32 targetId = obj->getFactionId();
S32 mFactionStatus;
mFactionStatus = control->getFactionStatus(myId, targetId);
dStrcpy(szShapeName, obj->getShapeName());
dStrcat(szShapeName, ", ");
dStrcat(szShapeName, obj->getFactionName(targetId));
switch (mFactionStatus)
{
case 0: //Neutral
{
mActiveColor = mNeutralTargetColor;
}
break;
case 1: //Allied
{
mActiveColor = mFriendlyTargetColor;
}
break;
case 2: //Enemy
{
mActiveColor = mEnemyTargetColor;
}
break;
}now you have the coolest guiCrosshair in town :)
Quote: i wish i wasnt this noob in torque, otherwise i could made this a bit better for you folks, but well all i ask is someone to review this and in any case make this better for everybody.
what there is really missing is some decent enums for faction and faction relations
Have FUN!!!
PD: The img below sux i know, just go up and check the code files :)
About the author
#2
04/27/2004 (10:03 am)
Wow this is awesome, thx so much!
#3
With some wrenching I go this in.
This is better than what I was working on.
Works with the latest head also.
Killer work.
Like the relationships!
07/17/2004 (3:16 am)
Thanks Jorge,With some wrenching I go this in.
This is better than what I was working on.
Works with the latest head also.
Killer work.
Like the relationships!
#4
I don't get any errors, but everyone is red to me and no faction names in the crosshair.
I added all the resources and checked the code 3 times.
Am I missing something simple?
07/19/2004 (2:58 am)
Doesn't seem to work.I don't get any errors, but everyone is red to me and no faction names in the crosshair.
I added all the resources and checked the code 3 times.
Am I missing something simple?
#5
This resource works perfectly!
It was self inflicted as most bugs are.
I call 'em "newbie killers", as I am still new to C.
The error was this...
In guiCrossHairHud.cc after you patched the code near line 161, at the end of the snippet rem these 2 lines.
//dStrcpy(szShapeName, obj->getShapeName());
//mActiveColor = mEnemyTargetColor;
The colors and faction tags will function as intended.
Btw, if you have bots using this faction system for attack and follow, try this for an instant war.
//Modify to max # of factions
%player.setFactionId(getRandom()*2);
07/25/2004 (10:16 pm)
Ok, I fixed it.This resource works perfectly!
It was self inflicted as most bugs are.
I call 'em "newbie killers", as I am still new to C.
The error was this...
In guiCrossHairHud.cc after you patched the code near line 161, at the end of the snippet rem these 2 lines.
//dStrcpy(szShapeName, obj->getShapeName());
//mActiveColor = mEnemyTargetColor;
The colors and faction tags will function as intended.
Btw, if you have bots using this faction system for attack and follow, try this for an instant war.
//Modify to max # of factions
%player.setFactionId(getRandom()*2);
#6
07/27/2004 (11:23 pm)
Can someone explain why this isn't part of shapeBaseData instead of shapeBase? The distinctions between the two are becoming fuzzy to me.
#7
10/29/2004 (10:05 am)
ShapeBaseData defines the datablock. ShapeBase is the game object. Read up on networking. Doing nearly anything in torque requires a working knowledge of the networking.
#8
Ari Rule if you are still there, did you added each player to a diff. faction?
using this example code i writed in the last part of this article?
%player.setFactionId(0);
This 0 is the Faction you want for the %player (i tested it on bots as well).
11/16/2004 (1:54 am)
I just came back from a long trip in Romania, sorry for not answering before.Ari Rule if you are still there, did you added each player to a diff. faction?
using this example code i writed in the last part of this article?
%player.setFactionId(0);
This 0 is the Faction you want for the %player (i tested it on bots as well).
#9
My current work in the faction area is having the AI react differently to the diferent factions. I have 5 working factions in our engine now. When I'm done, I will post a snippit for the bot's search code that identifies the target's faction.
11/22/2004 (2:08 pm)
@Jorge: I have the factions working perfectly as in my post above. I hope your trip was fun!My current work in the faction area is having the AI react differently to the diferent factions. I have 5 working factions in our engine now. When I'm done, I will post a snippit for the bot's search code that identifies the target's faction.
#10
03/31/2005 (3:36 pm)
ha my games named sixthfaction and this is pretty necessary thanks
#11
Works killer!
I respawn in factional allied hospitals, faction chat, etc.
Thanks again Jorge.
06/10/2005 (3:13 am)
I mixed this with teams.Works killer!
I respawn in factional allied hospitals, faction chat, etc.
Thanks again Jorge.
#12
06/12/2005 (3:37 am)
What teams resource did you use BrokeAss?
#14
09/05/2005 (5:11 pm)
I'm using the realmwars melee code which uses the 9th mask in enum ShapeBaseMasks. Any suggestions on a work around?
#15
Well if you still need it Michael, as far as im concerned you can change either the melee or this code to another mask number, i really gotta check into it, but if you follow and example like this one you shouldn't have any problem.
# find (enum ShapeBaseMasks) (Aprox line 970)..
# re-number
you might do something like this, but maybe in your case numbers would be something like 9 and 10?
01/07/2006 (6:20 am)
This might be too late, but again i was on a trip, and i forgot to turn on the Notify check.Well if you still need it Michael, as far as im concerned you can change either the melee or this code to another mask number, i really gotta check into it, but if you follow and example like this one you shouldn't have any problem.
# find (enum ShapeBaseMasks) (Aprox line 970)..
# re-number
SoundMaskN = Parent::NextFreeMask << 8,#to
SoundMaskN = Parent::NextFreeMask << 9,#then, above it add..
you might do something like this, but maybe in your case numbers would be something like 9 and 10?
#16
02/24/2006 (11:36 am)
Mm, so far this has been pretty good. My only complaint is that i cant change the faction while the object is ingame. If i do %obj.setFactionId(); it doesnt change what i get on my cursor. Any tips, guys?
#17
Well to be honest i can't find why you can't change the object faction ingame.
Can you send me the code you are using in the scriptside while trying to change faction?
Thanks
03/01/2006 (1:20 pm)
Nick, sorry for this delay i had some problems with my inet connection.Well to be honest i can't find why you can't change the object faction ingame.
Can you send me the code you are using in the scriptside while trying to change faction?
Thanks
#18
%obj.setFactionId(2);
and if i do getFactionId it does change the number, but if i put my cursor over him, its still the Green one or something. I did do some minor modifications to your guicrosshairhud.cc so that i didnt have the weird crosshair shaking around the place, but i dont think there was anything in there which verified changing of the colours or something? It just gets the faction id, which im sure is 2, and should then choose the correct colour for it. If i set it when the object spawns, its fine, but if i set it after it doesnt work.
Also: Im using the turrets code, and that picks up the change too, as i made them only fire at the enemy. The only thing that isnt doing it is guicrosshairhud.cc - It doesnt change the name or colour.
03/02/2006 (4:55 am)
Well i basically just use:%obj.setFactionId(2);
and if i do getFactionId it does change the number, but if i put my cursor over him, its still the Green one or something. I did do some minor modifications to your guicrosshairhud.cc so that i didnt have the weird crosshair shaking around the place, but i dont think there was anything in there which verified changing of the colours or something? It just gets the faction id, which im sure is 2, and should then choose the correct colour for it. If i set it when the object spawns, its fine, but if i set it after it doesnt work.
Also: Im using the turrets code, and that picks up the change too, as i made them only fire at the enemy. The only thing that isnt doing it is guicrosshairhud.cc - It doesnt change the name or colour.
#19
05/26/2006 (3:12 am)
Wow, been 2 months and no reply. I'll try giving the author a buzz on his email and post the fix here (if there is one?).
#20
08/13/2006 (4:56 pm)
I would also like to know how to fix it 
Torque Owner Stefan Lundmark