Script to count number of NCPs killed

Post » Thu Jan 06, 2011 1:44 am

Hi all..

I need some help with a script. I want a quest stage to update once 3 NCPS have been killed. To do this I thought I could use a script that counts the NCPS as they die.

As per normal my scripts are recycled from other quests in Oblivion…so I took the following script from the Battlehorn plugin that monitors when you have killed the 4 attackers.

scn DLCBattlehornMarauderSCRIPT

begin OnHit player
; trigger next phase of battle if player attacks
setstage DLCBattlehornCastle 20
end

begin OnDeath
set DLCBattlehornCastle.AttackersDead to DLCBattlehornCastle.AttackersDead + 1
if DLCBattlehornCastle.AttackersDead >= 4
setstage DLCBattlehornCastle 28
endif
end


I tried to amend it to this:

scn MiscPONassassinSCRIPT

begin OnDeath
set FH.AttackersDead to FH.AttackersDead + 1
if FH.AttackersDead >= 3
setstage 1MiscPON 30
endif
end

I know I’m missing something ..and I believe it’s the line: set FH.AttackersDead to FH.AttackersDead + 1

The CS isn’t recognising the bit that says AttackersDead…do I have to define this elsewhere? Or is there a better script I can use?
User avatar
dav
 
Posts: 3338
Joined: Mon Jul 30, 2007 3:46 pm

Post » Thu Jan 06, 2011 5:21 am

FH.AttackersDead <-- that is a quest variable, because you have the . (period) in there . The original code uses a quest variable too.

Quest variables have to be declared in a quest script, which must be attached to a new quest.

In this particular case, your quest name would be - FH .. And then in the script you would just put in the rest of the variables name.


To keep it simple for now, what you would do :


Goto the quests tab, right click the listing and select add new quest, give it the name FH

Set it to start game enabled. Set the priority to 90. Click 'Ok' to close the window when done.

Then create a new script under the 'scripts' tab, and just put this in :




Scn AABattleQuestScriptSp


Float AttackersDead



And thats it, no need for gameMode block or anything, just those two lines.

Then open up the quest tab again, find your new quest (FH) and then open the 'script' tab in the window and select that new script. Click ok.

Should be good to go. Hopefully I typed all that correctly :P Should be right tho.

You can actually use that quest script to add tons of new quest variables which can be accessed anywhere.

Quest variables are suggested to be used rather than adding new globals, as per the information I've gotten is that Global variables in mass numbers can begin to cause issues for users.
User avatar
SiLa
 
Posts: 3447
Joined: Tue Jun 13, 2006 7:52 am

Post » Thu Jan 06, 2011 7:53 am

Hi..Thanks for your help so far.

Ive got the script

Scn AABattleQuestScriptSp


Float AttackersDead


attached to my quest. However I'm still having trouble with the script attached to the 3 NCPs that need to be counted as they die.

The script I've tried attaching to the NCPs is:

scn FHNCPScript

begin OnDeath
set FH.AttackersDead to FH.AttackersDead + 1
if FH.AttackersDead >= 3
setstage FH 30
endif
end


This script fails to save. The error given is Line 4 'unknown variable or function AttackersDead' This leads me to think the AttackersDead quest variable is still not correctly defined.

The Original Scripts I used as a template are attached below. I note that the Battlehorn quest script uses a short command as opposed to the float command suggested in the post above. What’s the difference? And is this why the NCP half of the scripting is not working?


Battlehorn Castle quest script.

scn DLCBattlehornCastleScript

float fQuestDelayTime
short TotalBought ; counts number of items purchased

short Sparring ; set to 1 while player is sparring with trainer

short TrophyCount ; counts number of trophies created

ref FollowerRef ; set to knight who is currently following player
short Following ; 0 = no one following; 1 = following; 2 = waiting
short FollowerClear ; set to 1 to clear follower variables

short Following01 ; set to 1 when knight is following player, 2 when waiting
short Following02 ; set to 1 when knight is following player, 2 when waiting
short Following03 ; set to 1 when knight is following player, 2 when waiting
short Following04 ; set to 1 when knight is following player, 2 when waiting
short Following05 ; set to 1 when knight captain is following player, 2 when waiting

short MaidFollow ; set to 1 when maid is following

short AttackersDead ; tracks how many attackers have been killed

begin gamemode

;kickoff block

if ( GetStage DLCBattlehornCastle <= 0 ) && ( Player.IsInCombat == 0 ) && ( GetStage CharacterGen >= 88 ) && ( Player.GetinCell ImperialDungeon03 == 0 )
SetStage DLCBattlehornCastle 10
endif

;arrival trigger

if GetStage DLCBattlehornCastle == 10
if ( Player.GetDistance BattlehornCastleGateREF <= 5000 )
SetStage DLCBattlehornCastle 18
endif
endif

if GetStage DLCBattlehornCastle == 18
if ( Player.GetDistance BattlehornCastleGateREF <= 2000 )
SetStage DLCBattlehornCastle 20
endif
endif


; attackers all dead
if getStage DLCBattlehornCastle < 28
if AttackersDead >= 4
setstage DLCBattlehornCastle 28
endif
endif

; adds forge receipt to vendor after you buy one thing
if TotalBought > 0 && GetStageDone DLCBattlehornCastle 40 == 0
if player.getincell BattlehornCastle == 1
setstage DLCBattlehornCastle 40
DLCBhornKnightRef.Evp
endif
endif

