Scratching my head over a script

Post » Tue Dec 29, 2009 12:14 pm

So I'm nearly finished with a mod that patches some sense into a few Mages' Guild quests, and need Telvanni players who are also Guildmages to be able to call in a Morag Tong hit on Trebonius when he tells the player to kill all the Telvanni councillors. I'm flying by the seat of my pants on this since I have approximately jack all scripting experience, but reading Morrowind Scripting For Dummies and examining some scripts that are already in the game produced this:

Begin PL_TrebDeathif ( GetJournalIndex MG_KillTelvanni >= 100 )	Return	;If MG_KillTelvanni is completed, script does nothingelseif ( MenuMode == 1 )	Returnelseif ( GetJournalIndex MG_KillTelvanni < 50 )	PL_necromancers_amulet -> disable	Return	;Disables non-carried clone of Necromancer's Amulet until Trebonius is assassinatedendifif ( GetPCCell "Vivec, Guild of Mages" == 1 )	Return	;Make sure PC isn't present when Trebonius gets whackedendifif ( GetDeadCount "Trebonius Artorius" > 0 )	Return	;If PC has already killed Trebonius, don't botherendifif ( GetJournalIndex MG_KillTelvanni >= 50 )	"Trebonius Artorius" -> positioncell "Vivec, Guild of Mages" -557 440 -757 92	"Trebonius Artorius" -> sethealth 0	;kills Trebonius, places corpse in his quarters	PL_necromancers_amulet -> enable	;Places amulet next to corpse, in case corpse decaysendifif ( GetDistance Player <= 256 )	journal MG_KillTelvanni 110endifEnd PL_TrebDeath


For the life of me, I can't see anything wrong with it, but I get errors when I try to save: it says stuff about "function reference object not found" on line 9 and "miss mached quotes" on line 25. What the bargle is going on here?
User avatar
FirDaus LOVe farhana
 
Posts: 3369
Joined: Thu Sep 13, 2007 3:42 am

Post » Tue Dec 29, 2009 2:03 pm

PL_necromancers_amulet -> disable

If this line gives you an error, it is likely that there is either no reference of this object placed in the game world, or that its references are not persistent. You need to have it placed in the editor, placing it from a script is not adequate. You can change persistence in the object's properties window. (Persistent objects have an inpact on the game's memory use, even when they are in an unloaded cell.)

Now, in my opinion it's much better if you handle this disabling part on the object's local script. There you can make sure there are no issues like what may happen when the player has already taken that item before the script disables it. (If it can be taken, that is.)

Also, there is a syntax error in that line because there must not be a space before the reference operator: ->
And it's probably safer not to have one after it either, Morrowind is kinda picky with its syntax.

The same syntax issue is present in this line, and in some of the lines below it:

"Trebonius Artorius" -> positioncell "Vivec, Guild of Mages" -557 440 -757 92

Changing it to this makes it compile without errors:

"Trebonius Artorius"->positioncell "Vivec, Guild of Mages" -557 440 -757 92

User avatar
Kill Bill
 
Posts: 3355
Joined: Wed Aug 30, 2006 2:22 am

Post » Tue Dec 29, 2009 2:08 pm

Thanks Adul, it compiles now. I doubt there will be problems with what happens when the player takes it before it is disabled, because it should be disabled from the start - that's why I didn't put the script on the amulet itself; I think I heard somewhere that scripts attached to disabled objects don't function. If I could have done without the cloned amulet I would have (because now it's incompatible with replacers) but with the disabling script, I was worried about what you said concerning disabling an object that the player has... the real necromancer's Amulet is unique in the vanilla game, but someone may have modded a way to get another one in which case that could open a can of worms.
User avatar
mimi_lys
 
Posts: 3514
Joined: Mon Apr 09, 2007 11:17 am

Post » Tue Dec 29, 2009 9:53 am

scripts attached to disabled things function. i use scripts on NPCs to keep some disabled till the player is a certain rank in an appropriate faction, and now also to keep my legion patrols "away" before you order them to set out.
User avatar
Stephanie Kemp
 
Posts: 3329
Joined: Sun Jun 25, 2006 12:39 am

Post » Tue Dec 29, 2009 7:03 am

Can I add a question? :unsure:

I got this script from Doormouse a long time ago, it is for a Mehrunes Fatal Strike sort of thing like the Razor had in TESIV and TESII, where there is a % chance that an attack will instantly kill an enemy.

I tried to copy and paste the code into a script in my .esp, but it refuses to compile. I know nothing about coding, so I'm at a loss as to what to do. Would someone be so kind as to help? The error mentions something about not finding Setx on line 20... =/ I can try to get more details if needed.

