luvadea Posted May 1, 2020 Share Posted May 1, 2020 Hi there, I'm working on a mod that will feature a ship battles (pirates and such)My idea was to introduce a ship damage after each battle and I set it up like this (in my imagination):Created 3 global variables like Hull, Sail, and Rigging and set them to 100 initially.After each battle a script will subtract random amounts of each variable - making the ship damaged.Three items like Wood, Sailcloth and Rope (another global variables?) will be available to player to fix the corresponding damage.The final step is when players click on option to REPAIR SHIP - then this happens:1.HULL DAMAGE is at 80 (out of 100)2. Script will see the missing 20 and Substract 20 wood out of player supplies to make it 100Then ropes and sail etc.,What function can do that and is this possible at all?Or is there an easier way??I wouldn't dare to ask for a script sample but if you have an idea how to simulate that please help me. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted May 1, 2020 Share Posted May 1, 2020 Int RanDamage = RandomInt(10,30) ;selects between and including 10 & 30 Hull.ModValue(-RanDamage) ;subtracts the damage from the current value of the global variable Repeat that for each thing you want damaged and repeat again after each time you want it damaged. You may wish to include visible damaged portions to enable / disable as the ship progresses through its states of damage / repair. As far as repairing, put an activator or trigger volume box set as an activator at the area you want repaired. The use the OnActivate event to look at the player's inventory and take what is needed if there is enough. You may want to take a look at the atronach forge in the college of winterhold. Unlike other "workstations" that one is completely scripted and would be a good example on how to set this type of thing up. Link to comment Share on other sites More sharing options...
luvadea Posted May 1, 2020 Author Share Posted May 1, 2020 Aaand you just made yourself a troublesome friend.Thank you.But I don't quite understand how OnActivate part will know how much to subtract from player?Also is it possible to use another GlobalV instead of player inventory? (i.e stockroom of repair materials)? Link to comment Share on other sites More sharing options...
IsharaMeradin Posted May 1, 2020 Share Posted May 1, 2020 You have to do the scripting in the OnActivate event. The event is your hook into the game. From there, you have to check player inventory, container or whatever for the necessary items. If you take a page from the atronach forge, you can have a container that the player puts components within. The container can even be scripted to send back anything that does not belong to the repair system. Then when the player activates the activator, it will check the contents of the container against pre-determined combinations of materials and remove this first matching set and repair that. Alternatively, you can use the message box menu system to let the player select what to repair, then check the container or their inventory for the correct parts. If you felt really saucy, you could create a workbench complete with recipes that require certain materials and the global variable value to be at or below a certain amount. Then the player can craft an item that when added to their inventory causes a portion of the ship to be repaired and that item gets silently removed. This method is more like the Hearthfires homes. One possible method - not tested for compilation or function: Scriptname SomeActivator Extends ObjectReference ObjectReference Property myContainer Auto {storage container for repair materials} GlobalVariable Property HullGV Auto GlobalVariable Property SailGV Auto GlobalVariable Property RiggingGV Auto MiscObject Property SawnLogs Auto MiscObject Property Canvas Auto MiscObject Property Rope Auto ObjectReference Property HullFullHealthMarker Auto {xmarker that enables fully repaired hull pieces and disables the broken pieces} ObjectReference Property SailFullHealthMarker Auto {xmarker that enables fully repaired sail pieces and disables the broken pieces} ObjectReference Property RiggingFullHealthMarker Auto {xmarker that enables fully repaired Rigging pieces and disables the broken pieces} Event OnActivate(ObjectReference akActivator) If akActivator == Game.GetPlayer() RepairShipPart(myContainer,HullGV,SawnLogs,100) EnableIfPossible(HullGV, 100, HullFullHealthMarker, SawnLogs) RepairShipPart(myContainer,SailGV,Canvas,100) EnableIfPossible(SailGV, 100, SailFullHealthMarker, Canvas) RepairShipPart(myContainer,RiggingGV,Rope,100) EnableIfPossible(RiggingGV, 100, RiggingFullHealthMarker, Rope) EndIf EndEvent Function RepairShipPart(ObjectReference myPartSource, GlobalVariable myGV, MiscObject myPart, Int myRepairLevel) While myPartSource.GetItemCount(myPart) > 0 myPartSource.RemoveItem(myPart,1) ; send it to the ether myGV.ModValue(1) index += 1 EndWhile EndFunction Function EnableIfPossible(GlobalVariable myGV, Int myRepairLevel, ObjectReference myEnableMarker, MiscObject myPart) If myGV.GetValue() == myRepairLevel myEnableMarker.Enable() Else If SKSE.GetVersion() > 0 Debug.MessageBox("More "+myPart.GetName()+" are needed.") Else Debug.MessageBox("More parts are needed.") EndIf EndIf EndFunction And add a dialog option to purchase sawn logs from the sawmills to be sent directly to the ship to be repaired. Alternatively, see if you can utilize the same container as the hearthfires homes for the sawn logs. Cause the logs you purchase for them are shared across all three homes. Being able to work from that stock would probably be handy. If you separate this idea out into where one script handles just one set, then you can use generic property variables and re-use the script on a different activator for each type. Thus a smaller script, less to process at one time and possibly a faster response time. Link to comment Share on other sites More sharing options...
luvadea Posted May 2, 2020 Author Share Posted May 2, 2020 Thank you for this. :laugh:myGV.ModValue(1) did not workmyGV.Mod(1) did Also I do not understand the index += 1 So far, I managed to implement the damage done part, hull values are being modified each time for random values.But when I try the repair function it takes whatever amount of wood that is in the container and puts it into HULL.GV instead of topping it up only to a 100. (i.e. my HULL value after repair is 250 because I had 200 logs in the box)I think there comes:Int myRepairLevel 100 but how do I set a limit to it that will stop taking more wood than needed? Link to comment Share on other sites More sharing options...
IsharaMeradin Posted May 2, 2020 Share Posted May 2, 2020 I had a different while loop and changed it up and forgot to correct everything... the index += 1 was a left over.Change the one custom function to the following. Function RepairShipPart(ObjectReference myPartSource, GlobalVariable myGV, MiscObject myPart, Int myRepairLevel) While (myGV.GetValueInt() < myRepairLevel) && (myPartSource.GetItemCount(myPart) > 0) myPartSource.RemoveItem(myPart,1) ; send it to the ether myGV.Mod(1) EndWhile EndFunction This will stop it when you either reach the desired value on the global OR when parts run out. Link to comment Share on other sites More sharing options...
luvadea Posted May 2, 2020 Author Share Posted May 2, 2020 That worked and you're a Star :laugh:Thank you. Link to comment Share on other sites More sharing options...
Recommended Posts