Jump to content

Multiple plugins that edit the same script


Cyborgking

Recommended Posts

You can use this method for perks rather easily if you keep reference variables pointing to them.

 

 

scn ExampleScript

short modindex    ; Mod index for BuildRef

ref Perk1        ; Reference variables that act as handles to perks that you can't reference by EditorID.
ref Perk2
ref Perk3
ref Perk4
ref Perk5

short variable1    ; Some variables to do stuff with.
float variable2

begin gamemode

    if(getgamerestarted)                                ; You only need to build your references when the game is started.
        if(ismodloaded "PerkMod1.esm")
            set modindex to getmodindex "PerkMod1.esm"
            set Perk1 to buildref modindex 12345        ; FormID of a perk, converted to decimal.
            set Perk2 to buildref modindex 12346
        else
            set Perk1 to 0
            set Perk2 to 0
        endif
        if(ismodloaded "PerkMod2.esm")
            set modindex to getmodindex "PerkMod2.esm"
            set Perk3 to buildref modindex 21233
        else
            set Perk3 to 0
        endif
        if(ismodloaded "PerkMod3.esm")
            set modindex to getmodindex "PerkMod3.esm"
            set Perk4 to buildref modindex 34431
            set Perk5 to buildref modindex 34432
        else
            set Perk4 to 0
            set Perk5 to 0
        endif
    endif
    
    if(Perk1)                        ; Check if the perk has been retrieved from its mod before trying to call functions with it.
        if(player.hasperk Perk1)
            set variable1 to variable1 + 1
        elseif(Perk2)
            if(player.hasperk Perk2)
                set variable1 to variable1 + 2
            endif
        endif
    endif
    if(Perk3)
        if(player.hasperk Perk3)
            set variable1 to variable1 * 2
        endif
    endif
    if(Perk4)
        if(player.hasperk Perk4)
            set variable2 to variable2 * 1.1
        else
            set variable2 to variable2 * 0.8
        endif
    endif
    if(Perk5)
        if(player.hasperk Perk5)
            set variable2 to 3 - variable1
        endif
    endif
    
    player.setscale (variable1 / variable2)        ; Do something with these variables.
    
end ; gamemode
Link to comment
Share on other sites

EDIT: Ninja'd by Lutana. :)

 

That's a nice way for the ammo but I won't be able to do perks this way.

Why not? BuildRef also works with perks. In this case, instead of a form list, use a reference variable for each perk added by any optional mods. You already know which perks you are after, and by what mod they are added.

 

This is how it could work:

short	iIndex
ref	rDMHobbler
ref	rHHGrunt

begin GameMode

	if GetGameRestarted
		set iIndex to GetModIndex "DeadMoney.esm"
		if iIndex < 255
			set rDMHobbler to BuildRef iIndex 70761
		else
			set rDMHobbler to 0
		endif

		set iIndex to GetModIndex "HonestHearts.esm"
		if iIndex < 255
			set rHHGrunt to BuildRef iIndex 63095
		else
			set rHHGrunt to 0
		endif
	endif

	; (...)

	if rDMHobbler
		if player.HasPerk rDMHobbler
			set PerkBonus to PerkBonus * 1.2
		endif
	endif

	if rHHGrunt
		if player.HasPerk rHHGrunt
			if player.IsMoving
				set PerkBonus to PerkBonus * 0.8
    			else
				set PerkBonus to PerkBonus * 1.2
    			endif
		endif
	endif

end
Edited by jazzisparis
Link to comment
Share on other sites

Sorry, I must have overlooked a part of your post about the buildref function. This will work great, thanks a lot both of you. :smile:

 

I do have two questions:

-To get the form ID of perks that have been added by plugins, do I have to load the plugin alone with its master files to get the correct form ID?

-What is the use of:

if iIndex < 255

When the addon can't be found iIndex gets a value of above 255, I guess?

 

Thanks again.

Link to comment
Share on other sites

 

 

-To get the form ID of perks that have been added by plugins, do I have to load the plugin alone with its master files to get the correct form ID?

A Form ID of an object is composed of eight digits in base 16 (hexadecimal). The first two digits indicate the file's index in the load order and are non-persistent (subject to changes, depending on where the file is placed in the load order). The other 6 digits are the actual Form ID and are persistent.

Take the Grunt perk, for example: Load Honest Hearts in the GECK and find the Grunt perk. It's Form ID is XX00F677. You only need the 00F677, which equals 63095 in base 10.

 

 

 

When the addon can't be found iIndex gets a value of above 255, I guess?

Yep. If the mod was not loaded with the game, GetModIndex returns 255.

Link to comment
Share on other sites

 

When the addon can't be found iIndex gets a value of above 255, I guess?

Yep. If the mod was not loaded with the game, GetModIndex returns 255.

 

 

I did not know this. I wonder if it's really more efficient than calling IsModLoaded or if it's just faster to code...

 

Efficiency doesn't really matter on code that runs once, I suppose. Thanks for the tip.

Link to comment
Share on other sites

 

 

I did not know this. I wonder if it's really more efficient than calling IsModLoaded or if it's just faster to code...

 

Efficiency doesn't really matter on code that runs once, I suppose. Thanks for the tip.

 

Doesn't matter, really. Instead of calling both IsModLoaded and GetModIndex, I only call the later.

Link to comment
Share on other sites

  • 2 weeks later...

 

-To get the form ID of perks that have been added by plugins, do I have to load the plugin alone with its master files to get the correct form ID?

A Form ID of an object is composed of eight digits in base 16 (hexadecimal). The first two digits indicate the file's index in the load order and are non-persistent (subject to changes, depending on where the file is placed in the load order). The other 6 digits are the actual Form ID and are persistent.

Take the Grunt perk, for example: Load Honest Hearts in the GECK and find the Grunt perk. It's Form ID is XX00F677. You only need the 00F677, which equals 63095 in base 10.

 

 

 

When the addon can't be found iIndex gets a value of above 255, I guess?

Yep. If the mod was not loaded with the game, GetModIndex returns 255.

 

Thanks, it's clear now. :)

 

I tried this method for the gun runners arsenal DLC and it worked perfectly. Will probably release the first version in a week or two.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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