Jump to content

Custom made trap


LucidDreaming

Recommended Posts

I'm having trouble getting my script for a player-made trap to work. It makes it so when an item is added to a dead enemy's inventory (through hitting him. which is in another script), it makes him a mine.

Any ideas? (There are no scripting issues, it just doesn't work in game)

 

 

short trapTriggered
short trapDisarmed
short interactAttempt

float bufferTimer
float timer

Begin onAdd
set interactAttempt to 1
set bufferTimer to 5
set trapDisarmed to 0
set trapTriggered to 0
End

Begin gamemode

if (trapDisarmed == 0)
if (trapTriggered == 0)
	if (bufferTimer > 0)
		set bufferTimer to (bufferTimer - GetSecondsPassed)
	elseif (bufferTimer < 0)
		set trapTriggered to 1
	endif
endif
endif

if (trapTriggered == 1)
if (getdistance player <= 400)
	set trapTriggered to 2
	set timer to 1
endif
endif

if (trapTriggered == 2)
if (timer > 0)
	set timer to (timer - GetSecondsPassed)
elseif (timer < 0)
	placeatme 40mmGrenadeExplosion 1
	set trapTriggered to 5
endif
endif

end

Link to comment
Share on other sites

I think placeatme needs a reference that is in the worldspace.

So add these lines...

 

ref DeadDude

 

set DeadDude to GetContainer

DeadDude.placeatme 40mmGrenadeExplosion 1

 

If that still doesn't work then I'd add some ShowMessage debugging lines to see how far the process actually gets.

 

Edit: Just noticed GetDistance in there too. Same issue: DeadDude.getdistance player

Edited by tunaisafish
Link to comment
Share on other sites

are you sure? I noticed that the LegateKnokdownScript doesn't use a reference for it...I think that I would need one if this were an object script, but it's an effect script attached to a piece of non-playable armour.

And the getdistance I used from an existing trap...they should work...I'll try it later, though, and try the showmessage idea.

Honestly, though, I tried avoiding refs, because I'd have to use getself, which I dont really understand

Edited by LucidDreaming
Link to comment
Share on other sites

Yep, you're right about it needing to be an object script. I'd assumed that's what you'd done :)

 

The effect script on a piece of armour would only run if the armour were equipped, and it would be written differently using ScriptEffectStart blocks etc. (I'm pretty sure that the OnAdd and GameMode blocks are ignored in effect scripts).

 

So...

Change that script to an Object type.

Set the armour 'Object Effect' to NONE, and select the scriptname in the 'Script' dropdown box.

Link to comment
Share on other sites

I think I found the actual problem. The script for the object used to add the non-playable item to the target isn't working...

 

short button

Begin OnHit

Ref CattleProdTarget
Set CattleProdTarget to GetOwnerLastTarget

If (CattleProdTarget != PlayerRef)
	If CattleProdTarget.GetDead == 1
		ShowMessage CorpseRearmMsg
		set button to getbuttonpressed
		If [button == 0]
			CattleProdTarget.additem CorpseBombGlasses40mm 1
			CattleProdTarget.additem WeapKnife 1
			player.removeitem Ammo40mmGrenade 2
		else
			ShowMessage MessageFail1
		endif
	Else
		ShowMessage MessageFail2
		;do nothing
	endif
Else
	ShowMessage MessageFail3
	;do  nothing
EndIf

End

I assumed it was fine, since none of the error messages popped up, and the CorpseRearmMsg appeared (button '0' is the rearm button, the one I always pressed). However, I noticed that there was no deduction of 40mm ammo...what's happening?

Link to comment
Share on other sites

The menu is probably not working like you think it is.

ShowMessage does NOT block the script. So by the time you press option 0 the OnHit part has already completed.

The button press value will be stored until your same script calls GetButtonPressed.

[As GetButtonPressed is just after a ShowMessage command then it probably always gets the value -1]

 

The wiki has an example of how to catch menu input within a gamemode block.

 

BTW, It generally a good idea to avoid gamemode blocks where you can, as they run every frame. For that reason it would be more efficient to put the menu code within the armour token, as that has a shorter life. You could check the inventory count of the token within the OnHit block so only one is added at a time. Think about efficiency later though, get it working first :)

 

Another thing which seems a bit weird to me now that both scripts are here, and I'm not sure if it is intended. The mine is placed by the player using his own ammo, yet it is only triggered by the player.

Link to comment
Share on other sites

Okay...I don't care too much that the messages are not being shown (they were meant to be debug messages, although I guess they failed)

 

Um, this is my first mod, and I'm really trying to do whatever works. I tried doing it as a perk, like cannibal, but I couldn't figure out how to reference the target.

Yeah, when I get it working, I'm planning on doing something like the hasbeeneaten for cannibal, and making it so that you can't mine people who have been disintegrated of completely blown apart

 

I know it's weird, but as I've said before, I based most of it off of existing traps (there is a legacy script for the unwilling suicide bomber from FO3, whether he is alive or dead). Even after rearming a trap, some still use getdistance player, or it is not apparent how enemies would blow up.

Look up the script TrapMailboxSCRIPT, for where I got most of my code.

 

Of course, it's not working, so what should I do? If I knew how mines worked, I'd do something like that.

 

This bit is from the TrapCorpseSCRIPT.

	if (button > -1)
		set interactAttempt to 0
		if (button == 0)
			;player wants to rearm as a proximity trap
			ShowMessage TrapRearmProximityMsg
			set trapTriggered to 2												;trap is rearmed so start buffer timer
			set trapDisarmed to 0
			set bufferTimer to 10	

if (trapDisarmed == 0)
	if (trapTriggered == 0)
		if (getdistance Player <= 400)
			mySelf.playSound OBJMegatonBombTamperArm
			set trapTriggered to 1
			set timer to 1
		endif
	endif

	if (trapTriggered == 1)
		if (timer >0)
			set timer to (timer - GetSecondsPassed)
		elseif (timer<0)
			mySelf.playSound WPNRifleLaserReloadInOut
			set trapTriggered to 4
			set timer to 4
		endif
	endif

	if (trapTriggered == 2)														;trap has been rearmed as proximity so start buffer timer
		if (bufferTimer > 0)
			set bufferTimer to (bufferTimer - GetSecondsPassed)
		elseif (bufferTimer < 0)
			set trapTriggered to 0												;buffer time is up, trap is now rearmed
		endif
	endif

	if (trapTriggered == 4)
		if (timer > 0)
			set timer to (timer - GetSecondsPassed)
		elseif (timer < 0)
			mySelf.placeatme GrenadeFragExplosion 1
			; kill me bloodily
			kill mySelf 1
			kill mySelf 3
			kill mySelf 5
			kill mySelf 7
			kill mySelf 10
			set trapDisarmed to 2											;trap has exploded
		endif
	endif	
endif

End

Link to comment
Share on other sites

  • Recently Browsing   0 members

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