Conditional statement problem

Post » Thu Aug 11, 2011 10:22 am

I've got an assault rifle with an underbarrel grenade launcher. I've got them set up as separate formids (assault rifle = "weapon1"; M203 = "weapon2") and I've got scripts attached to them. I'm using NVSE and the script on each weapon monitors for a key press ("M") which will swap out the weapons.

I'm not having any problem at all capturing the keypress and I know this because I can successfully fire a message every time I hit the "M" key. The problem is in the conditional section of this code:

scn gdnvCarb203Swapint iModeBEGIN OnEquip    if iMode == 0        if getequippedobject 5 == weapon1                set iMode to 1        else                set iMode to 2        endif    endifEND BEGIN GameModethe conditional below is wrapped in a keypress event -- I have removed all that codebecause I know with 100% certainty that the error is not there.if iMode == 1     ; assault rifle version currently equipped, switch to M203	set iMode to 2	player.additem weapon2 1 1	player.equipitem weapon2	removemeelseif iMode == 2     ; m203 currently equipped, switch to rifle	set iMode to 1	player.additem weapon1 1 1	player.equipitem weapon1	removemeendifEND 


What happens is, I load up the game, add weapon1 via console, and equip it. Then I hit "M" and the weapon swaps to the M203 (grenade launcher) version. When I hit "M" again, nothing happens - the M203 remains. I have the same script attached to both weapons and it looks like it should work, but maybe I'm just too close to the code. Even more interesting is when I drop the M203 version, pick it up, equip it, and hit "M" -- it unequips (leaving me with just my fists out) but the model sticks itself to my right arm.

If anybody's got any pointers or better ways to handle such swaps... do you care to share?
User avatar
SUck MYdIck
 
Posts: 3378
Joined: Fri Nov 30, 2007 6:43 am

Post » Thu Aug 11, 2011 11:17 am

OnEquip blocks don't run when you equip an item through script (or for NPCs if they spawn with the item equipped). I generally handle this with a structure like:
begin OnEquipset Container to GetContainerset Active to 1endbegin GameModeif(Container)   ;Actual codeelse   set Container to GetContainer   if(Container)      if(Container.GetEquipped ThisItem)         set Active to 1      endif   endifendifend

User avatar
Jerry Jr. Ortiz
 
Posts: 3457
Joined: Fri Nov 23, 2007 12:39 pm

Post » Thu Aug 11, 2011 8:16 pm

OnEquip blocks don't run when you equip an item through script (or for NPCs if they spawn with the item equipped).


Ohhhh... hmm. That changes things. I'll have to fiddle with it when I get home then.

Thanks, TTT - this is a big help!!
User avatar
Darrell Fawcett
 
Posts: 3336
Joined: Tue May 22, 2007 12:16 am

Post » Thu Aug 11, 2011 8:04 pm

I couldn't seem to get it to work, so I scrapped as much of the code as I could and got it down to bare bones, just trying to add a custom weapon when I hit the "M" key.

The script (in its entirety) is below.

When I try to call player.additem customweaponname 1 the game crashes. (I'm using NVSE for the keypress event, btw)

scn GDNVItemAddint iMkeybegin gamemode	if imkey != iskeypressed 50		set imkey to iskeypressed 50		if imkey			player.additem WeapGDNVM249 1		endif	endifend


That block of code right there crashes my game 10 out of 10 times when it's called. I can spawn that weapon in with a console command (using the object id) but I cannot get this to work through script. I have copied the *exact* formid (it's "WeapGDNVM249") for the weapon from the GECK and pasted it in, so I know the spelling is correct.

The real kick between the legs here? If I change "WeapGDNVM249" to "WeapNV9mmPistol" then the script adds a 9mm pistol every time I hit "M" and it doesn't ever crash on me.

I'm hoping somebody can help me figure out why this doesn't want to work with a custom weapon.
User avatar
Chris Guerin
 
Posts: 3395
Joined: Thu May 10, 2007 2:44 pm

Post » Thu Aug 11, 2011 12:50 pm

From what you describe, it sounds like WeapGDNVM249 is NOT in your ESP mod. If thats the case then you cannot use a resource in another plugin in your own plugins. Only from a master file.
User avatar
luis ortiz
 
Posts: 3355
Joined: Sun Oct 07, 2007 8:21 pm


Return to Fallout: New Vegas