Jump to content

Scripting Error


ErianDragonborn

Recommended Posts

I don't think it's too hard to figure this one out, but I have no idea...
I made this script because I want to have a way of attacking an NPC, make the guards attack you if you do, but make them stop if the NPC is dead. I tried setting the crime gold to 0, but that gave some strange results (the guards were still in attack-mode, tried to arrest me, but I couldn't pay of my bounty, only go to jail. If I then attacked someone else, I got not crime gold anymore.)

 

I have searched for the error with my new script via google, but it didn't realy help me any further. I hope someone sees the problem.

This is the error:

no viable alternative at input '\\r\\n'

 

This is my script:

 

  Quote
Actor Property guard1 auto
Actor Property guard2 auto
Actor Property guard3 auto
Actor Property guard4 auto
Event OnCombatStateChanged(Actor akTarget, int aeCombatState)
if (akTarget == Game.GetPlayer())
if (aeCombatState != 0)
If (IsDead())
guard1.startcombat(Game.GetPlayer())
guard2.startcombat(Game.GetPlayer())
guard3.startcombat(Game.GetPlayer())
guard4.startcombat(Game.GetPlayer())
Elseif
guard1.stopcombat(Game.GetPlayer())
guard2.stopcombat(Game.GetPlayer())
guard3.stopcombat(Game.GetPlayer())
guard4.stopcombat(Game.GetPlayer())
EndIf
endif
endif
endEvent

 

 

 

Link to comment
Share on other sites

That seems logical, but I keep getting the same error, even after I changed it.

Oh, I noticed that it has something to do with the ElseIf line. Elseif should have been Else.
It still is not without problems, but I will try first if I can get it to work.

Edited by ErianDragonborn
Link to comment
Share on other sites

 

Actor Property guard1 auto
Actor Property guard2 auto
Actor Property guard3 auto
Actor Property guard4 auto
 
 
Event OnCombatStateChanged(Actor akTarget, int aeCombatState)
   if (akTarget == Game.GetPlayer())
      if (aeCombatState != 0)
         If !(Game.GetPlayer().IsDead())
            guard1.startcombat(Game.GetPlayer())
            guard2.startcombat(Game.GetPlayer())
            guard3.startcombat(Game.GetPlayer())
            guard4.startcombat(Game.GetPlayer())
         Else
            guard1.stopcombat()
            guard2.stopcombat()
            guard3.stopcombat()
            guard4.stopcombat()
         EndIf
      endif
   endif
endEvent
Link to comment
Share on other sites

I have got the right functionality, but I think it could have been done easier and cleaner than this.

What I now did is give the NPC an identical crime-faction as the one the rest of the town has. I also duplicated the guards that usually walk around town. I added the duplicate to the same crime-faction as the NPC that I wanted to kill.

Then, I also added 4 regular gards to the room and set them to 'initially disabled'.

Now, I added the following script to a trigger around the door:

  Quote

 

Actor Property guard1 auto

Actor Property guard2 auto
Actor Property guard3 auto
Actor Property guard4 auto
EVENT OnTriggerLeave(objectReference triggerRef)
if triggerRef == Game.GetPlayer()
guard1.startcombat(Game.GetPlayer())
guard2.startcombat(Game.GetPlayer())
guard3.startcombat(Game.GetPlayer())
guard4.startcombat(Game.GetPlayer())
EndIf
EndEvent
I added another script to the base-actor of the NPC I wanted to be able to kill. All of the references were to the guards. The references to the old guards are to the duplicate guards and the new guards to the regular guards. This way the bounty shows up when killing the NPC, but will not add up to the bounty you have for that town.
  Quote

 

Actor Property oldguard01 auto

Actor Property oldguard02 auto
Actor Property oldguard03 auto
Actor Property oldguard04 auto
Actor Property newguard01 auto
Actor Property newguard02 auto
Actor Property newguard03 auto
Actor Property newguard04 auto
Event OnDeath(Actor Killer)
oldguard01.Disable()
oldguard02.Disable()
oldguard03.Disable()
oldguard04.Disable()
newguard01.Enable()
newguard02.Enable()
newguard03.Enable()
newguard04.Enable()
EndEvent

 

Edited by ErianDragonborn
Link to comment
Share on other sites

Oh sorry.

 

Oh geez, please no, don't use RegisterForUpdate(). Use RegisterForSingleUpdate() instead.

 

You probably don't need to poll for this, or even a trigger. Just modify the previous script a bit, see what happens.

 

If checks of the target is the player. It checks if the combat state is greater than 0(so if it's 1, you're in combat). Then the guards attack the player. When the NPC dies, they should stop. Just like you want it.

Actor Property guard1 auto
Actor Property guard2 auto
Actor Property guard3 auto
Actor Property guard4 auto
 
 
Event OnCombatStateChanged(Actor akTarget, int aeCombatState)

PlayerRef = Game.GetPlayer() ; You only wanna call this function once.
   if (akTarget == PlayerRef)
        if (aeCombatState > 0) 
                guard1.startcombat(PlayerRef)
                guard2.startcombat(PlayerRef)
                guard3.startcombat(PlayerRef)
                guard4.startcombat(PlayerRef)
        EndIf
    Endif
EndEvent

Event OnDying(Actor akKiller)

    if akKiller == Game.GetPlayer() ; in case you want this to run on the player only.
            guard1.stopcombat()
            guard2.stopcombat()
            guard3.stopcombat()
            guard4.stopcombat()
    endif

EndEvent
 

Oh just incase, make sure you extend this script to actor, and attach to the NPC you want it to run on.

Edited by Terra Nova
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...