Jump to content

Wierd scripting issue.


HakunoWolf

Recommended Posts

So, I eventually got one issue fixed and learned some basics things of scripting(Thanks to everyone who helped) but now I need some more help, I actually re-adjusted the script multiple times, and I decided I wanted it to be one script for multiple things instead of multiples of the same script, here's the script that works

ScriptName NCRNWGunsEffect

begin OnEquip player ; Begins the script when the weapon is equipped

	if player.GetEquipped WeapNVNCRNWMCarbine == 1 ; Asks if whether or not the M. Carbine is equipped
		player.AddPerk NightWolfGuns ; Gives the player the M. Carbine if they have it equipped
	elseif player.GetEquipped WeapNVNCRNW44Revolver == 1
		player.AddPerk NightWolfGuns
	elseif player.GetEquipped WeapNVNCRNWAMR == 1
		player.AddPerk NightWolfGuns
	endif

End

begin OnUnequip player ; Begins the script when the weapon is unequipped

	if player.GetEquipped WeapNVNCRNWMCarbine == 1 ; Asks if whether or not the M. Carbine is equipped
		
	elseif player.GetEquipped WeapNVNCRNW44Revolver == 1
		
	elseif player.GetEquipped WeapNVNCRNWAMR == 1
		
	else player.HasPerk NightWolfGuns
		player.RemovePerk NightWolfGuns
		
	endif

End

And then I added in some more weapons, note, this worked fine and I can explain why I did certain things if that would help

 

But here's the script that doesn't work.

ScriptName NCRNWGunsEffect

begin OnEquip player ; Begins the script when the weapon is equipped

	if player.GetEquipped WeapNVNCRNWMCarbine == 1 ; Asks if whether or not the M. Carbine is equipped
		player.AddPerk NightWolfGuns ; Gives the player the M. Carbine if they have it equipped
	elseif player.GetEquipped WeapNVNCRNW44Revolver == 1
		player.AddPerk NightWolfGuns
	elseif player.GetEquipped WeapNVNCRNWAMR == 1
		player.AddPerk NightWolfGuns
	elseif player.GetEquipped WeapNVNCRNWRangerSequoia == 1
		player.AddPerk NightWolfGuns
	elseif player.GetEquipped WeapNVNCRNW10mmSubmachineGun == 1
		player.AddPerk NightWolfGuns
	elseif player.GetEquipped WeapNVNCRNW9mmPistol == 1
		player.AddPerk NightWolfGuns
	elseif player.GetEquipped WeapNVNCRNWAssaultCarbine == 1
		player.AddPerk NightWolfGuns
	elseif player.GetEquipped WeapNVNCRNWServiceRifle == 1
		player.AddPerk NightWolfGuns
	elseif player.GetEquipped WeapNVNCRNWSilenced22SMG == 1
		player.AddPerk NightWolfGuns
	elseif player.GetEquipped WeapNVNCRNWRiotShotgun == 1
		player.AddPerk NightWolfGuns
	elseif player.GetEquipped WeapNVNCRNWSniperRifle == 1
		player.AddPerk NightWolfGuns

	endif

End

begin OnUnequip player ; Begins the script when the weapon is unequipped

	if player.GetEquipped WeapNVNCRNWMCarbine == 1 ; Asks if whether or not the M. Carbine is equipped
		
	elseif player.GetEquipped WeapNVNCRNW44Revolver == 1
		
	elseif player.GetEquipped WeapNVNCRNWAMR == 1

	elseif player.GetEquipped WeapNVNCRNWRangerSequoia == 1
		
	elseif player.GetEquipped WeapNVNCRNW10mmSubmachineGun == 1

	elseif player.GetEquipped WeapNVNCRNW9mmPistol == 1
	
	elseif player.GetEquipped WeapNVNCRNWAssaultCarbine == 1
		
	elseif player.GetEquipped WeapNVNCRNWServiceRifle == 1
	
	elseif player.GetEquipped WeapNVNCRNWSilenced22SMG == 1
	
	elseif player.GetEquipped WeapNVNCRNWRiotShotgun == 1
		
	elseif player.GetEquipped WeapNVNCRNWSniperRifle == 1
		
	elseif player.HasPerk NightWolfGuns
		player.RemovePerk NightWolfGuns
		
	endif

