public
Last active

  • Download Gist
LevitationEffectScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
ScriptName LevitationEffectScript
 
;*******************************
;
; This script current on gist
;
;*******************************
; Author: Saltare
; Email: Saltare_ferocan@hotmail.com
; Date: 26-09-2006
; Version: 0.2
;
; You may alter, rip, crush & destroy this piece of script as much as you want ^_~
;
; Description:
; This script makes the player able to fly around
; It aims at having a good new movement feeling with clipping
; However certain velocity forces are lost (such as impact on hit)
; After experimenting with setting the position of the player i came to the following order of events
;
; new frame
; Oblivion adjusts the player position using,
; -intension of player to go
; -is in water/sneaking/jumping/stunned (change gravity, en movement speeds)
; -is hit by target (with additional force info), or other forces
; -add gravity and other forces
; Later then this script is run (it said RUNNED!!!, changed by Jeff Vinall)
;
; The problem here is, that in scripting there is no way to access these pieces of info seperatly
; It all comes packed into a new xyz.
; Therefore this script tries to determine according to its own forces if there was a force change which doesn't
; comply with the previous frames position and intension of direction.
; If so then it assumes it was a collision with the world and resets the position for a certain axis
;
; Detecting clipping the gravity example
; if the player wants to go down it overrides the current Z with a new value
; At the next frame when the script is runned check if the player really did go down,
; if not then there was a collision
;
; Problems:
; Due to the simplicity of collision detection, the xy collision detection/response isn't really working.
; Resulting in weird behaviour and has been commented out for such.
;
; Requirements:
; Oblivion script extender. (Script was made using version v0008)
; Alexanders Wing. (visual effect of wings on the player)
;*******************************
 
;*******************************
; Note the axis in Oblivion are specified as follows
; X = Horizontal
; Y = Depth
; Z = Altitude Vertical
; XY are the 2D position on the map so to say
; and Z is the height of the character
;*******************************
 
;*******************************
; Positional data variables
;*******************************
float velocityX
float X
float posX
 
float velocityY
float Y
float posY
 
float flowSpeed
float customSpeedAdjuster
 
float zAngle
float zAngleCross
 
float Z
float velocityZ
float oldZ
float newZ
float xAngle
float posZ
float jumpTimer
float moveTimer
 
;*******************************
;Indication if flying
;*******************************
short isNotFlying
short isMoving
 
 
;*******************************
; Cell information
;*******************************
short isInInteriorLocal
ref CellLastFrame
 
;*******************************
; References
;*******************************
ref self
ref itemFlying
ref itemNonFlying
short wingIndex
ref worldRef
 
float changeTimer ;a quick and dirty solution for not changing wings too fast
 
short forward
short backward
short strafeLeft
short strafeRight
short activateFlying
short deactivateFlying
short increaseSpeed
short decreaseSpeed
short switchWings
short jumpDetect
 
;*******************************
; A timer to use as accellerator for indepent frame movement
; Get the passed time between frames.
;*******************************
float timePassed
 
short jumpCode
;*******************************
; Block: ScriptEffectStart (Constructor)
; Description: Initial start of the script
; Sets the initial values to the variables in use.
; Adjust game setting parameters.
;*******************************
begin ScriptEffectStart
;message "Levitation script start"
set isInInteriorLocal to 0
;EnableFastTravel 0
 
;*******************************
; initialize variables
;*******************************
set oldZ to getPos z
set X to getPos x
set Y to getPos y
set customSpeedAdjuster to 1
set isNotFlying to 1
set self to GetSelf
set CellLastFrame to self.GetParentCell
set worldRef to Tamriel ;CellLastFrame.GetParentRef
 
;*******************************
; Set the wings initial
;*******************************
set wingIndex to 6
set itemFlying to AWWings3AFlying
if ( self.GetItemCount itemFlying <= 0 )
self.additem itemFlying 1
endif
 
set itemNonFlying to AWWings3ANonFlying
if ( self.GetItemCount itemNonFlying <= 0 )
self.additem itemNonFlying 1
endif
 
