Jump to content

NVSE based player Movement Script: needs optimization, slight debuggin


angelwraith

Recommended Posts

Ok so here is the script i am using for a device that acts somewhat like tcl outside at the push of a button by moving around an invisible ball under the player so they always have a surface to walk on. then it moves the player a small amount each frame each movement key is pressed. i had all eight directions but i couldn't figure out how to set up button priority with the if and elseif so that if two buttons were presses at the same time it acted appropriately.

 

ok what this post is really about:

  1. a bug where if using the device for a reeeeaaaally long time for some reason RARELY the ball surface underneath will stop updating, which if you're really high leaves you in a world of hurt cause that sudden stop....
  2. i know what i did here is inefficient.. and clunky. (especially in the way it enables and disables with those two separate variables).. however it does work. And i believe that with the knowledge here between you all, for sure it can be tidied up a bit to where itll run smoother (its pretty smooth as is, nevertheless i think you all can do better..) and maybe even eliminate that bug with teh surface not updating as well.
  3. wish list: a variable inertia. right now there is no acceleration, deceleration and i kinda want it to act more like your floating a bit not a whole lot, but a small amount.. and if that amount could be changed by a few simple numbers or even better a variable i would be ecstatic.. however.. the whole math thing is way beyond me anymore and i have no idea where to even start with it
  4. almost forgot... that timer interrupt there you see was my best attempt to stop the game from a CTD if the player were to turn the device on while moving. which i suspected had something to do with the variables changing because it didnt CTD if they were still... so i disable controls for the split second as the thing initialized... and it works, but if there is a better way please enlighten me.. i dont like the weapon being put up which comes on by disable player controls.. although i guess i could just disable movement... but still theres gotta be a better way.

 

 

without further adieu here is the code of which we speak.. and thank you for looking at it with me.

 

 

 

 

	; Plank hotkey
ref plankhotkey
int stoggleZ
float plankXpos
float plankYpos
float plankZpos
float plankangleX
float plankangleXb
int plankIO
float planktimer
short plankactivatedd
float plankZAngle
float dropVAR
float playerheightmodfloat
float fAngle
float fRelativePos
float WBXpos
float interuptTimer



set plankhotkey to SUBskillcostREF.plankhotkey
if plankhotkey == 0
	set plankhotkey to 156
endif
if IsKeyPressed plankhotkey != stoggleZ
	set stoggleZ to IsKeyPressed plankhotkey 
	if stoggleZ ;Button pressed
		if plankactivatedd == 0
			if player.IsInInterior == 0
				set plankactivatedd to 1
				set plankIO to 0
				set interuptTimer to 0
				disableplayercontrols
			else
				showmessage SUBcantdothatinside
			endif
		else
			set plankactivatedd to 0
			set plankIO to 1
		endif
	endif
endif


set interuptTimer to interuptTimer  + GetSecondsPassed	
if plankactivatedd == 1 && plankIO == 0
	SUBplankREF.Disable
	SUBplankREF.MoveTo Player 0 0 0
	SUBplankREF.Enable
	set plankXpos to SUBplankREF.GetPos X
	SUBplankREF.SetPos X plankXpos
	SUBjetpropREF.Disable
	SUBjetpropREF.MoveTo Player 0 0 0
	SUBjetpropREF.Enable
	SUBjetpropREF.SetPos X plankXpos
	set plankZpos to player.Getpos Z
	set planktimer to 0
	set plankIO to 1

elseif plankactivatedd == 1 && plankIO == 1
	if interuptTimer >= .2
		EnablePlayerControls
	endif
	If player.IsInInterior == 1
		set plankactivatedd to 0
	endif
	set plankangleX to player.getangle X
	set plankXpos to player.Getpos X
	set plankYpos to player.Getpos Y
	set plankZpos to player.Getpos Z
	set plankZpos to plankZpos - 126


	set dropVAR to ( ( plankangleX / 90 ) * 50 )



	if IsControlPressed 0 && interuptTimer >= .2
		set fAngle to player.GetAngle Z
		set fRelativePos to player.GetPos Y + 20 * cos fAngle
		player.SetPos Y fRelativePos
		set fRelativePos to player.GetPos X + 20 * sin fAngle
		player.SetPos X fRelativePos
		if plankangleX > 0 && plankangleX < 90 
			set playerheightmodfloat to ( player.getpos Z - dropVAR )
			player.setpos Z playerheightmodfloat
		elseif plankangleX < 0 && plankangleX > -90 
			set playerheightmodfloat to ( player.getpos Z - dropVAR )
			player.setpos Z playerheightmodfloat
		endif
		goto 86
	endif

	if IsControlPressed 1 && interuptTimer >= .2
		set fAngle to player.GetAngle Z
		set fRelativePos to player.GetPos Y - 20 * cos fAngle
		player.SetPos Y fRelativePos
		set fRelativePos to player.GetPos X - 20 * sin fAngle
		player.SetPos X fRelativePos
		if plankangleX > 0 && plankangleX < 90 
			set playerheightmodfloat to ( player.getpos Z + dropVAR )
			player.setpos Z playerheightmodfloat
		elseif plankangleX < 0 && plankangleX > -90 
			set playerheightmodfloat to ( player.getpos Z + dropVAR )
			player.setpos Z playerheightmodfloat
		endif
		goto 86
	endif

	if IsControlPressed 2 && interuptTimer >= .2
		set fAngle to player.GetAngle Z + 90
		set fRelativePos to player.GetPos Y - 20 * cos fAngle
		player.SetPos Y fRelativePos

		set fRelativePos to player.GetPos X - 20 * sin fAngle
		player.SetPos X fRelativePos
		goto 86
	endif

	if IsControlPressed 3 && interuptTimer >= .2
		set fAngle to player.GetAngle Z + 270
		set fRelativePos to player.GetPos Y - 20 * cos fAngle
		player.SetPos Y fRelativePos

		set fRelativePos to player.GetPos X - 20 * sin fAngle
		player.SetPos X fRelativePos
		goto 86
	endif




	label 86

	if IsControlPressed 12 && interuptTimer >= .2
		set playerheightmodfloat to ( player.getpos Z + 20 )
		player.setpos Z playerheightmodfloat
	endif
	if plankangleX > 52 && plankangleX < 90 && IsControlPressed 4 == 1
		SUBplankREF.disable
	else
		SUBplankREF.enable			
	endif
	set plankZAngle to player.GetAngle Z
	set plankZAngle to plankZAngle + 90
	SUBplankREF.setPos X plankXpos
	SUBplankREF.setPos Y plankYpos
	SUBplankREF.setPos Z plankZpos
	SUBplankREF.setAngle X 0
	SUBplankREF.setAngle Y 0
	SUBplankREF.setAngle Z plankZAngle 
	SUBjetpropREF.setPos X plankXpos
	SUBjetpropREF.setPos Y plankYpos
	set plankZpos to plankZpos + 126
	SUBjetpropREF.setPos Z plankZpos
	SUBjetpropREF.setAngle X 0
	SUBjetpropREF.setAngle Y 0
	SUBjetpropREF.setAngle Z plankZAngle 
elseif plankactivatedd == 0 && plankIO == 1
	SUBplankREF.Disable
	SUBjetpropREF.Disable
	set plankIO to 0
	set plankactivatedd to 0
endif

 

 

in the off chance you're interested in seeing it in action look here there's actually a buncha cools stuff in there this is in no means the focus of the mod.. however important to me.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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