Jump to content

Mod scripting help


Archanix29

Recommended Posts

Using RemoveAllItems is problematic, because it will remove unplayable items, and possibly quest ones, and is bad for compatability with other mods. I overcame this for Another Kick in the Head using a couple of UDFs, you can spork them if you want:

 

 

 

Needs an empty form list and container created.

 

 scn akhTransferItems

; * Transfers all items except quest/unplayable from one container to another

; * args
ref rActor
ref rTarget

; * local
ref rItem
int iCount
array_var entry
int iType

Begin Function { rActor, rTarget }

    if rTarget == None
        let rTarget := AKHBurnBoxREF
    endif
    DebugPrint "AKH: Start Transfer Items function (%n -> %n)" rActor, rTarget

    ListClear AKHSafeItemsFL
    let iCount := rActor.GetNumItems

    while (iCount -= 1) > 0
        let rItem := rActor.GetInventoryObject iCount
        if eval (IsFormValid rItem)
            if eval !(call akhIsLosable rItem)
                DebugPrint "AKH: TI - %n is quest or not playable. Skipping it." rItem
                ListAddForm AKHSafeItemsFL, rItem
            endif
        else
            DebugPrint "AKH: TI - grabbed an invalid form (%g) skipping it" iCount
        endif
    loop

    ; armor, (clothing), weapons, ammo, misc, alchemy, currency, mods, books, chips, cards
    foreach entry <- (Ar_List 24, 26, 40, 41, 31, 47, 116, 103, 25, 108, 115)
        let iType := entry["value"]
        rActor.RemoveAllTypedItems rTarget, 0, 0, iType, AKHSafeItemsFL
    loop

    if rTarget == AKHBurnBoxREF
        AKHBurnBoxREF.RemoveAllItems
    endif

    SetFunctionValue True
    DebugPrint "AKH: Completed Transfer Items function"

End 

and

 

 scn akhIsLosable

; Returns 0 if the specified item is a quest item
; Returns 0 if the specified weapon or armor is not playable
; Returns 0 if the specified item is Magic Companion Ammo
; Returns 0 is the specified item is in RobarNonLosableItemsFL
; Otherwise returns the type of the item

; * args
ref rItem

; * local
int iType
int bmWeapFlags
int bmPlayable

Begin Function { rItem }


    if eval !(IsFormValid rItem)
        Print "AKH: Error! IsLosable UDF passed invalid form"
        SetFunctionValue 0
        return
    endif

    let iType := GetType rItem

    ;Print "* Testing " + $rItem + " of type: " + $iType

    if eval (IsQuestItem rItem)
        SetFunctionValue 0
        ;Print "The item '" + $rItem + "' is quest"
        return
    endif

    if iType == 24 ; Armor
        if eval (IsPlayable rItem)
            SetFunctionValue iType
            ;Print "The armor '" + $rItem + "' is playable"
        else
            ;Print "The armor '" + $rItem + "' is not playable"
            SetFunctionValue 0
        endif
        return
    endif

    if iType == 40 ; Weapon
        let bmWeapFlags := GetWeaponFlags1 rItem
        let bmPlayable := ClearBit bmWeapFlags, 7 ; * 7 (128) is not playable flag
        ;Print "bmWeapFlags == " + $bmWeapFlags + " bmNotPlayable == " + $bmPlayable
        if bmWeapFlags == bmPlayable
            ;Print "The weapon '" + $rItem + "' is playable"
            SetFunctionValue iType
        else
            ;Print "The weapon '" + $rItem + "' is not playable"
            SetFunctionValue 0
        endif
        return
    endif

    if rItem == AmmoCompanion
        SetFunctionValue 0
        ;Print $rItem + " is magic companion ammo"
        return
    endif

    if eval (ListGetFormIndex RobarNonLosableItemsFL, rItem) > NotFound
        SetFunctionValue 0
        ;Print $rItem + " is in nonlosable FL"
        return
    endif

    SetFunctionValue iType
    ;Print "The item '" + $rItem + "' is safe to lose"

End

 

 

 

and you can launch the player into the air with something like: PlayerREF.PushActorAway PlayerREF, 9999

Link to comment
Share on other sites

  • Recently Browsing   0 members

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