End

As you can see, there aren't really any differences a side from the number of the times it's doing elseif.

So could that be it? I just have to large a number and need to fix it somehow?

Did I hit a character limit or something?

 

Note: the last elseif for the function that asks on whether or not the player has the perk was originally an else, I tried it both ways, neither worked.

Edited by HakunoWolf
Link to comment
Share on other sites

Hmm, I don't see why the second one shouldn't compile unless one of the weapons has a typo.

However, you could prevent it being because of a bunch of empty IF-blocks very easily by combining them all into a single check:

    if player.GetEquipped WeapNVNCRNWMCarbine == 0 ; Asks if whether or not the M. Carbine is equipped
        
    && player.GetEquipped WeapNVNCRNW44Revolver == 0
        
    && player.GetEquipped WeapNVNCRNWAMR == 0

    && player.GetEquipped WeapNVNCRNWRangerSequoia == 0
        
    && player.GetEquipped WeapNVNCRNW10mmSubmachineGun == 0

    && player.GetEquipped WeapNVNCRNW9mmPistol == 0
    
    && player.GetEquipped WeapNVNCRNWAssaultCarbine == 0
        
    && player.GetEquipped WeapNVNCRNWServiceRifle == 0
    
    && player.GetEquipped WeapNVNCRNWSilenced22SMG == 0
    
    && player.GetEquipped WeapNVNCRNWRiotShotgun == 0
        
    && player.GetEquipped WeapNVNCRNWSniperRifle == 0
        
    && player.HasPerk NightWolfGuns
        player.RemovePerk NightWolfGuns
        
    endif

You may have to remove the line breaks so it's all in a single line, and maybe introduce brackets around it and/or each individual condition as well, but this again depends on the scripting syntax of a game I'm unfamiliar with.

I'm not quite a friend of those 'empty' result blocks. Not sure the complex if structure will work that way.

 

On a different but related note though, what is the exact error it's giving you on compile anyways?

 

edit: Oh, and this construct in your first example isn't really doing what it should do but still working regardless.

The "else" won't take a condition. Now you have a line "player.HasPerk NightWolfGuns" as the first call inside its result block, which may return a value but will be ignored anyways, as it's not inside a condition, and the line "player.RemovePerk NightWolfGuns" gets called every time you unequip the item and don't have any of the three weapons equipped, regardless of whether you have the perk or not. Luckily removing a perk you don't even have doesn't have any negative effect on the game.

Edited by DrakeTheDragon
Link to comment
Share on other sites

In both scripts a number of elseifs seem redundant, and could be what's breaking your script.

 