self.EquipItem itemNonFlying 1
 
set changeTimer to 0.5 ; 0.5 seconds
;*******************************
; Try to find out the current assigned jump key
; Note: doesn't seem to work, getting a 0 as value returned
; Using hardcoded keycodes
;*******************************
;set jumpCode to GetControl 13
;message "jumpcode is %i", jumpCode
 
;*******************************
; Key bindings
;*******************************
set forward to 200
set backward to 208
set strafeLeft to 203
set strafeRight to 205
set activateFlying to 40
set deactivateFlying to 39
set increaseSpeed to 27
set decreaseSpeed to 26
set switchWings to 25
set jumpDetect to 54
set isMoving to 0
set moveTimer to 3
;*******************************
;Note:
;function GetAngle
;X angle returns a value (theorically) from -90 to 90. The true in-game range is -89 to 89,
;with -89 if the player is looking above himself, and 89 if player is looking at his feet.
;*******************************
end
 
;*******************************
; Block: ScriptEffectFinish
; Description: Stops the script (Destructor)
; Reset certain game setting values
;*******************************
begin ScriptEffectFinish
;EnableFastTravel 1
 
;this crashes for some reason :/
;Really weird this is because the line
; if ( self.GetItemCount itemFlying > 0 )
; still works, however the actual removal crashes the whole game :S
 
;remove current wings
; if( isNotFlying )
; self.unequipItem itemNonFlying 1
; else
; self.unequipItem itemFlying 1
; endif
 
; if ( self.GetItemCount itemFlying > 0 )
; self.removeitem itemFlying 1
; endif
; If ( self.GetItemCount itemNonFlying > 0 )
; self.removeitem itemNonFlying 1
; endif
 
end
 
;*******************************
; Block: ScriptEffectUpdate
; Description: Loop the script
; Unleashes the flying algoritm ^_~
;*******************************
begin ScriptEffectUpdate
 
;*******************************
;get the time passed from the last frame
;returns a nice float with good enough accurancy
;*******************************
set timePassed to GetSecondsPassed
 
;*******************************
;Start Wing selection
;Key home
;*******************************
if( isKeyPressed2 switchWings)
set changeTimer to changeTimer - timePassed
if( changeTimer <=0 )
set changeTimer to 0.5 ;reset the timer
 
;remove current wings
if ( self.GetItemCount itemFlying > 0 )
self.removeitem itemFlying 1
endif
If ( self.GetItemCount itemNonFlying > 0 )
self.removeitem itemNonFlying 1
endif
 
;set index counter to next wings
set wingIndex to wingIndex + 1
if (wingIndex > 16) ;note: Change when adding new wings
set wingIndex to 1;
endif
 
;set wing refs
if ( wingIndex == 1 ) ;note: Add a new if for every new type of wings
set itemFlying to AWWings1Flying
set itemNonFlying to AWWings1NonFlying
elseIf ( wingIndex == 2 )
set itemFlying to AWWings1AFlying
set itemNonFlying to AWWings1ANonFlying
elseIf ( wingIndex == 3 )
set itemFlying to AWWings2Flying
set itemNonFlying to AWWings2NonFlying
elseIf ( wingIndex == 4 )
set itemFlying to AWWings2AFlying
set itemNonFlying to AWWings2ANonFlying
elseIf ( wingIndex == 5 )
set itemFlying to AWWings3Flying
set itemNonFlying to AWWings3NonFlying
elseIf ( wingIndex == 6 )
set itemFlying to AWWings3AFlying
set itemNonFlying to AWWings3ANonFlying
elseif ( wingindex == 7)
set itemflying to AWwings4flying
set itemnonflying to AWwings4flying
elseif ( wingindex == 8)
set itemflying to AWwings5flying
set itemnonflying to AWwings5flying
elseif ( wingindex == 9)
set itemflying to AWwings6flying
set itemnonflying to AWwings6flying
elseif ( wingindex == 10)
set itemflying to AWwings7flying
set itemnonflying to AWwings7flying
elseif ( wingindex == 11)
set itemflying to AWwings8flying
set itemnonflying to AWwings8flying
elseif ( wingindex == 12)
set itemflying to AWwings9flying
set itemnonflying to AWwings9flying
elseif ( wingindex == 13)
set itemflying to AWwings10flying
set itemnonflying to AWwings10flying
elseif ( wingindex == 14)
set itemflying to AWwings11flying
set itemnonflying to AWwings11flyingD
elseif ( wingindex == 15)
set itemflying to AWwings12flying
set itemnonflying to AWwings12flying
elseif ( wingindex == 16)
set itemflying to AWwings13flying
set itemnonflying to AWwings13flying
endif
;set the wings
if ( self.GetItemCount itemFlying <= 0 )
self.additem itemFlying 1
endif
if ( self.GetItemCount itemNonFlying <= 0 )
self.additem itemNonFlying 1
endif
 
