View previous topic :: View next topic |
Author |
Message |
Extreme
Joined: 28 Nov 2007 Posts: 135
|
Posted: Sat Nov 15, 2008 15:19 Post subject: GetFactionID |
|
|
i have this function in a script and it is not working as i thought it would. I have this in my random encounter script and my goal is to have this script TRUE if there is any hostile creature left in the area. And if it returns FALSE, the script will return
With hostile creatures in an area, This function is returning FALSE. Am i using the right constant for this function?
Code: | int GetIsHostileCreatureInArea(object oPC)
{
int i = 1;
object oMonster = GetNearestCreature(CREATURE_TYPE_IS_ALIVE, TRUE, oPC, i, CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_NOT_PC);
while(GetIsObjectValid(oMonster)){
if(GetFactionID(oMonster) == STANDARD_FACTION_HOSTILE){
return TRUE;
}
else{
oMonster = GetNearestCreature(CREATURE_TYPE_IS_ALIVE, TRUE, oPC, ++i, CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_NOT_PC);
}
}
return FALSE;
} |
this if clause is the caller of the function. The CreateCreatures() is firing even tho there are Hostile creatures.
Code: | if(GetIsHostileCreatureInArea(oPC) == FALSE){
DebugServer("No hostile creatures and we are respawning now");
CreateCreatures(oPC, oArea, AscertainSpawnCount(oArea));
DelayCommand(fRespawnTime, PrepareForRespawn(oArea, fRespawnTime));
}
else{
DebugServer("Delayed the respawn as there are still hostile creatures");
DelayCommand(fRespawnTime, PrepareForRespawn(oArea, fRespawnTime));
} |
|
|
Back to top |
|
|
Extreme
Joined: 28 Nov 2007 Posts: 135
|
Posted: Wed Nov 19, 2008 14:17 Post subject: |
|
|
*hopes he can ask before virusman leaves*
is STANDARD_FACTION_* the correct varaibles in this function?
*Hopes virusman doesnt plot his death* |
|
Back to top |
|
|
virusman
Joined: 30 Jan 2005 Posts: 1020 Location: Russia
|
Posted: Wed Nov 19, 2008 14:23 Post subject: |
|
|
Extreme wrote: | *hopes he can ask before virusman leaves*
is STANDARD_FACTION_* the correct varaibles in this function?
*Hopes virusman doesnt plot his death* | I haven't tested GetFactionID with 1.69, but I think yes, STANDARD_FACTION_* constants should work. |
|
Back to top |
|
|
Urlord
Joined: 17 Nov 2006 Posts: 122
|
Posted: Wed Nov 19, 2008 14:49 Post subject: |
|
|
Your function returns an INT, so you will only be able to return an interger. TRUE (1) and FALSE (0) are integers. But you cannot return the hostile creature. You could approach this one of two ways that I can think of. (a) Return TRUE and store the nearest hostile creature on the PC for later use OR (B) change your function to return the nearest hostile creature, returning OBJECT_INVALID is none exists. Examples Follow:
METHOD A
Code: | int GetIsHostileCreatureInArea(object oPC) {
int i = 1;
object oMonster = GetNearestCreature(CREATURE_TYPE_IS_ALIVE, TRUE, oPC, i, CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_NOT_PC);
while(GetIsObjectValid(oMonster)){
if(GetIsEnemy(oMonster)){
SetLocalObject(oPC, "Nearest_Enemy", oMonster);
return TRUE;
}
i += 1;
oMonster = GetNearestCreature(CREATURE_TYPE_IS_ALIVE, TRUE, oPC, i, CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_NOT_PC);
}
return FALSE;
}
|
METHOD B
Code: | object GetNearestHostileCreature(object oPC) {
int i = 1;
object oMonster = GetNearestCreature(CREATURE_TYPE_IS_ALIVE, TRUE, oPC, i, CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_NOT_PC);
while(GetIsObjectValid(oMonster)){
if(GetIsEnemy(oMonster)){
return oMonster;
}
i += 1;
oMonster = GetNearestCreature(CREATURE_TYPE_IS_ALIVE, TRUE, oPC, i, CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_NOT_PC);
}
return OBJECT_INVALID;
}
|
I hope this offers some assistance. _________________ Jim (aka, Urlord)
Visit the Persistent World of Nymri |
|
Back to top |
|
|
Extreme
Joined: 28 Nov 2007 Posts: 135
|
Posted: Wed Nov 19, 2008 14:52 Post subject: |
|
|
it does slightly. but i was hoping that thru the nwnx function i would not have to reference the hostle creature vs anything. So i could just run the GetFactionID and if it is a certain faction, return TRUE/FALSE respectively |
|
Back to top |
|
|
virusman
Joined: 30 Jan 2005 Posts: 1020 Location: Russia
|
Posted: Wed Nov 19, 2008 15:55 Post subject: |
|
|
Urlord, if I understand the first post right, the purpose of the function is to return TRUE or false depending on whether there are any hostile creatures in the area or not. |
|
Back to top |
|
|
Extreme
Joined: 28 Nov 2007 Posts: 135
|
Posted: Wed Nov 19, 2008 15:57 Post subject: |
|
|
that is correct. and potentially finding a function that is not working right? we shall see
but im just ahppy the whole system works fine. especially when this is fixed, but i could result to not using the NWNX function....but forget that |
|
Back to top |
|
|
acaos
Joined: 08 May 2007 Posts: 153
|
Posted: Wed Nov 19, 2008 15:57 Post subject: |
|
|
The STANDARD_FACTION_* constants will only work if you haven't actually made any factions in your mod. So if you made an Army of Foo faction which was hostile to PCs, that won't match STANDARD_FACTION_HOSTILE.
Acaos |
|
Back to top |
|
|
Extreme
Joined: 28 Nov 2007 Posts: 135
|
Posted: Wed Nov 19, 2008 16:25 Post subject: |
|
|
i actually have not made any factions at all to date. still early for that. What would i need to set the faction to to use this? I want to make a Hostile faction. just your basic hostile creature faction and use it |
|
Back to top |
|
|
acaos
Joined: 08 May 2007 Posts: 153
|
Posted: Wed Nov 19, 2008 17:11 Post subject: |
|
|
The best thing to do would be to actually log what GetFactionId() is telling you for your creatures and compare that to the STANDARD_FACTION constants.
Acaos |
|
Back to top |
|
|
Extreme
Joined: 28 Nov 2007 Posts: 135
|
Posted: Wed Nov 19, 2008 17:12 Post subject: |
|
|
thats a good testing idea there. place all the known factions in a large area and then just loop thru them. I will do that so that i can do that function using NWNx. Especially cause i have 2 versions of the system (1 windoze and 1 linux) |
|
Back to top |
|
|
virusman
Joined: 30 Jan 2005 Posts: 1020 Location: Russia
|
Posted: Wed Nov 19, 2008 17:24 Post subject: |
|
|
Extreme wrote: | thats a good testing idea there. place all the known factions in a large area and then just loop thru them. I will do that so that i can do that function using NWNx. Especially cause i have 2 versions of the system (1 windoze and 1 linux) | Don't forget to clear all scripts on them.. Otherwise they'll attack each other. |
|
Back to top |
|
|
Extreme
Joined: 28 Nov 2007 Posts: 135
|
Posted: Wed Nov 19, 2008 17:25 Post subject: |
|
|
lol...i know
or just put them in corners of a 16x16 area |
|
Back to top |
|
|
Baaleos
Joined: 02 Sep 2007 Posts: 830
|
Posted: Fri Dec 19, 2008 17:26 Post subject: This might help |
|
|
I dunno if this helps, but I was working on something to do with factions and making the player friendly to them, but part of it does what you need it to.
I can't recall the entire script, but it involved using the
Code: | GetFactionAverageReputation() | on a monster & player, to find out how that faction feels towards the player.
Interpretation of the values returned by this function:
0-10 means oSource is hostile to oTarget: oSource will attack oTarget on sight.
11-89 means oSource is neutral to oTarget: oSource won't attack oTarget, but won't defend it either.
90-100 means oSource is friendly to oTarget: oSource will anyone attacking oTarget.
Using this method, allows you to get the NON-Standard Bioware Faction feelings towards players.
By all means, you can use the Bioware Factions, and the associated scripts that can detect hostility for those factions, but if you have used custom factions, you may need to use the function listed above.
The way my function that I wrote worked, was it got the difference between the current faction reputation, and the number 70, then it incremented the players reputation with those groups to 70 to make them none-hostile to him.
I used this as a method of making players of evil subraces in my server able to do the main quests and enter other races cities, which would otherwise be hostile to Drow, and Undead. |
|
Back to top |
|
|
|