Jump to content

Weapon-switching script keeps crashing


Zephyr102

Recommended Posts

I'm trying to make a rifle with a 'usable' bayonet. I've so far gotten both weapons working in-game, but when I try to use the following script to switch between 'em, FO3 drops to desktop like a rocket-propelled brick:

 

scn M1AFOSEScript

;renamed variables to match the mod
Short Setup
Short m1akey
Short m1atoggle
Float m1ahealth

BEGIN Gamemode


                                                                                                                		;  Initialization
IF Setup == 0
   	IF m1ahealth == 0
           	Set m1ahealth to 95
   	EndIF
   	Set m1akey to 46 ; 
   	Set Setup to 1
EndIF

con_SetINISetting "fScopeScissorAmount:Display" 0.000

IF Player.GetItemCount M1Aspecial > 0 && player.GetItemCount M1AspecialM > 0  ; needs to be outside the setup loop
   	IF Player.GetItemCount M1Aspecial == 0
           	IF m1ahealth > 0
                   	Player.AddItemHealthPercent M1Aspecial 1 m1ahealth 1
           	ELSE
                   	Player.AddItem M1Aspecial 1 
           	EndIF
EndIF
   	Player.removeitem M1AspecialM 1 1   	
EndIF                                                                                                                                            	;  Bayonet Toggle
IF m1atoggle != IsKeyPressed m1akey
   	Set m1atoggle to m1atoggle == 0
   	IF m1atoggle 
           	IF Player.getEquipped M1Aspecial == 1
                   	Set m1ahealth to (Player.GetWeaponHealthPerc / 100)
                   	player.AddItemHealthPercent  M1AspecialM 1 m1ahealth 1
                   	player.equipitem  M1AspecialM 0 1
                   	Player.removeitem  M1Aspecial 1 1
           	ElseIF player.getEquipped  M1AspecialM == 1
                   	Set m1ahealth to (Player.GetWeaponHealthPerc / 100)
                   	player.AddItemHealthPercent   M1Aspecial 1 m1ahealth 1
                   	player.equipitem  M1Aspecial 0 1
                   	player.RemoveItem   M1AspecialM 1 1
           	ElseIF IsKeyPressed m1akey
                   	IF Player.GetItemCount  M1AspecialM > 0
                           	Player.removeitem  M1AspecialM 1  1
                           	Player.AddItemHealthPercent   M1Aspecial 1  m1ahealth 1
                   	EndIF
                   	player.equipitem M1Aspecial 0 1  ; defaults to normal version
           	EndIF
   	ENDIF
EndIF

END ;GameMode Block

 

I borrowed the script from a rifle with similar functions (switching from 5.56mm AR to 40mm grenade launcher while maintaining weapon condition), and that weapon still works fine. All I've really done is changed item references and the names of variables.

 

I tested both weapons by adding them to my inventory with console, and they work fine, so I'm left debugging the script. Since I'm still rubbish at scripting, I could use a bit of help in that department.

Link to comment
Share on other sites

I'm having a hard time following this script. For example, this section will never execute because of the IF statement above it:

 

        IF Player.GetItemCount M1Aspecial == 0 
               IF m1ahealth > 0 
                       Player.AddItemHealthPercent M1Aspecial 1 m1ahealth 1 
               ELSE 
                       Player.AddItem M1Aspecial 1  
               EndIF 
       EndIF 

Is the script running on one or both weapons?

Link to comment
Share on other sites

Hmm, will fiddle with that. 'Player.GetItemCount M1Aspecial == 0' is an odd line. The script is assigned to both weapons (rifle and melee), but I may try removing it from one and see what that changes.

 

UPDATE: Mmk, tried the above- removed script from melee weapon, which resulted in a successful switch from rifle to melee, but now I need to figure out how to switch it back. Seems I might need multiple scripts, but the source rifle only had the one. Will scour it again, see if I find anything off.

Edited by DJZephyr
Link to comment
Share on other sites

Maybe try something like this on both weapons:

 

 

scn M1AFOSEScript 

;renamed variables to match the mod 
Short Setup 
Short m1akey 
Short m1atoggle 
Float m1ahealth
short curKey

BEGIN Gamemode 

;  Initialization 
IF Setup == 0 
 Set m1ahealth to .95
 Set m1akey to 46 ;  
 Set Setup to 1 
EndIF 

con_SetINISetting "fScopeScissorAmount:Display" 0.000 


  ;  Bayonet Toggle  
  
IF (curKey && IsKeyPressed curKey) ;Makes sure key is only registered once
 return
Else
 set curKey to 0
Endif

IF (IsKeyPressed m1akey)
 Set m1atoggle to 1
 Set curkey to m1akey
Endif

IF m1atoggle 
 Set m1atoggle to 0  
 IF Player.getEquipped M1Aspecial == 1 
  Set m1ahealth to (Player.GetWeaponHealthPerc / 100) 
  player.AddItemHealthPercent  M1AspecialM 1 m1ahealth 1 
  player.equipitem  M1AspecialM 0 1 
  Player.removeitem  M1Aspecial 1 1 
 ElseIF player.getEquipped  M1AspecialM == 1 
  Set m1ahealth to (Player.GetWeaponHealthPerc / 100) 
  player.AddItemHealthPercent   M1Aspecial 1 m1ahealth 1 
  player.equipitem  M1Aspecial 0 1 
  player.RemoveItem   M1AspecialM 1 1
 Elseif Player.GetItemCount M1Aspecial
  Player.RemoveItem M1Aspecial 1 1
  Player.AddItemHealthPercent M1AspecialM 1 m1ahealth 1
  Player.EquipItem M1AspecialM 0 1
 Elseif Player.GetItemCount M1AspecialM
  Player.RemoveItem M1AspecialM 1 1
  Player.AddItemHealthPercent M1Aspecial 1 m1ahealth 1
  Player.EquipItem M1Aspecial 0 1  
 EndIF 
ENDIF 


END ;GameMode Block

 

 

Link to comment
Share on other sites

It's m1akey being the same on both scripts that's crashing it. I tried my script with a hunting rifle and combat shotgun with two scripts identical except for the name and the key to press.

I'd have to see the original mod to figure out what they did to make it work.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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