Jump to content

Quick question about a simple script


Legotrash

Recommended Posts

I made this script but I couldn't figure out how to make it work with an if statement in one block so I made it with a second block starting with begin.Everything works as intended but I'd really appreciate if someone with more experience in scripting than me (and I have none experience really) can tell me if everything's fine with it.

 

ScriptName aaStaticAlchemyScript

short doOnce

 

Begin OnActivate Player

Player.AddItem RetortMaster 1

Player.AddItem MortarPestleMaster 1

Player.AddItem CalcinatorMaster 1

Player.AddItem AlembicMaster 1

Player.EquipItem CalcinatorMaster

Set doOnce to 1

End

 

Begin GameMode

If doOnce == 1

Player.RemoveItem RetortMaster 1

Player.RemoveItem MortarPestleMaster 1

Player.RemoveItem CalcinatorMaster 1

Player.RemoveItem AlembicMaster 1

Set doOnce to 0

EndIf

End

 

Making a second block makes me feel a bit uneasy about it that's why I thought I should ask about it.

Link to comment
Share on other sites

To prevent adding all items and then removing them, why not go for a script that checks your player's inventory, and uses an appropriate item? If none, then the standard M&P is used. Here is my static alchemy script from the Highwood mod:

 

 

ScriptName HighwoodStaticAlchemyScript

;Script by Hickory

Short borrowed

Begin OnActivate

If ( IsActionRef Player == 1 )

	; Have to have a Mortar & Pestle to make potions
	If ( Player.GetItemCount MortarPestle == 0 ) && ( Player.GetItemCount CGMortarPestle == 0 )
		Player.AddItem MortarPestle 1
		Set borrowed To 1
	EndIf
		
	; Equip Master first
	If ( Player.GetItemCount MortarPestleMaster > 0 )
		Player.EquipItem MortarPestleMaster
		Return
	ElseIf ( Player.GetItemCount RetortMaster > 0 )
		Player.EquipItem RetortMaster
		Return
	ElseIf ( Player.GetItemCount AlembicMaster > 0 )
		Player.EquipItem AlembicMaster
		Return
	ElseIf ( Player.GetItemCount CalcinatorMaster > 0 )
		Player.EquipItem CalcinatorMaster
		Return

	; Equip Expert if no Master
	ElseIf ( Player.GetItemCount MortarPestleExpert > 0 )
		Player.EquipItem MortarPestleExpert
		Return
	ElseIf ( Player.GetItemCount RetortExpert > 0 )
		Player.EquipItem RetortExpert
		Return
	ElseIf ( Player.GetItemCount AlembicExpert > 0 )
		Player.EquipItem AlembicExpert
		Return
	ElseIf ( Player.GetItemCount CalcinatorExpert > 0 )
		Player.EquipItem CalcinatorExpert
		Return

	; Equip Journeyman if no Expert
	ElseIf ( Player.GetItemCount MortarPestleJourneyman > 0 )
		Player.EquipItem MortarPestleJourneyman
		Return
	ElseIf ( Player.GetItemCount RetortJourneyman > 0 )
		Player.EquipItem RetortJourneyman
		Return
	ElseIf ( Player.GetItemCount AlembicJourneyman > 0 )
		Player.EquipItem AlembicJourneyman
		Return
	ElseIf ( Player.GetItemCount CalcinatorJourneyman > 0 )
		Player.EquipItem CalcinatorJourneyman
		Return

	; Equip Apprentice if no Journeyman
	ElseIf ( Player.GetItemCount MortarPestleApprentice > 0 )
		Player.EquipItem MortarPestleApprentice
		Return
	ElseIf ( Player.GetItemCount RetortApprentice > 0 )
		Player.EquipItem RetortApprentice
		Return
	ElseIf ( Player.GetItemCount AlembicApprentice > 0 )
		Player.EquipItem AlembicApprentice
		Return
	ElseIf ( Player.GetItemCount CalcinatorApprentice > 0 )
		Player.EquipItem CalcinatorApprentice
		Return
		
	; Equip Novice if no Journeyman
	ElseIf ( Player.GetItemCount Retort > 0 )
		Player.EquipItem Retort
		Return
	ElseIf ( Player.GetItemCount Alembic > 0 )
		Player.EquipItem Alembic
		Return
	ElseIf ( Player.GetItemCount Calcinator > 0 )
		Player.EquipItem Calcinator
		Return
	ElseIf ( Player.GetItemCount MortarPestle > 0 )
		Player.EquipItem MortarPestle
		Return
	Else
		Player.EquipItem MortarPestle
		
	Endif
	
Endif

End

Begin GameMode

IF ( borrowed != 1 )
	Return
Else
	Player.RemoveItem MortarPestle 1
	Set borrowed To 0
EndIf


End

 

Link to comment
Share on other sites

Thanks for the reply!

 

I did it while having in mind "Listener Overhaul",it's supposed to equip the player with master leveled equipment.I saw that there are others bothered by the mod's alchemy script (very nice mod though) so I thought to upload a fix for it.Other than that,this is my first time scripting so I wanted to keep it simple. :biggrin:

 

Your script is only set to equip the player with what he has in his inventory or the equip command can also add the specific item?

 

 

By the way,should I consider my script ok? I was wondering about my second block,it wont keep on running if "doOnce == 0",right?

Link to comment
Share on other sites

Thanks for the reply!

 

I did it while having in mind "Listener Overhaul",it's supposed to equip the player with master leveled equipment.I saw that there are others bothered by the mod's alchemy script (very nice mod though) so I thought to upload a fix for it.Other than that,this is my first time scripting so I wanted to keep it simple. :biggrin:

 

Your script is only set to equip the player with what he has in his inventory or the equip command can also add the specific item?

 

 

By the way,should I consider my script ok? I was wondering about my second block,it wont keep on running if "doOnce == 0",right?

 

Your script is ok, (sort of). The set doOnce should be at the beginning, or at least not at the end of the first block, because when you equip the item the OnActivate block stops running.

 

You should also get into the habit of using 'Return' in GameMode blocks where possible, to negate processing the whole of the script every frame. It's good optimisation practice. I would do it like this:

 

ScriptName aaStaticAlchemyScript
short doOnce

Begin OnActivate Player
Set doOnce to 1
Player.AddItem RetortMaster 1
Player.AddItem MortarPestleMaster 1
Player.AddItem CalcinatorMaster 1
Player.AddItem AlembicMaster 1
Player.EquipItem CalcinatorMaster
End

Begin GameMode
If doOnce == 0
	Return
Else
	Set doOnce to 0
	Player.RemoveItem RetortMaster 1
	Player.RemoveItem MortarPestleMaster 1
	Player.RemoveItem CalcinatorMaster 1
	Player.RemoveItem AlembicMaster 1
EndIf
End

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

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