Jump to content

Wood cutting improvements


IsharaMeradin

Recommended Posts

I've done some looking and there is currently a mod out there that does indeed change the max # of pieces of firewood available to be gathered in one setting. That mod does not stop chopping even if the player becomes encumbered. I have an idea that would allow for non-stop chopping until the player is about to reach max carry weight.

 

I don't know anything about papryus scripting and frankly doesn't make that much sense to me. I can understand some things like specific entries but not how it flows.

 

If anyone who understands papryus is willing to help me to convert this default script so that it will examine the player's carry weight and determine at what point to stop the chopping prior to becoming over encumbered, it would be much appreciated. The first thing I'd do with the script is test it in game and the second thing I'd do is offer it to the existing wood chopping mod that is out there. Only then if that author didn't want to use it would I make it available as a resource/plugin.

 

The default script (in quote form so I can highlight the line that I believe needs to have the modified # ... in spoiler form to reduce in post length)

 

Scriptname ResourceFurnitureScript extends ObjectReference Conditional

{script for furniture which the player can use to get resources}

 

 

formlist Property requiredItemList Auto

{required for player to use - optional}

 

Message Property FailureMessage Auto

{Message to say why you can't use this without RequiredWeapon}

 

MiscObject Property Resource Auto

{what you get from using this furniture}

 

int Property ResourceCount = 1 Auto

{how many resources you get per use}

 

int property MaxResourcePerActivation = 6 auto

{How many times can this object be used before the player has to re-activate?}

 

int counter

; count up how many resources have been gathered on this go.

 

faction property CurrentFollowerFaction auto

{Used to handle player followers using the furniture object}

 

objectReference property NPCfollower auto hidden

{hidden property to track followers who used this}

 

Event OnLoad()

BlockActivation(true)

endEvent

 

Event OnUnload()

; safety measure

UnregisterForEvents(game.getplayer())

if NPCfollower

UnregisterForEvents(NPCfollower)

endif

endEvent

 

auto STATE normal

Event OnActivate(ObjectReference akActionRef)

gotoState("busy")

; debug.trace(self + "OnActivate")

if akActionRef == Game.GetPlayer() || (akActionRef as actor).isInFaction(CurrentFollowerFaction)

; debug.trace("akActionRef is either player or a follower")

if (akActionRef as actor) != game.getPlayer()

; debug.trace("It's a follower - store in NPCfollower property")

; if not the player, must be the follower

NPCfollower = akActionRef

endif

bool allowActivation = true

; check if player has required item

if requiredItemList

if akActionRef.GetItemCount(requiredItemList) == 0

if akActionRef == game.getPlayer()

; only require the axe item for the player

allowActivation = false

; debug.trace("allowActivation = "+allowActivation)

FailureMessage.Show()

endif

endif

endif

 

if allowActivation

RegisterForEvents(akActionRef)

; debug.trace(self + "player/follower activation START")

Activate(akActionRef, true)

; debug.trace(self + "player/follower activation END")

endif

else

; ;debug.trace(self + "non-follower NPC activation START")

; just activate it

Activate(akActionRef, true)

; ;debug.trace(self + "non-follower NPC activation END")

endif

gotoState("normal")

endEvent

endState

 

STATE busy

; do nothing

endState

 

Event OnAnimationEvent(ObjectReference akSource, string asEventName)

; debug.trace(self + ": animation event received=" + asEventName)

if asEventName == "AddToInventory"

akSource.AddItem(Resource, ResourceCount)

; increment counter by however many items we just received

; debug.trace("Pre-add counter = "+counter)

counter = (counter + resourceCount)

; debug.trace("Post-add counter = "+counter)

if counter >= MaxResourcePerActivation

; if we've bagged our limit, kick the player out. Reset timer for next activation

; debug.trace("Woodpile - player has gotten "+counter+" logs this go. Kicking out.")

counter = 0

(akSource as actor).PlayIdle(IdleWoodchopExit)

unregisterForEvents(akSource)

endif

elseif asEventName == "IdleFurnitureExit"

; debug.trace("Resource Object Unregistering: "+self)

; reset the counter if I exit manually

counter = 0

UnregisterForEvents(akSource)

endif

endEvent

 

bool isRegisteredForEvents = false

 

function RegisterForEvents(objectReference whoToRegister)

; centralize this

isRegisteredForEvents = true

RegisterForAnimationEvent(whoToRegister, "AddToInventory")

RegisterForAnimationEvent(whoToRegister, "SoundPlay . NPCHumanWoodChop")

RegisterForAnimationEvent(whoToRegister, "IdleFurnitureExit")

endFunction

 

function UnregisterForEvents(objectReference whoToUnregister)

; centralize this

 

; It is perfectly safe to unregister for events you never registered for, however

; this function is called as part of OnUnload, and if this object isn't persistent

; then it may be deleted by the time OnUnload runs, and these function calls will

; fail. Since RegisterForAnimationEvent persists us, we know it will be safe to

; call Unregister if we've previously Registered, even if called as a part of

; OnUnload

if isRegisteredForEvents

isRegisteredForEvents = false

UnRegisterForAnimationEvent(whoToUnregister, "AddToInventory")

UnRegisterForAnimationEvent(whoToUnregister, "IdleFurnitureExit")

endif

endFunction

 

Idle Property IdleWoodchopExit Auto

 

I would think that it needs a formula like:

(max carry weight - current weight) / weight of 1 resource = variable to be used

 

to be on the safe side whenever possible it should be rounded down. The purpose is to prevent going over the player's max carry weight and abusing the ability to chop wood non-stop.

 

Again any help would be appreciated. I'm willing to do the coding and testing, I just need help with implementing the formula into the script. In the meantime, I'll be looking thru CK to see if I can find the variables for the player's weight.

 

side thought: i suppose if the behavior is changed to stop the chopping at just before max carry weight, there would have to be something in place to define what happens when the player wants to chop wood while encumbered. Simplest might be a fail safe to the default method? Not sure...

 

******************************

looks like

player max carry weight = carryweight

player current inventory weight = inventoryweight

default firewood weight = 5.0000

 

so however the variable values are actually fetched would be followed by:

(carryweight - inventoryweight) / 5.0000 = firewoodtoget

IF firewoodtoget <= 0

THEN MaxResourcePerActivation = 6

ELSE MaxResourcePerActivation = firewoodtoget

 

******************************

I don't really know modern programming and it really is confusing, but I push on and read tutorials that don't make sense LOL

I'm guessing from what I've read and examples I've seen so far that I'm looking for something like this? but I've no clue if any of it is actually in proper syntax or what it means

 

int playersMaxCarryWeight = Game.GetPlayer().GetActorValue("carryweight") as int
int playersInventoryWeight = Game.GetPlayer().GetActorValue("inventoryweight") as int

int firewoodtoget = (playersMaxCarryWeight - playersInventoryWeight) / 5

if (firewoodtoget <= 0)
int property MaxResourcePerActivation = 6 auto
elseif int property MaxResourcePerActivation = firewoodtoget auto
endif

 

Can anyone shed further light on this?

Edited by IsharaMeradin
Link to comment
Share on other sites

New post because all my stumbling around in the dark paid off!!!! I just got something that compiled without error and when I tried it in game IT WORKED!!!!!

 

Now the way I understand this is that followers who chop wood will still chop at intervals of 6 pieces of wood. However the player will chop till just before they reach max carry weight.

 

here is the source code. I'll highlight the part I put in. If any papyrus gurus could take a look and see if there is any way to make it better, I'd appreciate it.

 

 

Scriptname ResourceFurnitureScript extends ObjectReference Conditional

{script for furniture which the player can use to get resources}

 

 

formlist Property requiredItemList Auto

{required for player to use - optional}

 

Message Property FailureMessage Auto

{Message to say why you can't use this without RequiredWeapon}

 

MiscObject Property Resource Auto

{what you get from using this furniture}

 

int Property ResourceCount = 1 Auto

{how many resources you get per use}

 

int property MaxResourcePerActivation = 6 auto

{How many times can this object be used before the player has to re-activate?}

 

int counter

; count up how many resources have been gathered on this go.

 

faction property CurrentFollowerFaction auto

{Used to handle player followers using the furniture object}

 

objectReference property NPCfollower auto hidden

{hidden property to track followers who used this}

 

Event OnLoad()

BlockActivation(true)

endEvent

 

Event OnUnload()

; safety measure

UnregisterForEvents(game.getplayer())

if NPCfollower

UnregisterForEvents(NPCfollower)

endif

endEvent

 

auto STATE normal

Event OnActivate(ObjectReference akActionRef)

gotoState("busy")

; debug.trace(self + "OnActivate")

if akActionRef == Game.GetPlayer() || (akActionRef as actor).isInFaction(CurrentFollowerFaction)

; debug.trace("akActionRef is either player or a follower")

if (akActionRef as actor) != game.getPlayer()

; debug.trace("It's a follower - store in NPCfollower property")

; if not the player, must be the follower

NPCfollower = akActionRef

endif

bool allowActivation = true

; check if player has required item

if requiredItemList

if akActionRef.GetItemCount(requiredItemList) == 0

if akActionRef == game.getPlayer()

; only require the axe item for the player

allowActivation = false

; debug.trace("allowActivation = "+allowActivation)

FailureMessage.Show()

endif

endif

endif

 

if allowActivation

;my added stuff hope it works

if akActionRef == Game.GetPlayer()

int playersMaxCarryWeight = Game.GetPlayer().GetActorValue("carryweight") as int

int playersInventoryWeight = Game.GetPlayer().GetActorValue("inventoryweight") as int

int firewoodtoget = (playersMaxCarryWeight - playersInventoryWeight) / 5

if (firewoodtoget <= 0)

MaxResourcePerActivation = 6

else

MaxResourcePerActivation = firewoodtoget

endif

endif

;end my added stuff

RegisterForEvents(akActionRef)

; debug.trace(self + "player/follower activation START")

Activate(akActionRef, true)

; debug.trace(self + "player/follower activation END")

endif

else

; ;debug.trace(self + "non-follower NPC activation START")

; just activate it

Activate(akActionRef, true)

; ;debug.trace(self + "non-follower NPC activation END")

endif

gotoState("normal")

endEvent

endState

 

STATE busy

; do nothing

endState

 

Event OnAnimationEvent(ObjectReference akSource, string asEventName)

; debug.trace(self + ": animation event received=" + asEventName)

if asEventName == "AddToInventory"

akSource.AddItem(Resource, ResourceCount)

; increment counter by however many items we just received

; debug.trace("Pre-add counter = "+counter)

counter = (counter + resourceCount)

; debug.trace("Post-add counter = "+counter)

if counter >= MaxResourcePerActivation

; if we've bagged our limit, kick the player out. Reset timer for next activation

; debug.trace("Woodpile - player has gotten "+counter+" logs this go. Kicking out.")

counter = 0

(akSource as actor).PlayIdle(IdleWoodchopExit)

unregisterForEvents(akSource)

endif

elseif asEventName == "IdleFurnitureExit"

; debug.trace("Resource Object Unregistering: "+self)

; reset the counter if I exit manually

counter = 0

UnregisterForEvents(akSource)

endif

endEvent

 

bool isRegisteredForEvents = false

 

function RegisterForEvents(objectReference whoToRegister)

; centralize this

isRegisteredForEvents = true

RegisterForAnimationEvent(whoToRegister, "AddToInventory")

RegisterForAnimationEvent(whoToRegister, "SoundPlay . NPCHumanWoodChop")

RegisterForAnimationEvent(whoToRegister, "IdleFurnitureExit")

endFunction

 

function UnregisterForEvents(objectReference whoToUnregister)

; centralize this

 

; It is perfectly safe to unregister for events you never registered for, however

; this function is called as part of OnUnload, and if this object isn't persistent

; then it may be deleted by the time OnUnload runs, and these function calls will

; fail. Since RegisterForAnimationEvent persists us, we know it will be safe to

; call Unregister if we've previously Registered, even if called as a part of

; OnUnload

if isRegisteredForEvents

isRegisteredForEvents = false

UnRegisterForAnimationEvent(whoToUnregister, "AddToInventory")

UnRegisterForAnimationEvent(whoToUnregister, "IdleFurnitureExit")

endif

endFunction

 

Idle Property IdleWoodchopExit Auto

 

Link to comment
Share on other sites

I think if you don't want do it yourself, woodcutting I mean, it would be much easier to create a merchant at the mill(s). Woodcutting is for the atmosphere, isn't it?

I do want to do it myself (there are mods that require firewood for crafting arrows & other stuff), but I'm tired of after every 6 pieces having to recenter the view so I can click on the chopping block. With the adjustment, I can chop wood till a logical stopping point rather than going on for a very long time as in the mod I had previously mentioned.

 

Maybe if I can learn how to make interface options (probably would require SKSE), then the player could be given options for customizing a specific wood chopping event or modifying the base default value for all chopping blocks. However, I'm happy with chopping till max carry weight.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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