Difference between revisions of "User:Diarrhoe"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>Diarrhoe
imported>Diarrhoe
Line 65: Line 65:
   if target
   if target
     disablePlayerControls
     disablePlayerControls
     player.setRestrained 1
     disableMouse
   else
   else
     set finished to 1
     set finished to 1
Line 138: Line 138:
       set finished to 1
       set finished to 1
       enablePlayerControls
       enablePlayerControls
       player.setRestrained 0
       enableMouse
       return
       return
     endif
     endif

Revision as of 11:41, 31 October 2010

Just modding around in Oblivion.

"The modder's worst foe is the player himself!"

I'm from Germany. So please excuse my poor English.

Script samples

A script for a trigger that makes the player look at the trigger's parent and at the parent's parent and...

scn DiarrhoeTriggerLookAtParentSCRIPT

; script needs OBSE as it uses mathematical functions
; sure, OBSE is not mandatory, but it makes the script much shorter

short init
short triggered
short break
short finished

ref target

;-------------------
; movement control
;-------------------

float pos_x
float pos_y
float pos_z
float z_offset

float ang_x
float ang_z

float target_pos_x
float target_pos_y
float target_pos_z

float diff_pos_x
float diff_pos_y
float diff_pos_z

float radicand
float sine
float heading_ang_x

float diff_ang_x
float diff_ang_z
float diff_ges

float timer
float secondsPassed


Begin onTriggerActor player

if finished
  return
endif

if triggered == 0
  set triggered to 1
  set break to 1
  set target to getParentRef
  if target
    disablePlayerControls
    disableMouse
  else
    set finished to 1
    return
  endif

  set pos_x to player.getPos x
  set pos_y to player.getPos y
  set pos_z to player.getPos z
  set z_offset to (player.getScale * (115 - 20*player.isSneaking))
  set pos_z to (pos_z + z_offset)

  set ang_x to player.getAngle x
  set ang_z to player.getAngle z
endif

end


Begin GameMode

if finished
  return
endif

if triggered
  set secondsPassed to getSecondsPassed
  if timer > 0
    set timer to (timer - secondsPassed)
    if break
      return
    endif
  else
    if break
      set break to 0
    else
      set break to 1
      set target to target.getParentRef
      set timer to 0.4
      return
    endif

    if target
      set target_pos_x to target.getPos x
      set target_pos_y to target.getPos y
      set target_pos_z to target.getPos z

      set diff_pos_x to (pos_x - target_pos_x)
      set diff_pos_y to (pos_y - target_pos_y)
      set diff_pos_z to (pos_z - target_pos_z)


      set radicand to (diff_pos_x*diff_pos_x + diff_pos_y*diff_pos_y + diff_pos_z*diff_pos_z)
      set sine to (diff_pos_z / (sqrt radicand))
      set heading_ang_x to (asin sine)


      set diff_ang_x to ((heading_ang_x - ang_x) * 89 / 90)
      set diff_ang_z to player.getHeadingAngle target


      set radicand to (diff_ang_x*diff_ang_x + diff_ang_z*diff_ang_z)
      set diff_ges to (sqrt radicand)
      set timer_start to (0.2 + diff_ges/(28 + diff_ges/3))
      if timer_start > 2.5
        set timer_start to 2.5
      endif
      set timer to timer_start

      return
    else
      set finished to 1
      enablePlayerControls
      enableMouse
      return
    endif
  endif

  set ang_x to (ang_x + (diff_ang_x * secondsPassed / timer_start))
  player.setAngle x ang_x

  set ang_z to (ang_z + (diff_ang_z * secondsPassed / timer_start))
  player.setAngle z ang_z
  return
endif

end

Contact

To contact me, you can: