Aller au contenu

Photo

on perception change faction to hostile?


  • Veuillez vous connecter pour répondre
6 réponses à ce sujet

#1
dickel

dickel
  • Members
  • 72 messages
Sorry, but I'll have to admit straight up I can't script.
So some help would be appreciated.

The spot i'm up to at the moment in my module, involves npc's that the pc's must run from (or choose to stay and fight...and most likely die), but if the npc's spot the pc's then i'd like them to all turn hostile?

Has anyone got a simliar script they can post up for me?
Or if you can make one that'd be ace. I was thinking of using Lilac's soul to make an onHeartbeat script to do something like this, but I couldnt find an option to change factions. I only did this, because Lilac's doesn't offer an option for npc onPerceived scripts...as far as I can tell.

I'm not sure which would be better, onHeartbeat or onPerception..but i'd presume onPerception would use less resources etc.

Anyway, hope someone can help me. Thanks.

Peace.:wizard:

#2
dickel

dickel
  • Members
  • 72 messages
Here is what I managed to get from using Lilac's. It's close to what I want, but the npc doesn't actually become hostile doing this.


<script>//Goes on creature's OnHeartbeat. Fires when not fighting or talking.
#include "nw_i0_generic"
void main()
{

object oPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, OBJECT_SELF, 1, CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN);

if (IsInConversation(OBJECT_SELF) || GetIsInCombat()) return;

object oTarget;
oTarget = OBJECT_SELF;

SetIsTemporaryEnemy(oPC, oTarget);

ActionAttack(oPC);

DetermineCombatRound(oPC);

}</script>

(Not sure if i have done the above correctly to display in a box....fingers crossed.)


peace.


update: turns out I didn't. :)

Modifié par dickel, 12 mars 2011 - 09:23 .


#3
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
If you make the NPC's hostile from the beginning, they will automatically attack the PC using the standard scripts. Is there some other reason you want them to start out non-hostile? This could save the need for scripting.

#4
Lance Botelle

Lance Botelle
  • Members
  • 1 480 messages

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 .


#5
dickel

dickel
  • Members
  • 72 messages
You know what, that is really strange that I hadn't considered just starting the npc's out as Hostile faction. It is so blatantly obvious.
Although the circumstances I had in mind, I had planned to have them turn 'Hostile' when they saw that the pc's were in their 'home' so to speak. The enemies dont know the Pc's are there initially.

Thanks for the above reply too, Lance Botelle, appreciate it.

#6
dethia

dethia
  • Members
  • 146 messages
Well it is not difficult to do what you want either way, though because perception scripts fire often what we did on our pw as a solution is create an area of effect on spawned npcs and when those effects are entered we modify hostile/friendly settings. The advantage of using area of effects is they fire only once per enter. The disadvantage is that an AOE is an additional object of sorts, but we have not had any performance issues with the solution.

#7
Shaughn78

Shaughn78
  • Members
  • 637 messages
Another optinion is to create a trigger that surrounds the fish home. As long as your not in their home, the trigger, everything is good. Once you enter the trigger they turn hostile and if they chase you out of their home/trigger they return to neutral with the exit.