lasere200 Posted January 29, 2014 Share Posted January 29, 2014 Hello. I need some help with ref ownership. What I am trying to achieve is get my mod to steal loot from evil factions automatically when stealing is not enabled. What I know so far: ref owner can be a npc or a faction or noneI don't know if NPCs can own cells or only factions but it can also be set to nonewhen I getOwner or GetParentCellOwner if any of them are set to none I run into certain problems regardless of what OCell and ORef containt after setting them to the owners of the ref, I can look the values up in lists without issuesthis was my solution for factions as I don't know of any way to identify if a faction is evil since the only such function im aware of is GetISAlignment and IsActorEvil which only works on actors and to my knowledge factions are not actors so I tried using that for actors checking if they are actors firstthe thing is if either the owner or the cell owner is none when i try to work with that variable the script stopsI tried it a bunch of different ways, the script below is just the last attempt so any help to be able to actually get correct ORefEvil and OCellEvil variables would be appreciated. thanks if ALEnhGAmmoExplosives == 1 ;global variable that turns explosives looting on and off set WeaponRef to GetFirstRef 40 1 0 Label 40 if WeaponRef if Player.GetDistance WeaponRef < 200 && WeaponRef.GetDisabled == 0 set OCell to WeaponRef.GetParentCellOwner set ORef to WeaponRef.GetOwner set LIOCell to ListGetFormIndex ALEnhLEvilFactions OCell set LIORef to ListGetFormIndex ALEnhLEvilFactions ORef help if OCell != 0 help if OCell.IsActor == 1 help set OCellEvil to OCell.IsActorEvil help endif help endif help if ORef != 0 help if ORef.IsActor == 1 help set ORefEvil to ORef.IsActorEvil help endif help endif if (OCell == 0 && ORef == 0) || (OCell == Player && ORef == 0) || (OCell == PlayerFaction && ORef == 0) || ORef == Player || ORef == PlayerFaction || (ALEnhGModeSteal == 1 && Detected == 0) || LIOCell >= 0 || LIORef >= 0 || OCellEvil == 1 || ORefEvil == 1 if WeaponRef.IsInList ALEnhLWeaponsExplosivesThrown == 1 WeaponRef.Activate Player 1 elseif WeaponRef.IsInList ALEnhLWeaponsExplosivesPlaced == 1 WeaponRef.Activate Player 1 endif endif endif set WeaponRef to Pencil01 set WeaponRef to GetNextRef Goto 40 endif endif Link to comment Share on other sites More sharing options...
rickerhk Posted January 30, 2014 Share Posted January 30, 2014 You should check is ORef and OCell are non-null before performing any more functions on it. In fact this applies to any NVSE function - don't run them on null refs. Check them first.Erm - seem to have lost the tabs in the code :/ if ALEnhGAmmoExplosives == 1 ;global variable that turns explosives looting on and off set WeaponRef to GetFirstRef 40 1 0 Label 40 if WeaponRef if Player.GetDistance WeaponRef < 200 && WeaponRef.GetDisabled == 0 set OCell to WeaponRef.GetParentCellOwner set ORef to WeaponRef.GetOwner if OCell set LIOCell to ListGetFormIndex ALEnhLEvilFactions OCell else set LIOCell to 0 endif if ORef set LIORef to ListGetFormIndex ALEnhLEvilFactions ORef else set LIORef to 0 endif if OCell != 0 help if OCell.IsActor == 1 help set OCellEvil to OCell.IsActorEvil help endif help endif help if ORef != 0 help if ORef.IsActor == 1 help set ORefEvil to ORef.IsActorEvil help endif help endif if (OCell == 0 && ORef == 0) || (OCell == Player && ORef == 0) || (OCell == PlayerFaction && ORef == 0) || ORef == Player || ORef == PlayerFaction || (ALEnhGModeSteal == 1 && Detected == 0) || LIOCell >= 0 || LIORef >= 0 || OCellEvil == 1 || ORefEvil == 1 if WeaponRef.IsInList ALEnhLWeaponsExplosivesThrown == 1 WeaponRef.Activate Player 1 elseif WeaponRef.IsInList ALEnhLWeaponsExplosivesPlaced == 1 WeaponRef.Activate Player 1 endif endif endif endif set WeaponRef to Pencil01 set WeaponRef to GetNextRef Goto 40 endif endif Link to comment Share on other sites More sharing options...
lasere200 Posted January 30, 2014 Author Share Posted January 30, 2014 Thank you for your reply. So what I need help with are the lines that have help listed in front of them. But I took your suggestion and checked OCell and ORef for null values before doing anything with them. Please note that getting LIOCell and LIORef was working fine (note that the list index variables should be set to -1 since ListGetFormIndex can return 0 for the first item on the list). Somehow comparing any value ORef and OCell can have with anything in a list works fine regardless if any of the two variables are null, npc or faction. Then I used "MessageEx "%n - %n - %n - %n" OCell ORef OCellEvil ORefEvil" this debug message to identify what the problem is. What I found is that "if ORef" and "ifOcell" work fine in evaluating if it's null or not. What does not work is this: if ORef.IsActor == 1 when ORef is a faction. The script stops. Probably happens with OCell also if it's a faction. (It also stops on Oref.GetIsAlignment Evil and Oref.IsActorEvil if it's a faction but I guess that's normal.) In my opinion it shouldn't stop on IsActor because it's not an actor. It defeats the purpose. Any suggestions on how to fix it or work around it would be appreciated. I really don't want to use a list for evil NPCs. I mean factions I don't think it's that big of a deal because there aren't that many and there's no function for it. I tested it on Power Gang Camp West. There are 3 pieces of dynamite on a table and they have no cell ownerhip and PowderGangerFactionNV as the ref owner. if OCell set LIOCell to ListGetFormIndex ALEnhLEvilFactions OCell else set LIOCell to -1 endif if ORef set LIORef to ListGetFormIndex ALEnhLEvilFactions ORef else set LIORef to -1 endif if OCell if OCell.IsActor == 1 set OCellEvil to OCell.IsActorEvil endif endif if ORef if ORef.IsActor == 1 set ORefEvil to ORef.IsActorEvil endif endif Link to comment Share on other sites More sharing options...
jazzisparis Posted January 30, 2014 Share Posted January 30, 2014 You should check is ORef and OCell are non-null before performing any more functions on it. In fact this applies to any NVSE function - don't run them on null refs. Check them first.The GECK's built-in functions are stupid and seem to have no form of assertion - if called on an invalid input, will cause the script to break for the rest of the session (until the game is restarted). All NVSE function, however, handle invalid input just fine, and will return 0. IsActor expects a reference, and will fail if called on null or a base form (in this case, a faction). Try this script: if ALEnhGAmmoExplosives == 1 ;global variable that turns explosives looting on and off set WeaponRef to GetFirstRef 40 1 0 Label 40 if IsFormValid WeaponRef if Player.GetDistance WeaponRef < 200 && WeaponRef.GetDisabled == 0 set ORefEvil to 0 set OCellEvil to 0 set ORef to WeaponRef.GetOwner set OCell to WeaponRef.GetParentCellOwner if ORef if GetType ORef == 8 ; ORef is a faction. set ORefEvil to (ListGetFormIndex ALEnhLEvilFactions ORef >= 0) elseif ORef.IsActorEvil set ORefEvil to 1 endif elseif OCell if GetType OCell == 8 ; OCell is a faction. set OCellEvil to (ListGetFormIndex ALEnhLEvilFactions OCell >= 0) elseif OCell.IsActorEvil set OCellEvil to 1 endif endif if ((OCell == 0) && (ORef == 0)) || (ORef == Player) || (ORef == FactionPlayer) || (OCell == Player) || (OCell == FactionPlayer) || ((ALEnhGModeSteal == 1) && (Detected == 0)) || ORefEvil || OCellEvil if WeaponRef.IsInList ALEnhLWeaponsExplosivesThrown || WeaponRef.IsInList ALEnhLWeaponsExplosivesPlaced WeaponRef.Activate Player 1 endif endif endif set WeaponRef to Pencil01 set WeaponRef to GetNextRef Goto 40 endif endif Link to comment Share on other sites More sharing options...
lasere200 Posted January 30, 2014 Author Share Posted January 30, 2014 It works! When I saw that GetType I knew it would :) Thank you very much, I can finish my mod now. I am really impressed with your scripting. Just looking at it I learned a lot. I actually had some trouble with it's lenght but now I'll go over it again and I think I'll get it down to size easily. Thanks again. Link to comment Share on other sites More sharing options...
lasere200 Posted January 30, 2014 Author Share Posted January 30, 2014 One problem though - weapons dropped by dead NPCs list me as the RefOwner and the faction as the CellOwner (ncrf visitors center). Script locks up. I think I'll figure this out on my own but I thought it was interesting to note. Link to comment Share on other sites More sharing options...
jazzisparis Posted January 30, 2014 Share Posted January 30, 2014 One problem though - weapons dropped by dead NPCs list me as the RefOwner and the faction as the CellOwner (ncrf visitors center). Script locks up. I think I'll figure this out on my own but I thought it was interesting to note.Strange. That's good to know. Then just fix the conditions: if ORef && (ORef != Player) && (ORef != PlayerFaction) (...) elseif OCell && (OCell != Player) && (OCell != PlayerFaction) (...) endif Link to comment Share on other sites More sharing options...
lasere200 Posted January 30, 2014 Author Share Posted January 30, 2014 (edited) if ORef && (ORef != Player) && (ORef != PlayerFaction) MessageEx "%n - %n" OCell ORef if GetType ORef == 8 set ORefEvil to (ListGetFormIndex ALEnhLEvilFactions ORef >= 0) elseif ORef.IsActorEvil set ORefEvil to 1 endif elseif OCell && (OCell != Player) && (OCell != PlayerFaction) if GetType OCell == 8 set OCellEvil to (ListGetFormIndex ALEnhLEvilFactions OCell >= 0) elseif OCell.IsActorEvil set OCellEvil to 1 endif endif So I've got this Straight Razor on the floor and the my debug message says the ref belongs to me (Rooster Cogburn) and the cell belongs to NCRFPowderGangFaction. The thing is the message is displayed before the script locks up. This means that: if ORef && (ORef != Player) && (ORef != PlayerFaction) evaluates as true and I know for a fact that ORef is <Rooster Cogburn> I'm getting that feeling that it's happening because i've got a space in my char's name. What do you think? Edit: I changed my name using Shownamemenu and that's not it. Edited January 30, 2014 by lasere200 Link to comment Share on other sites More sharing options...
lasere200 Posted January 30, 2014 Author Share Posted January 30, 2014 (edited) if ORef == Player MessageEx "1 %n - %n" OCell ORef elseif OCell == Player MessageEx "2 %n - %n" OCell ORef elseif ORef && (ORef != Player) && (ORef != PlayerFaction) MessageEx "3 %n - %n" OCell ORef if GetType ORef == 8 set ORefEvil to (ListGetFormIndex ALEnhLEvilFactions ORef >= 0) elseif ORef.IsActorEvil set ORefEvil to 1 endif elseif OCell && (OCell != Player) && (OCell != PlayerFaction) if GetType OCell == 8 set OCellEvil to (ListGetFormIndex ALEnhLEvilFactions OCell >= 0) elseif OCell.IsActorEvil set OCellEvil to 1 endif endif I just don't understand it. I used this code and I get the 3rd message before the script locks up. Edit: Well I tried dropping the unique weapon Lucky in the visitors center in NCRF and it says that I'm the Ref Owner and the NCRFPowderGangerFaction is the cell owner just like the straight razor. But If I drop it outside (a cell with no owner) the ref owner is none and not me the player. So I guess depending on weather they drop in a owned or unowned cell (inside or outside) the Ref owner is different (either the player or NONE). The script does not lock up outside because everything evaluates correctly. So why wouldn't the RefOwner evaluate correctly inside? Edit 2: Tersspassing mechanics maybe? Edited January 30, 2014 by lasere200 Link to comment Share on other sites More sharing options...
luthienanarion Posted January 30, 2014 Share Posted January 30, 2014 Rooster CogburnThis made my morning. Link to comment Share on other sites More sharing options...
Recommended Posts