Jump to content

Need Some Scripting Help


Recommended Posts

I have a script that I wrote for Skyrim. I came from Fallout 4, so I realize that a lot of features in FO4 creation kit arent there...but I feel like my code should be working, but I have no idea why it isn't. Any clues? It's a Quest script by the way. What it does is, when the player equips a weapon from my mod that has the keyword that matches their race (the weapons are racial weapons), they get a small perk that buffs them. WHen they dont have it equipped, it removes the perk.

Scriptname TCOSS_RSRaceQuestScript extends Quest  


Actor player
Race Property ArgonianRace Auto 
Race Property ArgonianRaceVampire Auto 
Race Property BretonRace Auto 
Race Property BretonRaceVampire Auto 
Race Property DarkElfRace Auto 
Race Property DarkElfRaceVampire Auto 
Race Property HighElfRace Auto 
Race Property HighElfRaceVampire Auto 
Race Property ImperialRace Auto 
Race Property ImperialRaceVampire Auto 
Race Property KhajiitRace Auto 
Race Property KhajiitRaceVampire Auto 
Race Property NordRace Auto 
Race Property NordRaceVampire Auto 
Race Property OrcRace Auto 
Race Property OrcRaceVampire Auto 
Race Property RedguardRace Auto 
Race Property RedguardRaceVampire Auto 
Race Property WoodElfRace Auto 
Race Property WoodElfRaceVampire Auto 

Keyword Property WeapMaterialRSArgonian Auto 
Keyword Property WeapMaterialRSAylied Auto 
Keyword Property WeapMaterialRSBosmer Auto 
Keyword Property WeapMaterialRSBreton Auto 
Keyword Property WeapMaterialRSDaedric Auto 
Keyword Property WeapMaterialRSDunmer Auto 
Keyword Property WeapMaterialRSHighElf Auto 
Keyword Property WeapMaterialRSImperial Auto 
Keyword Property WeapMaterialRSKhajiit Auto 
Keyword Property WeapMaterialRSLegend Auto 
Keyword property WeapMaterialRSNord Auto 
Keyword Property WeapMaterialRSOrc Auto 
Keyword Property WeapMaterialRSRedguard Auto 

bool rsWeaponAlreadyEquipped
Race[] RaceToIndex
int[] RaceIndexToRaceDataIndex
Race playerRace
Keyword[] RSRaceKeyword
string[] DisplayText
string[] DisplayTextUnEquip
Perk TCOSS_RSRacePerk

Event OnQuestInit()
	TraceAndNotify("OnQuestInit()", True)
	player = Game.GetPlayer()
    ReInit()
EndEvent

Event OnPlayerLoadGame()
	TraceAndNotify("OnPlayerLoadGame()")
	ReInit()
EndEvent