Begin MehrunesRazorlong PCReflong Targetshort Hitshort Healthshort Luckshort Bladeshort Successshort Failureif ( Player->HasItemEquipped "mehrunes'_razor_unique" == 0 )	Returnendifif ( Player->GetWeaponDrawn == 0 )	ReturnendifSetx PCRef to xGetRef "Player"Setx Target to PCRef->xGetCombatif ( Target == 0 )	ReturnendifxSetRef TargetSet Hit to GetSoundPlaying "Destruction Hit"if ( Hit == 0 )	ReturnendifxSetRef TargetStopSound "Destruction Hit"PlaySound "Destruction Hit"xSetRef TargetSet Health to GetHealthif ( Health > 500 )	ReturnendifSet Luck to ( Player->GetLuck )Set Blade to ( Player->GetShortBlade )Set Success to ( Luck * 0.075 + Blade * 0.025 )Set Failure to Random, 100if ( GetPCSneaking == 1 )	if ( GetDetected "Player" == 0 )		Set Success to ( Success * 2 )	endifendifif ( Failure > Success )	ReturnendifXSetRef TargetSetHealth 0PlaySound "Thunder0"MessageBox "I, Mehrunes Dagon, banish you to Oblivion!"End

User avatar
jessica robson
 
Posts: 3436
Joined: Mon Oct 09, 2006 11:54 am

Post » Tue Dec 29, 2009 7:40 pm

It is a MWSE script, so it needs to be compiled with MWEDIT.
User avatar
Neliel Kudoh
 
Posts: 3348
Joined: Thu Oct 26, 2006 2:39 am

Post » Tue Dec 29, 2009 8:09 pm

Yes, scripts do run on disabled objects. I would probably solve the situation by creating a clone for the amulet and place it in the game world. Its local script would look something like this:

Begin somescriptshort doonceif ( doonce == 2 )	Returnif ( doonce == 1 )	if ( GetDisabled == 1 )		if ( GetJournalIndex, "somejournalindex" >= 50 )			Enable		endif	endif	if ( OnActivate == 1 )		"player"->AddItem, "necromancers_amulet_uniq", 1		Disable		set doonce to 2	endifelse	Disable	set doonce to 1endifEnd

This way the clone amulet only appears when the appropriate quest stage is triggered and is replaced by the real amulet when the player takes it.
User avatar
Dean Ashcroft
 
Posts: 3566
Joined: Wed Jul 25, 2007 1:20 am

Post » Tue Dec 29, 2009 5:53 am

Okay, I went over the script again and worked it (hopefully) so that the Necromancer's Amulet clone no longer needs to be used, so as to avoid incompatibilities with mods that alter the Amulet - the part that makes sure the player isn't present when Trebonius dies is now handled by simply not giving them the MG_KillTelvanni 50 journal entry unless they aren't in the guildhall:

Begin PL_TrebDeath_Journal;Global script for giving player the journal entry that Trebonius has been killed;Based on stronghold building scripts - script is started by dialogue entriesshort DaysPassedshort CurrentDayif ( GetJournalIndex MG_KillTelvanni < 20 )	returnelseif  ( MenuMode == 1 )	returnelseif ( GetJournalIndex MG_KillTelvanni >= 50 )	StopScript PL_TrebDeath_Journalendifif ( DaysPassed == 0 )		set CurrentDay to Day		set daysPassed to 1endifif ( CurrentDay != Day )	;presumably it went up...	set daysPassed to daysPassed + 1	set CurrentDay to Dayendif;wait 2 days for hit, give journal;make sure player is NOT in the cell while Trebonius gets whackedif ( GetPCCell "Vivec, Guild of Mages" == 0 )	if ( daysPassed > 2 )		Journal MG_KillTelvanni 50	endifendifEnd PL_TrebDeath_Journal


Begin PL_TrebDeath;Placed on a miscellaneous object just below the floor in Trebonius quartersif ( GetJournalIndex MG_KillTelvanni >= 100 )	Return	;If MG_KillTelvanni is completed, script does nothingelseif ( MenuMode == 1 )	Returnelseif ( GetDeadCount "Trebonius Artorius" > 0 )	Return	;If PC has already killed Trebonius, script does nothingelseif ( GetJournalIndex MG_KillTelvanni < 50 )	Return	;do nothing until PC gets journal entry that Trebonius should be deadendifif ( GetJournalIndex MG_KillTelvanni >= 50 )	"Trebonius Artorius"->positioncell "Vivec, Guild of Mages" -557 440 -757 92	"Trebonius Artorius"->sethealth 0	"Trebonius Artorius"->removeitem necromancers_amulet_uniq 1	;kills Trebonius, places corpse in his quarters, removes amulet from body	if ( GetPCCell "Vivec, Guild of Mages" == 1 )		PlaceItemCell "necromancers_amulet_uniq" "Vivec, Guild of Mages" -513 379 -767 0		;puts amulet next to body so it is not lost if corpse decays	endifendifif ( GetDistance Player <= 256 )	journal MG_KillTelvanni 110	;Player gets quest-is-finished journal entry when they see the corpseendifEnd PL_TrebDeath


Anyone see anything devastatingly wrong with this, or am I good to go?
User avatar
Jack Moves
 
Posts: 3367
Joined: Wed Jun 27, 2007 7:51 am


Return to III - Morrowind