Jump to content

Disarm weapon script.


NameNotPresent

Recommended Posts

PlaceAtMe and Drop have exactly the same effect: both create a dynamic reference (a reference created on the fly, as opposed to a reference created in the CS).

 

Most dynamic references are removed when the cell is reset. kuertee Clean Up should take care of the ones that, for one reason or another, are not.

 

Persistent items are non-dynamic (created in the CS). Non-dynamic references (persistent or not), when dropped, do not create a new reference. They 'reuse' their existing reference, so, no bloating.

 

 

Re. the crash at the MoveTo:

 

In these lines:

temp.DropMe
;temp.MoveToMarker target

Temp refers to an inventory item (a temporary reference used exclusively within the loop). When you drop it, the reference becomes invalid.

MoveTo, on the other hand, needs as 'regular' reference. In this case, the dynamic reference created by Drop (which is not in the 'temp' var).

 

Instead of DropMe+MoveTo, you may use RemoveMeIR+PlaceAtMe, as lubronbrons suggests.

 

As Maskar says, both involve some risk of bloating, considering that there is no control over how many times the mod user will disarm an actor and whether or not they are using the Cleanup mod.

 

 

 

@lubronbrons - OBSE doc has a note saying not to use SetRefCount to modify the quantity of an inventory reference.

Edited by QQuix
Link to comment
Share on other sites

oah ! the God of code is here :D

 

well, Thank you QQuix for the correction. OK Done ! I've made a revision.

 

Let's just hope the op of this thread use the latest script which is more stable, but less realistic ...

since the item that gonna be removed in the ' target ' inventory is random..... not the current equipped object

Link to comment
Share on other sites

And, if I may ask a quick question, what will happen to unique items with a script and variables attached to it? For example if a sword keeps track of something, and gets removed upon disarming, and a new one is created, how would variables be affected? Or is it really an issue?

 

Have to ask not that QQuix is here. Thank you for the explanation again.

 

Edit: Ooops. Forget the edits. The question still stands.

Edited by Contrathetix
Link to comment
Share on other sites

hmmm..... first, I must state that I write that script without knowing where the op wants to apply it

can be in event handler (several variable must be set to Quest), or can be in GameMode, or can be in Object script, or can be in Magic script

I assume the code running in GameMode so the script is like that

 

@Contra

well ...

of course when it removed all the variables will be gone, so the next one added will have new fresh sets of variables

also keep in mind about Object script, thig thing can have several issue such as :

- never use string_var for Object script !! since it will bloat your savegame (my teacher Forli said this)

- if you have more than one item of the same kind that have Object script. Then the script will be running more than one too ... very ugly isn't it ?

so ... be careful when you implement some script. Or alternatively you can make sure every actor can only have one of that item

Link to comment
Share on other sites

Okay, will keep in mind. The script looks interesting, and helping others is great. I was just pointing out how it might be relevant to keep track of some object script variables, and how creating a new object could cause issues with that. Disarming seems tedious to implement in a way that accounts for everything.

 

Please, continue, and apologies for the disturbance. :thumbsup:

Link to comment
Share on other sites

well I am sorry this is off topic, but since Contra is here. I just want to encourage you about your companion mod

 

if that mod is matured, it will greatly help the current. All of companion mod is very limited, but yours is more than that :)

 

I am still wondering why your name change from Phillipetain to Contra anyway .... lol

 

yeah. for sure disarm weapon can cause issue afterwards.

 

no way, you're proud member of nexus. I've seen you like everywhere, you're modest aren't you :)

Link to comment
Share on other sites

Re. scripted items:

 

Dynamic items :

PlaceAtMe / Drop - a brand new script is created (empty vars) when the item is PlaceAtMe`d /Dropped.

Pick up - The script continues running and the variables are preserved when the item is picked up.

 

Non-Dynamic items (persistent or not) - script continues running and the variables are preserved when the item is picked up and/or dropped.

 

And, as lubronbrons already said, if RemoveItem/RemoveMe is used, the item, its script and variables are gone.

Link to comment
Share on other sites

This script is called by an OnHit event handler.

 

temp.DropMe
;temp.MoveToMarker target

 

I did not try those two lines at the same time. The DropMe line does nothing, while using the MoveToMarker line crashes the game.

 

Any chance of OBSE getting a disarm function?

Link to comment
Share on other sites

Hei, have you tried my code yet ? I think because it's in the previous page, you just missed it


I just wrote you a code in previous page in this thread, at least you can try that :) with help of QQuix the code is improved, Thx to him BUT


Nevertheless ! The previous code that I wrote is NOT working anyway LOL


Let's get this done :) here the new code, Tested, and working ;) enjoy~




======== this is Quest script
scn disarmWpnA
begin GameMode
if GetGameRestarted
RemoveEventHandler "OnHealthDamage" disarmWpnOnDmg
SetEventHandler "OnHealthDamage" disarmWpnOnDmg
endif
end


======== this is Event Handler
scn disarmWpnOnDmg
float dmg
ref atker

ref weapon

ref rf1
ref rf2
short sh1
float fl1
array_var ar1

begin Function {dmg atker}
if dmg >= 0
return
elseif GetAV Health < 1 ;this event only happen to the living, not for the dead
return
elseif atker.IsActor == 0 ;only works if there is valid actor as attacker
return

;NOTES --- Delete the ' ; ' if you want to enable the feature

;elseif GetFatiguePercentage > 0.25 ;fatigue requirement
; return

;elseif GetRandomPercent > 30 ;30% disarm chance
; return

;elseif atker.IsPowerAttacking == 0 ;make the disarm only happen when power attacking only
; return

endif

Let weapon := GetEquippedObject 16
if weapon
ForEach ar1 <- GetInvRefsForItem weapon
Let rf1 := *ar1
if rf1.IsEquipped
rf1.UnequipMe
Let rf2 := PlaceAtMe weapon 1 25 0
Let sh1 := GetPos z + 25
rf2.SetPos z sh1
Let fl1 := rf1.GetCurrentHealth
rf2.SetCurrentHealth fl1
Let fl1 := rf1.GetCurrentCharge
rf2.SetCurrentCharge fl1
Let sh1 := rf1.GetRefCount
rf2.SetRefCount sh1
break
endif
loop
RemoveItemNS weapon sh1
endif

end

Link to comment
Share on other sites

If the disarm script is being triggered by being hit, then how exactly is this going to be different from what's already in the game? You might be able to do this by (temporarily) changing a few game settings when being hit (using event handlers).

Link to comment
Share on other sites

  • Recently Browsing   0 members

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