Function ReInit()
    Debug.Trace("Initializing Races...")
    ;Race Array    
	RaceToIndex = New Race [20]
	RaceToIndex[0] = ArgonianRace 
	RaceToIndex[1] = ArgonianRaceVampire
	RaceToIndex[2] = BretonRace
	RaceToIndex[3] = BretonRaceVampire
	RaceToIndex[4] = DarkElfRace
	RaceToIndex[5] = DarkElfRaceVampire
	RaceToIndex[6] = HighElfRace
	RaceToIndex[7] = HighElfRaceVampire
	RaceToIndex[8] = ImperialRace
	RaceToIndex[9] = ImperialRaceVampire
	RaceToIndex[10] = KhajiitRace
	RaceToIndex[11] = KhajiitRaceVampire
	RaceToIndex[12] = NordRace
	RaceToIndex[13] = NordRaceVampire
	RaceToIndex[14] = OrcRace
	RaceToIndex[15] = OrcRaceVampire
	RaceToIndex[16] = RedguardRace
	RaceToIndex[17] = RedguardRaceVampire
	RaceToIndex[18] = WoodElfRace
	RaceToIndex[19] = WoodElfRaceVampire

	RaceIndexToRaceDataIndex = New int [20]
	RaceIndexToRaceDataIndex[0] = 0
	RaceIndexToRaceDataIndex[1] = 0
	RaceIndexToRaceDataIndex[2] = 1
	RaceIndexToRaceDataIndex[3] = 1
	RaceIndexToRaceDataIndex[4] = 2
	RaceIndexToRaceDataIndex[5] = 2
	RaceIndexToRaceDataIndex[6] = 3
	RaceIndexToRaceDataIndex[7] = 3
	RaceIndexToRaceDataIndex[8] = 4
	RaceIndexToRaceDataIndex[9] = 4
	RaceIndexToRaceDataIndex[10] = 5
	RaceIndexToRaceDataIndex[11] = 5
	RaceIndexToRaceDataIndex[12] = 6
	RaceIndexToRaceDataIndex[13] = 6
	RaceIndexToRaceDataIndex[14] = 7
	RaceIndexToRaceDataIndex[15] = 7
	RaceIndexToRaceDataIndex[16] = 8
	RaceIndexToRaceDataIndex[17] = 8
	RaceIndexToRaceDataIndex[18] = 9
	RaceIndexToRaceDataIndex[19] = 9

	RSRaceKeyword = New Keyword [10]
	RSRaceKeyword[0] = WeapMaterialRSArgonian
	RSRaceKeyword[1] = WeapMaterialRSBreton
	RSRaceKeyword[2] = WeapMaterialRSDunmer
	RSRaceKeyword[3] = WeapMaterialRSAylied
	RSRaceKeyword[4] = WeapMaterialRSImperial
	RSRaceKeyword[5] = WeapMaterialRSKhajiit
	RSRaceKeyword[6] = WeapMaterialRSNord
	RSRaceKeyword[7] = WeapMaterialRSOrc
	RSRaceKeyword[8] = WeapMaterialRSRedguard
	RSRaceKeyword[9] = WeapMaterialRSBosmer


	DisplayText = New String [10]
	DisplayText[0] = "The Hist whispers approval in your mind as you take up a weapon of the Root. You are empowered."
	DisplayText[1] = "You feel the salt and warmth of the Iliac Bay on your skin as you draw a weapon of High Rock. You are empowered."
	DisplayText[2] = "You taste the bitter ashes of Morrowind as you grip a weapon of the Dunmer. You are empowered."
	DisplayText[3] = "The sound of the waves breaking upon the crystalline shores of Alinor comes to your ears as you take up a weapon of your people. You are empowered."	
	DisplayText[4] = "The tall and mighty White Gold Tower casts a shadow on you as you hold a weapon of Cyrodiil. You are empowered."
	DisplayText[5] = "You feel the warm sands of Elsweyr between your toes as you hold aloft a weapon of the Khajiit. You are empowered."
	DisplayText[6] = "The northern Skyrim winds blow strongly around you as you wield a weapon of your ancestors. You are empowered."
	DisplayText[7] = "The Spirit of Malacath fills you with bloodlust as you wield a weapon of your people. You are empowered."
	DisplayText[8] = "The proud ancestors of old Yokuda guide your hand as you bring forth a weapon of your people. You are empowered."
	DisplayText[9] = "You smell the sap of the trees of Valenwood as you hold a weapon of your people. You are empowered."

	DisplayTextUnEquip = New string [10]
	DisplayTextUnEquip[0] = "The whispers fade as you lay down the weapon."
	DisplayTextUnEquip[1] = "The warmth fades as you lay down the weapon."
	DisplayTextUnEquip[2] = "The taste of ash vanishes as you lay down the weapon."
	DisplayTextUnEquip[3] = "The dull whistle of the gales of Skyrim drown out the waves as you lay down the weapon."
	DisplayTextUnEquip[4] = "The shadow passes as you lay down the weapon."
	DisplayTextUnEquip[5] = "The sand turns to rocky tundra under your feet as you lay down the weapon."
	DisplayTextUnEquip[6] = "The winds falter as you lay down the weapon."
	DisplayTextUnEquip[7] = "Your nerves calm as you lay down the weapon."
	DisplayTextUnEquip[8] = "The spirits vanish as you lay down the weapon."
	DisplayTextUnEquip[9] = "The smell dissipates as you lay down the weapon."

