Ninjaluxray7685 Posted September 2 Share Posted September 2 (edited) so i have been letting chatgpt teach me how to script because i couldn't find a video to teach me how to create a 1-20 chance roll system for a object to simulate rolling a d20 but for what ever reason its failing the save with a error here is my script and screenshot of my work can some one please help me im getting annoyed trying to make this work error i get is "ApplySpell is not a function or does not exist" or when i change applyspell > cast i get "Cast is not a function or does not exist" Spoiler Scriptname SaintCastTreasureScript extends ObjectReference MiscObject Property SaintCastTreasure Auto ; Reference to the Saint Cast Treasure item Weapon Property BladeOfDestiny Auto ; Reference to the Blade of Destiny Spell Property StunEffect Auto ; Reference to the Stun spell/effect Spell Property FearEffect Auto ; Reference to the Fear spell/effect Spell Property CritFailEffect Auto ; Reference to the Crit Fail effect (e.g., summon a Dremora) Spell Property BoostEffect Auto ; Reference to the temporary stat boost effect Spell Property InstantKillEffect Auto ; Reference to the Instant Kill effect Message Property MsgCritFail Auto ; Reference to the Crit Fail message box Message Property MsgStun Auto ; Reference to the Stun message box Message Property MsgFear Auto ; Reference to the Fear message box Message Property MsgBoost Auto ; Reference to the Boost message box Message Property MsgInstantKill Auto ; Reference to the Instant Kill message box Message Property MsgDrainMagickaStamina Auto ; Reference to the Drain Magicka and Stamina message box Form Property Gold001 Auto ; Reference to the gold item Form Property DragonBone Auto ; Reference to the Dragon Bone item Form Property DaedraHeart Auto ; Reference to the Daedra Heart item Form Property DragonScales Auto ; Reference to the Dragon Scales item Event OnEquipped(Actor akActor) ; Only run the script if the player interacts with the Saint Cast Treasure if akActor == Game.GetPlayer() int rollResult = Utility.RandomInt(1, 20) ; Handle the different roll outcomes if rollResult == 1 MsgCritFail.Show() akActor.Cast(CritFailEffect, akActor) ; Apply Crit Fail Effect (e.g., summon a Dremora) elseif rollResult >= 2 && rollResult <= 6 MsgDrainMagickaStamina.Show() akActor.DamageActorValue("Magicka", 50) akActor.DamageActorValue("Stamina", 50) elseif rollResult >= 7 && rollResult <= 11 MsgStun.Show() akActor.Cast(StunEffect, akActor) ; Apply Stun Effect directly to the actor elseif rollResult >= 12 && rollResult <= 17 MsgFear.Show() akActor.Cast(FearEffect, akActor) ; Apply Fear Effect directly to the actor elseif rollResult >= 18 && rollResult <= 19 MsgBoost.Show() akActor.Cast(BoostEffect, akActor) ; Apply Boost Effect directly to the actor elseif rollResult == 20 MsgInstantKill.Show() akActor.Cast(InstantKillEffect, akActor) ; Apply Instant Kill Effect directly to the actor ; Add rewards to the player Game.GetPlayer().AddItem(Gold001, 250) Game.GetPlayer().AddItem(DragonBone, 1) Game.GetPlayer().AddItem(DaedraHeart, 1) Game.GetPlayer().AddItem(DragonScales, 3) endif endif EndEvent Edited September 2 by redlink32 Link to comment Share on other sites More sharing options...
IsharaMeradin Posted September 2 Share Posted September 2 The correct syntax for Cast is: mySpell.Cast(mySource,myTarget) The reason it is creating an error is that Cast is a function on the Spell script rather than the Actor script. Thus having the actor call Cast results in the error you are seeing. 1 Link to comment Share on other sites More sharing options...
Ninjaluxray7685 Posted September 2 Author Share Posted September 2 i also realize i didnt make spells so i fixed that akActor.Cast(InstantKillEffect, akActor) RNGInstantKillSpell.Cast(mySource, akActor) for "mysource" would it be InstantKillEffect or RNGInstantKillSpell Link to comment Share on other sites More sharing options...
Ninjaluxray7685 Posted September 2 Author Share Posted September 2 (edited) so i fixed the script thank you by the way but now i have a new issue i am trying to compile a script for the weaker blade where crafting has a chance to apply a 1, 2, or 3 random enchantments here is the script i am deciding to use the base enchantments provided by the game so i dont have to make new ones i hope but i am getting this and do not know what this means Spoiler Scriptname BladeOfChanceCraftScript extends ObjectReference ; Base Enchantment properties Enchantment Property FireDamageEnchantment Auto Enchantment Property FrostDamageEnchantment Auto Enchantment Property ShockDamageEnchantment Auto Enchantment Property AbsorbHealthEnchantment Auto Enchantment Property BanishEnchantment Auto Enchantment Property ParalyzeEnchantment Auto Enchantment Property MagickaAbsorbEnchantment Auto Enchantment Property StaminaAbsorbEnchantment Auto Enchantment Property TurnUndeadEnchantment Auto Enchantment Property FearEnchantment Auto Enchantment Property SoulTrapEnchantment Auto Weapon Property BladeOfChance Auto ; Reference to the Blade of Chance Event OnInit() ; Ensure the script is for the correct weapon if Self == BladeOfChance ; Array of possible enchantments Enchantment[] enchantments = new Enchantment[11] enchantments[0] = FireDamageEnchantment enchantments[1] = FrostDamageEnchantment enchantments[2] = ShockDamageEnchantment enchantments[3] = AbsorbHealthEnchantment enchantments[4] = BanishEnchantment enchantments[5] = ParalyzeEnchantment enchantments[6] = MagickaAbsorbEnchantment enchantments[7] = StaminaAbsorbEnchantment enchantments[8] = TurnUndeadEnchantment enchantments[9] = FearEnchantment enchantments[10] = SoulTrapEnchantment ; Random number to decide the number of enchantments int roll = Utility.RandomInt(1, 20) int numEnchantments = 0 ; Determine how many enchantments to apply based on the roll if roll == 8 ; Group 1: 3 random enchantments numEnchantments = 3 elseif roll == 2 || roll == 9 || roll == 14 ; Group 2: 2 random enchantments numEnchantments = 2 elseif roll == 1 || roll == 3 || roll == 4 || roll == 5 || roll == 6 || roll == 10 || roll == 11 || roll == 18 ; Group 3: 1 random enchantment numEnchantments = 1 else ; Group 4: no enchantment numEnchantments = 0 endif ; Shuffle the array for randomness int length = 11 ; The length of the array int i = 0 int j = 0 Enchantment temp while i < length j = Utility.RandomInt(0, length - 1) ; Swap elements at indices i and j temp = enchantments enchantments = enchantments[j] enchantments[j] = temp i += 1 endwhile ; Apply enchantments to the weapon int k = 0 while k < numEnchantments if k == 0 Self.SetEnchantment(enchantments[k]) else Self.AddEnchantment(enchantments[k]) endif k += 1 endwhile endif EndEvent Errors Breakdown Error at Line 55, Column 8: no viable alternative at input 'int' Explanation: This error typically indicates a problem with how the int keyword or variable declarations are used in the script. Papyrus might be expecting a different syntax or context. Error at Line 55, Column 19: required (...)+ loop did not match anything at input '=' Explanation: This error often occurs if there is a syntax issue with how variables are assigned or if there is an error with loop constructs. Edited September 2 by Ninjaluxray7685 Link to comment Share on other sites More sharing options...
IsharaMeradin Posted September 3 Share Posted September 3 I'll be honest, I'm a little lost on what it is you are trying to do with that last script. If you provide a bit more information on what you want to have happen, I could see if I can theory craft some code for it. Link to comment Share on other sites More sharing options...
scorrp10 Posted September 3 Share Posted September 3 Formlist property enchlist auto ;empty formlist enchlist.revert() enchlist.addform(FireDamageEnchantment) enchlist.addform(FrostDamageEnchantment) enchlist.addform(ShockDamageEnchantment) enchlist.addform(AbsorbHealthEnchantment) enchlist.addform(BanishEnchantment) enchlist.addform(ParalyzeEnchantment) enchlist.addform(MagickaAbsorbEnchantment) enchlist.addform(StaminaAbsorbEnchantment) enchlist.addform(TurnUndeadEnchantment) enchlist.addform(FearEnchantment) enchlist.addform(SoulTrapEnchantment) int roll = utility.randomint(1, 20) while roll > 8 enchantment ench = enchlist.getat(utility.randomint(0, enchlist.getsize() - 1)) as enchantment if enchlist.getsize() == 11 self.setEnchantment(ench) roll = roll - 8 else self.addEnchantment(ench) roll = roll - 3 endif enchlist.removeaddedform(ench) endwhile Link to comment Share on other sites More sharing options...
Ninjaluxray7685 Posted September 3 Author Share Posted September 3 (edited) 12 hours ago, IsharaMeradin said: I'll be honest, I'm a little lost on what it is you are trying to do with that last script. If you provide a bit more information on what you want to have happen, I could see if I can theory craft some code for it. Core Concept: You want the Blade of Chance to have random enchantments every time it is crafted or initialized. A D20 roll is used to decide how many enchantments will be applied to the weapon, with a chance for either 0, 1, 2, or 3 enchantments. Details of the Randomization: D20 Roll System: You roll a 20-sided die (using the function Utility.RandomInt(1, 20)), and based on the result of that roll, the number of enchantments to be applied is decided. You have divided the D20 roll into 4 groups: Group 1 (3 enchantments): If the roll is 8, the weapon gets 3 random enchantments. Group 2 (2 enchantments): If the roll is 2, 9, 14, the weapon gets 2 random enchantments. Group 3 (1 enchantment): If the roll is 1, 3, 4, 5, 6, 10, 11, 18, the weapon gets 1 random enchantment. Group 4 (no enchantment): If the roll is 7, 12, 13, 15, 16, 17, 19, 20, no enchantments are applied. Array of Enchantments: You have created an array of 11 base enchantments (such as Fire, Frost, Shock, Absorb Health, etc.) that the script will choose from. The script shuffles this array to randomize the selection of enchantments. Shuffling the Array: The script randomly rearranges the elements in the array so that the enchantments are not always in the same order. Applying Enchantments: Based on the result of the D20 roll, the script applies the appropriate number of enchantments from the shuffled array to the Blade of Chance. If 1 enchantment is to be applied, the first element of the shuffled array is used. If 2 enchantments are to be applied, the first two elements of the shuffled array are used, and so on. Desired Outcome: The weapon's enchantments will vary each time it is crafted, making each version of the Blade of Chance unique. Depending on the D20 roll: The player may get a powerful version of the blade with 3 enchantments. They might get a weaker version with only 1 or 2 enchantments. Or they might get an unenchanted version (if the roll lands in Group 4). This randomness aligns with the "chance" theme of the weapon, giving it a different power level and functionality each time it is acquired. Edited September 3 by Ninjaluxray7685 Link to comment Share on other sites More sharing options...
scorrp10 Posted September 3 Share Posted September 3 You are needlessly overcomplicating things. First, if you are doing a RandomInt(1.20), you are going to get a random number between 1 and 20. You gain absolutely nothing by making 8 your 'critical success' instead of 20. So making it instead: 1-8 - nothing; 9-16 - 1 enchantment, 17-19 - 2 enchantments, 20 - 3 enchantments, has no impact on outcome distribution, and is a whole lot easier to manage. Shuffling randomly an array of 11 items just to pick out at most 3? Why? Heck, almost half the time it don't even NEED to pick out anything, so why even shuffle? Just use RandomInt to determine the array index of each enchantment as you add it. Also, this whole concept as it is will not work. A weapon can have only one enchantment on it, but an enchantment can have multiple effects. So you will need to make an array of potential effects, determine how many effects the enchantment will have and what they will be, create arrays, populate them, and then call: Function CreateEnchantment(float maxCharge, MagicEffect[] effects, float[] magnitudes, int[] areas, int[] durations) There is no 'AddEnchantment' function. 1 Link to comment Share on other sites More sharing options...
Ninjaluxray7685 Posted September 3 Author Share Posted September 3 i didnt know that this makes more since now thank you im gonna get to work on that Link to comment Share on other sites More sharing options...
Ninjaluxray7685 Posted September 3 Author Share Posted September 3 so here is the new script but i keep running in to this issue (23,53): mismatched input 'enchCount' expecting INTEGER Spoiler Scriptname BladeOfChanceScript extends ObjectReference ; Properties FormList Property EnchList Auto Weapon Property BladeOfChance Auto Event OnItemCrafted(Form akBaseItem, ObjectReference akItem) if akBaseItem == BladeOfChance ; Determine the number of effects int effectCount = 0 int roll = Utility.RandomInt(1, 20) if roll == 20 effectCount = 3 elseif roll >= 17 effectCount = 2 elseif roll >= 9 effectCount = 1 endif ; Prepare a list of available enchantments EnchList.Revert() int enchCount = EnchList.GetSize() Enchantment[] enchantments = new Enchantment[enchCount] ; Populate enchantments array int index = 0 while index < enchCount Enchantment ench = EnchList.GetAt(index) as Enchantment if ench != None enchantments[index] = ench endif index += 1 endWhile ; Apply effects to the weapon Weapon weaponItem = akItem as Weapon if weaponItem != None ; Remove existing enchantments (not directly possible in Skyrim, so this is for illustrative purposes) ; Note: Skyrim does not provide direct methods to clear enchantments, so consider alternatives. ; Initialize enchantment details Enchantment selectedEnchantment = None MagicEffect[] effects = new MagicEffect[3] ; Placeholder for effects float[] magnitudes = new float[3] ; Placeholder for magnitudes int[] areas = new int[3] ; Placeholder for areas int[] durations = new int[3] ; Placeholder for durations ; Apply the selected number of effects int appliedCount = 0 while appliedCount < effectCount int enchantIndex = Utility.RandomInt(0, enchCount - 1) selectedEnchantment = enchantments[enchantIndex] if selectedEnchantment != None ; Add effect to arrays (assuming valid MagicEffect objects and values) ; This part is simplified. You need to define the actual effects, magnitudes, etc. effects[appliedCount] = selectedEnchantment.GetMagicEffect() ; Placeholder function magnitudes[appliedCount] = 10.0 ; Placeholder value areas[appliedCount] = 0 ; Placeholder value durations[appliedCount] = 0 ; Placeholder value appliedCount += 1 endif endwhile ; Create and apply the enchantment with multiple effects if appliedCount > 0 ; CreateEnchantment is not a real function. Placeholder for your method of applying the effects. ; weaponItem.CreateEnchantment(0.0, effects, magnitudes, areas, durations) ; Placeholder function endif endif endif EndEvent Link to comment Share on other sites More sharing options...
Recommended Posts