dickel wrote...
<SNIP> ... but I couldnt find an option to change factions. <SNIP>
Hi dickel,
As M.Rider says, the easiest way to do what you want is to simply set the creatures as HOSTILE in their
faction setting in the toolset. The only reason to have your NPCs change faction is if you want to give the appearance that they are "friendly" and turn "hostile" when they spot the PCs. However, this would also imply that the PCs do not know the NPCs intentions, and would not have considered them hostile in the first place.
Anyway, when in the toolset scripting section, make sure the
Script Assist is enabled and you are on the
functions tab (in the pane that appears) and then type into the box at the top, "Faction". You will then get a list of all the functions that relate to factions. One such function is
ChangeToStandardFaction, which can take the STANDARD_FACTION_HOSTILE setting, which will turn the creature you are working with to the hostile setting.
Please note, factions can be very tricky to work with and if you are not yet competent with basic scripting, you may be jumping in too soon. It is best to keep to simple scripting to start with and use the toolsets own faction system to make creatures hostile or not from the start. I won't bog you down with the details, but if you do as M.Rieder says, or make use of the basic function above, then you should be on safe ground. As an indication of potential problems, however, you must remember that if you use this function to turn previously neutrals into hostiles, then any other neutrals (who you in fact wanted to stay friends with the newly changed creatures) will ,in fact, become enemies as well as the PCs. In the end, the function
SetIsTemporaryEnemy that you used is probably the easiest and safest way to go.
Lastly, if you do want to change from neutral to hostile, then I would suggest you write this script for the
OnPerceived and not the heartbeat, as that is the best place for it. Here is an example of some script that you can add to the OnPerceived that should work (have not tested though). (Obviously, you have to edit the code out of its current void main section.)
Lance.
// ADD TO THE ON PERCEIVED SCRIPT SOMEWHERE
void main()
{
object oPC = GetLastPerceived();
object oNPC = OBJECT_SELF;
// ONLY FIRE FOR PC. DO NOT FIRE IF NPC IS IN CONVERSATION OR COMBAT.
if(!GetIsPC(oPC) || IsInConversation(oNPC) || GetIsInCombat(oNPC)){return;}
// MAKE THE PC A PERMANENT ENEMY
SetIsTemporaryEnemy(oPC, oNPC);
// MAKE NPC ATTACK THE PC
AssignCommand(oNPC, ClearAllActions());
AssignCommand(oNPC, ActionAttack(oPC));
}
EDIT: I am aware that the OnPerceived may not fire as often as you might like or think, which may give some unusual results. Also, the SetIsTemporaryEnemy does not immediately give the red hostile ring under the NPC until they have actually hit the PC in question. To have the red ring appear, you will need to use the faction functions. E.g. Change the
SetIsTemporaryEnemy(oPC, oNPC); to
ChangeToStandardFaction(oNPC, STANDARD_FACTION_HOSTILE); and every NPC with this script will turn hostile and attack the PC when spotted. However, there may be the occassional time when an NPC (who has not yet turned hostile) could potentially attack the hostile prior to spotting the PC due to the default faction settings in the toolset ... if you see what I mean?
Modifié par Lance Botelle, 12 mars 2011 - 02:47 .