EndFunction

;Check what Item is equipped vs the Race of the player
Event OnItemEquipped(Actor akSender, Form akBaseObject, ObjectReference akReference) 
	RSRaceChecker() 
EndEvent

Event OnItemUnequipped(Form akBaseObject, ObjectReference akReference) 
    playerRace = player.GetRace()
	int RaceIndexValue = RaceIndexToRaceDataIndex[RaceToIndex.Find(playerRace)]	
	if player.WornHasKeyword(RSRaceKeyword[RaceIndexValue]) ;if At least one equipped item has the keyword, avoid showing text
		;Do Nothing
	else ;if nothing equipped has that keyword when you unequipped then...
		if rsWeaponAlreadyEquipped ;if a rsweapon was equipped at the time Onunequipped happened, play the unequip text
			TraceAndNotify(DisplayTextUnEquip[RaceIndexValue])
			RemoveRealswordsPerk()
		endif
	endif
EndEvent

Function RSRaceChecker()
	playerRace = player.GetRace()
	int RaceIndexValue = RaceIndexToRaceDataIndex[RaceToIndex.Find(playerRace)]
	if player.WornHasKeyword(RSRaceKeyword[RaceIndexValue]) ;Check to see if the player has the keyword matching their race
		if !rsWeaponAlreadyEquipped ;no RSweapons are already equipped
			TraceAndNotify(DisplayText[RaceIndexValue]) ;display text for equip
			AddRealswordsPerk() ;add the perk
		endif
	else ; if the player doesnt have the keyword and equipped a weapon...
		if rsWeaponAlreadyEquipped ;and the flag for an RS weapon type was already on.
			TraceAndNotify(DisplayTextUnEquip[RaceIndexValue]) ;display unequip text
			RemoveRealswordsPerk() ;remove RSperk and toggle rsEquipped flag
		endif
	endif
EndFunction

Function AddRealswordsPerk()
	TraceAndNotify("AddRealswordsPerk()", True)
	if !player.HasPerk(TCOSS_RSRacePerk)
		player.AddPerk(TCOSS_RSRacePerk)
	EndIf
	rsWeaponAlreadyEquipped = True
EndFunction

Function RemoveRealswordsPerk()
	TraceAndNotify("RemoveRealswordsPerk()", True)
	if player.HasPerk(TCOSS_RSRacePerk)
		player.RemovePerk(TCOSS_RSRacePerk)
	EndIf
	rsWeaponAlreadyEquipped = False
EndFunction

Function TraceAndNotify(string msg, bool TraceOnly = False) ;debugging purposes
	Debug.Trace(msg)
	if !TraceOnly
		Debug.Notification(msg)
	EndIf
EndFunction

Link to comment
Share on other sites

Why not just add a script that adds the perk to the actor when equipped, and add a condition to the perk so as to only make it work for its specific race?

 

Wuuthrad already has a ready-to-use script that adds a perk to the actor when its equipped

 

 

Or do you only want it to work while the quest is active? (Assuming your quest doesnt auto start, like controller quests)

Link to comment
Share on other sites

You'll need to rethink your script a bit. Not all of that will run on a quest script.

 

OnQuestInit <-- is not a Skyrim event. Use OnInit instead

OnPlayerLoadGame <-- does not run on a quest script. Can only run on a reference alias script for the player.

OnItemEquipped <-- Skyrim version is OnObjectEquipped and can only run on an actor script or reference alias script

OnItemUnequipped <-- Same as the above. OnObjectUnequipped

Link to comment
Share on other sites

  • Recently Browsing   0 members

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