;and re-equip wings, depending on flying or not
if( isNotFlying )
self.equipItem itemNonFlying 1
else
self.equipItem itemFlying 1
endif
endif
endif
;*******************************
;End Wing selection
;*******************************
 
set Z to getPos z
set velocityZ to 0
;*******************************
; Check if we have changed from cell, then we need to adjust the position
;*******************************
if( CellLastFrame != self.GetParentCell )
set CellLastFrame to self.GetParentCell
if(isNotFlying == 0)
if(isInInteriorLocal == 0 && IsInInterior == 0)
;changing from exterior cell to another (however the new cell can belong to another worldspace
;A crude workaround for not being able to get the Worldspace ID
;Currently i don't know a way to detect if the player changed from world space type
;okay i do know one, but that solution sucks even more (by using handtyped checks on all possible worldspaces)
;i know this is also ridiculous crappy, but i hope it is only temporary >_<
set newZ to getPos x - X ;reusing the variable newZ (is going to be set later on anyway)
if( newZ > 200 || newZ < -200 ) ;detect a sudden change on the x-axis
set oldZ to getPos z + 20
set X to getPos x
set Y to getPos y
endif
set newZ to getPos y - Y
if( newZ > 200 || newZ < -200 ) ;detect a sudden change on the y-axis
set oldZ to getPos z + 20
set X to getPos x
set Y to getPos y
endif
else
set isInInteriorLocal to IsInInterior
set oldZ to getPos z+20
set X to getPos x
set Y to getPos y
Message "Entering new cell - in/out", 10
endif
endif
endif
 
;*******************************
; Check if we want to go flying, if so set initial vars
;and change equipment
;*******************************
if ( iskeypressed2 activateFlying && isNotFlying)
set isNotFlying to 0
self.unequipItem itemNonFlying 1
self.equipItem itemFlying 1
;reset the initial variables
set oldZ to Z
set X to getPos x
set Y to getPos y
endif
 
;*******************************
; Check for flying triggering via extended jump key
;and change equipment
;******************************
if ( iskeypressed2 jumpDetect && isNotFlying)
set jumpTimer to jumpTimer - timePassed
if( jumpTimer <=0 )
set jumpTimer to 1.0 ;reset the timer
set isNotFlying to 0
self.unequipItem itemNonFlying 1
self.equipItem itemFlying 1
;reset the initial variables
set oldZ to Z
set X to getPos x
set Y to getPos y
endif
else
set jumpTimer to 1.0
endif
;*******************************
; If not flying stop script for current frame
;*******************************
;if( isNotFlying)
; if ( iskeypressed2 forward || iskeypressed2 backward || iskeypressed2 strafeLeft || iskeypressed2 strafeRight)
; set isMoving to 1
; set moveTimer to 3
; else
; set moveTimer to moveTimer - timePassed
; endif
;endif
 
;if (moveTimer <= 0)
; set isMoving to 0
;endif
;if ( isMoving )
; self.unequipItem itemNonFlying 1
; self.equipItem itemFlying 1
;else
; self.unequipItem itemFlying 1
; self.equipItem itemNonFlying 1
;endif
 
if ( isNotFlying)
return
endif
;*******************************
; If Key T is pressed or is gone swimming .. then stop flying
; also equipment change
;*******************************
if(iskeypressed2 deactivateFlying || isSwimming )
self.unequipItem itemFlying 1
self.equipItem itemNonFlying 1
set isNotFlying to 1
return
endif
 
set zAngle to GetAngle z
set xAngle to GetAngle x
 
set velocityX to 0
set velocityY to 0
 
;*******************************
;Movement
;*******************************
if( isKeyPressed2 forward)
;*******************************
; adjust fly behaviour
;*******************************
if ( xAngle < 0 )
set flowSpeed to 1 + xAngle * 0.01111111 ;
else
if (xAngle <= 45)
set flowSpeed to 1 + xAngle * 0.0222222 ;
else
set flowSpeed to 2 - ((xAngle - 44) * 0.0444444) ;
endif
endif
set flowSpeed to flowSpeed * customSpeedAdjuster
 
set velocityX to Sin zAngle * flowSpeed
set velocityY to Cos zAngle * flowSpeed
set velocityZ to timePassed * -20 * xAngle
endif
 
if( isKeyPressed2 strafeLeft )
set zAngleCross to zAngle - 90 ;going left
set velocityX to velocityX + Sin zAngleCross
set velocityY to velocityY + Cos zAngleCross
endif
 
if( isKeyPressed2 backward )
set zAngleCross to zAngle + 180 ;going back around
set velocityX to velocityX + Sin zAngleCross
set velocityY to velocityY + Cos zAngleCross
set velocityZ to timePassed * 10 * xAngle
endif
 
if( isKeyPressed2 strafeRight )
set zAngleCross to zAngle + 90 ; going right
set velocityX to velocityX + Sin zAngleCross
set velocityY to velocityY + Cos zAngleCross
endif
 
if ( iskeypressed2 activateFlying )
set velocityZ to velocityZ + 20 ; going up
endif
 
if( iskeypressed increaseSpeed)
set customSpeedAdjuster to customSpeedAdjuster + 0.1
elseif( iskeypressed decreaseSpeed)
set customSpeedAdjuster to customSpeedAdjuster - 0.1
if ( customSpeedAdjuster <= 1 )
set customSpeedAdjuster to 1
endif
endif
 
set velocityX to velocityX * timePassed * 500 ; 500 a fixed multiplyer for the time value
set velocityY to velocityY * timePassed * 500
 
;set posX to getPos x - X
;set posY to getPos y - Y
 
;*******************************
;some failed attempt to have some sort of collosion detection
;uncomment to see what happens, only works when flying slow :/
;*******************************
;if ( velocityX >=0 && posX <= 0) || ( velocityX <=0 && posX >= 0)
; set X to getPos x
;else
set X to X + velocityX
;endif
;if ( velocityY >=0 && posY <= 0) || ( velocityY <=0 && posY >= 0)
; set Y to getPos y
;else
set Y to Y + velocityY
;endif
 
;*******************************
;simple collision detection on height
;if going down and prevFrameZ is lower then getPos z then assume collision
;*******************************
if ( velocityZ < 0 && oldZ < Z)
Set velocityZ to 0
set isNotFlying to 1
self.unequipItem itemFlying 1
self.equipItem itemNonFlying 1
endif
 
set newZ to oldZ + velocityZ
 
;*******************************
;if hanging around or going up and the newZ is still lower then the getPos z then assume being to low (collision)
;*******************************
if ( velocityZ >= 0 && newZ < Z)
set isNotFlying to 1
self.unequipItem itemFlying 1
self.equipItem itemNonFlying 1
set newZ to Z
endif
 
;*******************************
; Set new xyz position
;*******************************
setPos y, Y
setPos x, X
setPos z, newZ
set oldZ to newZ
 
;For some reason setScale prevent you from falling down (thus no gravity), but it also completly resets the animation
;self.setscale 1.0
resetFallDamageTimer
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.