In the OnUnequip block, only your last elseif actually does anything. If you're adding the perk each time you equip one of those weapons, you don't need to then check that weapon is equipped, since if they have the perk you know that it is indeed equipped (You know when they unequip, because that's when the OnUnequip block runs). However, if the player has one of those weapons equipped and then you run through the OnUnequip block, one of your elseifs will be true, so it'll skip over your last elseif and thus not remove the perk.

 

Try this instead:

 

 

 

ScriptName NCRNWGunsEffect

begin OnEquip player

	if player.GetEquipped WeapNVNCRNWMCarbine
		player.AddPerk NightWolfGuns
	elseif player.GetEquipped WeapNVNCRNW44Revolver
		player.AddPerk NightWolfGuns
	elseif player.GetEquipped WeapNVNCRNWAMR
		player.AddPerk NightWolfGuns
	elseif player.GetEquipped WeapNVNCRNWRangerSequoia
		player.AddPerk NightWolfGuns
	elseif player.GetEquipped WeapNVNCRNW10mmSubmachineGun
		player.AddPerk NightWolfGuns
	elseif player.GetEquipped WeapNVNCRNW9mmPistol
		player.AddPerk NightWolfGuns
	elseif player.GetEquipped WeapNVNCRNWAssaultCarbine
		player.AddPerk NightWolfGuns
	elseif player.GetEquipped WeapNVNCRNWServiceRifle
		player.AddPerk NightWolfGuns
	elseif player.GetEquipped WeapNVNCRNWSilenced22SMG
		player.AddPerk NightWolfGuns
	elseif player.GetEquipped WeapNVNCRNWRiotShotgun
		player.AddPerk NightWolfGuns
	elseif player.GetEquipped WeapNVNCRNWSniperRifle
		player.AddPerk NightWolfGuns

	endif
end

begin OnUnequip player

	if player.HasPerk NightWolfGuns
		player.RemovePerk NightWolfGuns
	endif
end

 

 

Edited by Jojash
Link to comment
Share on other sites

It's better to use single conditions and ElseIfs than to use the && or II operators because the compiler does not optimize conditions. If you have a condition that returns false, it will still check all of the other conditions in the If statement before deciding upon a false result and skipping to the EndIf.

 

More information here: Script Optimization.

 

In order to simplify the script and make the list of affected guns easily modifiable, I would create a form list with all of the guns in it and pass the form list to GetEquipped. It will return true if any of the items in the list are equipped.

 

Also, OnUnequip is so unreliable that Obsidian patched its use out of the Rebreather script. Examine that script for an example of how to reliably emulate it.

Link to comment
Share on other sites

Hmm, I don't see why the second one shouldn't compile unless one of the weapons has a typo.

However, you could prevent it being because of a bunch of empty IF-blocks very easily by combining them all into a single check:

    if player.GetEquipped WeapNVNCRNWMCarbine == 0 ; Asks if whether or not the M. Carbine is equipped
        
    && player.GetEquipped WeapNVNCRNW44Revolver == 0
        
    && player.GetEquipped WeapNVNCRNWAMR == 0

    && player.GetEquipped WeapNVNCRNWRangerSequoia == 0
        
    && player.GetEquipped WeapNVNCRNW10mmSubmachineGun == 0

    && player.GetEquipped WeapNVNCRNW9mmPistol == 0
    
    && player.GetEquipped WeapNVNCRNWAssaultCarbine == 0
        
    && player.GetEquipped WeapNVNCRNWServiceRifle == 0
    
    && player.GetEquipped WeapNVNCRNWSilenced22SMG == 0
    
    && player.GetEquipped WeapNVNCRNWRiotShotgun == 0
        
    && player.GetEquipped WeapNVNCRNWSniperRifle == 0
        
    && player.HasPerk NightWolfGuns
        player.RemovePerk NightWolfGuns
        
    endif

You may have to remove the line breaks so it's all in a single line, and maybe introduce brackets around it and/or each individual condition as well, but this again depends on the scripting syntax of a game I'm unfamiliar with.

I'm not quite a friend of those 'empty' result blocks. Not sure the complex if structure will work that way.

 

On a different but related note though, what is the exact error it's giving you on compile anyways?

 

edit: Oh, and this construct in your first example isn't really doing what it should do but still working regardless.

The "else" won't take a condition. Now you have a line "player.HasPerk NightWolfGuns" as the first call inside its result block, which may return a value but will be ignored anyways, as it's not inside a condition, and the line "player.RemovePerk NightWolfGuns" gets called every time you unequip the item and don't have any of the three weapons equipped, regardless of whether you have the perk or not. Luckily removing a perk you don't even have doesn't have any negative effect on the game.

 

I actually did a retest where I saved it after every line of the script, It doesn't save as soon as it hits the 5th elseif, so apparently there's a limit to how many elseifs you can have in the script

I also just tried your variation and put it all in one line, didn't work, so I'm guessing there's a limit on how much you can put in one block of a script

 

 

In both scripts a number of elseifs seem redundant, and could be what's breaking your script.

 

In the OnUnequip block, only your last elseif actually does anything. If you're adding the perk each time you equip one of those weapons, you don't need to then check that weapon is equipped, since if they have the perk you know that it is indeed equipped (You know when they unequip, because that's when the OnUnequip block runs). However, if the player has one of those weapons equipped and then you run through the OnUnequip block, one of your elseifs will be true, so it'll skip over your last elseif and thus not remove the perk.

 

Try this instead:

 

 

 

ScriptName NCRNWGunsEffect

begin OnEquip player

	if player.GetEquipped WeapNVNCRNWMCarbine
		player.AddPerk NightWolfGuns
	elseif player.GetEquipped WeapNVNCRNW44Revolver
		player.AddPerk NightWolfGuns
	elseif player.GetEquipped WeapNVNCRNWAMR
		player.AddPerk NightWolfGuns
	elseif player.GetEquipped WeapNVNCRNWRangerSequoia
		player.AddPerk NightWolfGuns
	elseif player.GetEquipped WeapNVNCRNW10mmSubmachineGun
		player.AddPerk NightWolfGuns
	elseif player.GetEquipped WeapNVNCRNW9mmPistol
		player.AddPerk NightWolfGuns
	elseif player.GetEquipped WeapNVNCRNWAssaultCarbine
		player.AddPerk NightWolfGuns
	elseif player.GetEquipped WeapNVNCRNWServiceRifle
		player.AddPerk NightWolfGuns
	elseif player.GetEquipped WeapNVNCRNWSilenced22SMG
		player.AddPerk NightWolfGuns
	elseif player.GetEquipped WeapNVNCRNWRiotShotgun
		player.AddPerk NightWolfGuns
	elseif player.GetEquipped WeapNVNCRNWSniperRifle
		player.AddPerk NightWolfGuns

	endif
end

begin OnUnequip player

	if player.HasPerk NightWolfGuns
		player.RemovePerk NightWolfGuns
	endif
end

 

 

 

I tried it, it broke the script as well, apparently there number of elseifs that will cause the script to break(Sounds a bit wierd IMO but explains it)

 

 

It's better to use single conditions and ElseIfs than to use the && or II operators because the compiler does not optimize conditions. If you have a condition that returns false, it will still check all of the other conditions in the If statement before deciding upon a false result and skipping to the EndIf.

 

More information here: Script Optimization.

 

In order to simplify the script and make the list of affected guns easily modifiable, I would create a form list with all of the guns in it and pass the form list to GetEquipped. It will return true if any of the items in the list are equipped.

 

Also, OnUnequip is so unreliable that Obsidian patched its use out of the Rebreather script. Examine that script for an example of how to reliably emulate it.

 

The OnUnequip seems to work how I need it to, so I wouldn't call it unreliable as due to the fact It's working fine a side from the fact effects don't take effect until you lower the pipboy, which isn't the OnUnequip, it's more the gametime or something like that.

 

I will try and put it into a formlist, that sounds like it'll work as the issue wasn't the script itself, it was the fact there were too many elseifs.

Link to comment
Share on other sites

What if you skip the 5th 'elseif' and add in the others? Only 5 elseif allowed sounds about as wrong as can be. I'm very hesitant to believe this is true. I'd rather check for an error in the 5th condition, like referencing a weapon which doesn't exist in this plugin.

 

I know there are hardcoded limitations control structures in scripts have to abide by, but they're for complex things like nesting depths rather, not for number of elseif lines allowed.

Link to comment
Share on other sites

I tried it, it broke the script as well, apparently there number of elseifs that will cause the script to break(Sounds a bit wierd IMO but explains it)

 

 

There is a limitation with elseifs, but if I remember correctly I believe it's actually to do with nested elseifs, which you're not using. I'm pretty sure you just have a syntax error (mistyping, or misspelling something) somewhere (presumably with the fifth elseif), Making a form-list is a good idea though, especially since that eliminates the chances of making a syntax error, so long as you get the list name right the first time, and you can easily add or remove weapons from it. :)

 

Also, might I ask, which object are you putting this script on?

Link to comment
Share on other sites

 

I tried it, it broke the script as well, apparently there number of elseifs that will cause the script to break(Sounds a bit wierd IMO but explains it)

 

 

There is a limitation with elseifs, but if I remember correctly I believe it's actually to do with nested elseifs, which you're not using. I'm pretty sure you just have a syntax error (mistyping, or misspelling something) somewhere (presumably with the fifth elseif), Making a form-list is a good idea though, especially since that eliminates the chances of making a syntax error, so long as you get the list name right the first time, and you can easily add or remove weapons from it. :smile:

 

Also, might I ask, which object are you putting this script on?

 

 

I'm putting it on a weapon, I'm about to try

Scriptname NCRNWGunsEffect

begin OnEquip Player
	if player.GetEquipped PerkNightWolfGunsList == 1
		player.Addperk NightWolfGuns
	endif
End

Begin OnUnequip player
	if player.GetEquipped PerkNightWolfGunsList == 0 && player.HasPerk NightWolfGuns
		player.RemovePerk NightWolfGuns
        endif
 End

With PerkNightWolfGunsList being the formlist ID of course.

 

Edit: I all most forgot the last endif and End, lol

Edited by HakunoWolf
Link to comment
Share on other sites

Well, if the weapon in question is the one that's meant to add the perk when it's equipped and remove it when it's unequipped most of your script is redundant.

 

Here:

if player.GetEquippedPerNightWolfGunsList == 1

You wouldn't need this, since you know that it's true already.

 

And here:

if player.GetEquipped PerkNightWolfGunsList == 0 && player.HasPerk NightWolfGuns

Again, you already know both of these conditions are true, since you equipped the weapon to get the perk in the first place!

 

If you're adding this effect to each weapon that would give the perk you don't need any of those conditions, since OnEquip and OnUnequip only run once.

 

If you use something like:

begin OnEquip player
    player.AddPerk NightWolfGuns
end
 
begin OnUnequip player
    player.RemovePerk NightWolfGuns
end

You should get the desired result. The only reason to do it the way you're doing it now would be if you incorporated it into a Quest script, but I don't think that'd really make much sense.

 

If it's not the weapon that should add the perk, then none of the conditions will return true and your script will do nothing anyway. Unless you've found a crazy way to do dual-wielding weapons, in which case, I salute you. :smile: Good luck either way!

Edited by Jojash
Link to comment
Share on other sites

Well, if the weapon in question is the one that's meant to add the perk when it's equipped and remove it when it's unequipped most of your script is redundant.

 

Here:

if player.GetEquippedPerNightWolfGunsList == 1

You wouldn't need this, since you know that it's true already.

 

And here:

if player.GetEquipped PerkNightWolfGunsList == 0 && player.HasPerk NightWolfGuns

Again, you already know both of these conditions are true, since you equipped the weapon to get the perk in the first place!

 

If you're adding this effect to each weapon that would give the perk you don't need any of those conditions, since OnEquip and OnUnequip only run once.

 

If you use something like:

begin OnEquip player
    player.AddPerk NightWolfGuns
end
 
begin OnUnequip player
    player.RemovePerk NightWolfGuns
end

You should get the desired result. The only reason to do it the way you're doing it now would be if you incorporated it into a Quest script, but I don't think that'd really make much sense.

 

If it's not the weapon that should add the perk, then none of the conditions will return true and your script will do nothing anyway. Unless you've found a crazy way to do dual-wielding weapons, in which case, I salute you. :smile: Good luck either way!

Actually, I do need them, there is a bug with the OnEquip block that will start the script if you try to equip the broken weapon, meaning you could get the perk without actually equipping the gun, the OnUnequip also was giving me issues as if I would go from one weapon that gives me this perk to another that does as well, it would take away the perk and not give it, so I had to do both of those...But as for the Dual-Wielding

Nope, I got no ideas on how to do the dual-wielding, except maybe having some type of script where you pull out two guns or something, Idk, lol

Link to comment
Share on other sites

  • Recently Browsing   0 members

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