;***Handle clearing of follower variables***

if ( FollowerClear == 1 )
set Following01 to 0
set Following02 to 0
set Following03 to 0
set Following04 to 0
set Following05 to 0
set Following to 0
set FollowerClear to 0
endif


end


The NCP script from Battlehorn Castle

scn DLCBattlehornMarauderSCRIPT

begin OnHit player
; trigger next phase of battle if player attacks
setstage DLCBattlehornCastle 20
end

begin OnDeath
set DLCBattlehornCastle.AttackersDead to DLCBattlehornCastle.AttackersDead + 1
if DLCBattlehornCastle.AttackersDead >= 4
setstage DLCBattlehornCastle 28
endif
end


Incidentally.. I've tried taking the relevant parts out of the above scripts as well but its not worked...I'm sure I'm missing something simple!!
User avatar
Leonie Connor
 
Posts: 3434
Joined: Mon Mar 12, 2007 4:18 pm

Post » Thu Jan 06, 2011 12:29 am

This script fails to save. The error given is Line 4 'unknown variable or function AttackersDead' This leads me to think the AttackersDead quest variable is still not correctly defined.

The Original Scripts I used as a template are attached below. I note that the Battlehorn quest script uses a short command as opposed to the float command suggested in the post above. What’s the difference? And is this why the NCP half of the scripting is not working?
set FH.AttackersDead to FH.AttackersDead + 1

did you name your quest FH ? if yes check for typos in the quest script- btw short variable not command - use code tags and indent your code - otherwise no one will read it ! put large blocks of code into spoiler tags (on top of the code tags)
User avatar
victoria johnstone
 
Posts: 3424
Joined: Sat Oct 14, 2006 9:56 am

Post » Wed Jan 05, 2011 11:19 pm

set FH.AttackersDead to FH.AttackersDead + 1

did you name your quest FH ? if yes check for typos in the quest script- btw short variable not command - use code tags and indent your code - otherwise no one will read it ! put large blocks of code into spoiler tags (on top of the code tags)


Thanks..point noted about the spoiler boxes.

I’m not sure about the typos…I’ll check tonight. But to get whats required straight in my head. I need 3 things to make this work.

1) A quest, in this example I’ll name it QuestName

2) This script attached to QuestName

Scn AABattleQuestScriptSpFloat AttackersDead


3) This script attached to the NCPS

scn QuestNameNCPScriptbegin OnDeathset QuestName.AttackersDead to QuestName.AttackersDead + 1        if QuestName.AttackersDead >= 3                    setstage QuestName 30endifend


Is this correct?
User avatar
gandalf
 
Posts: 3400
Joined: Wed Feb 21, 2007 6:57 pm

Post » Wed Jan 05, 2011 7:31 pm

Thanks..point noted about the spoiler boxes.

I’m not sure about the typos…I’ll check tonight. But to get whats required straight in my head. I need 3 things to make this work.

1) A quest, in this example I’ll name it QuestName

2) This script attached to QuestName

Scn AABattleQuestScriptSpFloat AttackersDead


3) This script attached to the NCPS

scn QuestNameNCPScriptbegin OnDeathset QuestName.AttackersDead to QuestName.AttackersDead + 1        if QuestName.AttackersDead >= 3                    setstage QuestName 30endifend


Is this correct?



Looks right to me :)

You got it, for quest variables to work, they always have to have the quest name , then a dot, then the variable declared in the script which is under that quest.

It is kind of a shame that globals are frowned upon and dont seem to work very well in Oblivion, it certainly would be so much easier...


And the quest name I put in there of course, just a generic name, the two AA's at the start keeps it easy to find in the script listing. Script name can be anything.

You should know too, that although there is a GetDead script command, it is actually somewhat unreliable, especially when dealing with multiple npc's that are killed. I had to completely revise my battle code and get rid of the GetDead commands and stick with all onDeath scripts for each npc, which fixed everything. Unfortunately the wiki says nothing of such, but as soon as I made the switch, all the sudden 'bam' .. all the testers were able to get thru the battle.. Good o'l Oblivion :D
User avatar
Alexis Acevedo
 
Posts: 3330
Joined: Sat Oct 27, 2007 8:58 pm

Post » Thu Jan 06, 2011 5:14 am

Hi again.

I got this script working and it counts the dead bodies as they pile up quite nicely.

However, I've got one further question. This script runs regardless of the quests stage. So, if the quest is advanced without killing off these three NCPs and they are killed later in the game the quest still updates to stage 30 breaking the quest story line.

How could I include a line that says: if (getstage QuestName == 20) run the script. I've tried inserting the line, or a new block to make this work but have failed! Can anyone help me learn how to do this?

scn QuestNameNCPScriptbegin OnDeathset QuestName.AttackersDead to QuestName.AttackersDead + 1        if QuestName.AttackersDead >= 3                    setstage QuestName 30endif

User avatar
WTW
 
Posts: 3313
Joined: Wed May 30, 2007 7:48 pm

Post » Thu Jan 06, 2011 2:55 am

does this work ?

scn QuestNameNCPScriptbegin OnDeathif GetStageDone QuestName  20        returnendifset QuestName.AttackersDead to QuestName.AttackersDead + 1if QuestName.AttackersDead >= 3        setstage QuestName 30endifend

User avatar
Lucie H
 
Posts: 3276
Joined: Tue Mar 13, 2007 11:46 pm


Return to IV - Oblivion