Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jul 23rd, 2014  |  syntax: TCL  |  size: 5.65 KB  |  views: 252  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #
  2. # This script defines the player entity
  3. #
  4.  
  5. func Player:constructor {ent type} {
  6.     set global player $ent
  7.     set global player-firstperson 0
  8.     set global player-rotation 0
  9.     set global player-lookrot 0
  10.     set global player-rotspeed 0
  11.     set global player-turnmul 1
  12.     set global player-movexmul 1
  13.     set global player-moveymul 1
  14.     camera-chase $player 128
  15.     camera-offset 0 16 0
  16.     entity-model $ent [get-model rob.rtm]
  17.     entity-cspheres $ent {{0 12 0 12} {0 -12 0 12}}
  18.     entity-blocking $ent 1 {{-1 0 -1} {1 0 1}}
  19.  
  20.     capture mouse 1
  21. }
  22.  
  23. func toggle-perspective {v} {
  24.     if not $v return
  25.     if $player-firstperson {
  26.         set global player-firstperson 0
  27.         set global player-lookrot 0
  28.         camera-chase $player 128
  29.         camera-smooth 0.2
  30.         entity-visible $player 1
  31.         entity-rotation $player yxz 0 $player-rotation 0
  32.     } {
  33.         set global player-firstperson 1
  34.         camera-fpp $player
  35.         entity-visible $player 0
  36.     }
  37. }
  38.  
  39. func key:t {v} {
  40.     if not $v return
  41.     eset $player stop-light [expr ![eget $player stop-light]]
  42. }
  43.  
  44. func toggle-flashlight {v} {
  45.     if not $v return
  46.     local light
  47.     set light [eget $player light]
  48.     if $light {
  49.         dlight-remove $light
  50.         eset $player light {}
  51.     } {
  52.         set light [dlight-new spot]
  53.         dlight-radius $light 768
  54.         dlight-inner-radius $light 600
  55.         dlight-shadow $light 1
  56.         dlight-color $light {1.3 1.0 0.9}
  57.         eset $player light $light
  58.         eset $player stop-light 0
  59.     }
  60. }
  61.  
  62. foreach {forward backward strafe-left strafe-right turn-left turn-right} {
  63.     func $i {v} "set global go-$i \$v"
  64. }
  65.  
  66. func turn {delta} {
  67.     if not $player return
  68.     set global player-rotation [expr $player-rotation - $delta * 0.0035 * $turnspeed ]
  69.     entity-rotation $player yxz $player-lookrot $player-rotation 0
  70.     if $player-firstperson { camera-smooth 1 }
  71. }
  72.  
  73. func look {delta} {
  74.     if $player-firstperson {
  75.         set global player-lookrot [expr $player-lookrot + $delta * 0.0035 * $turnspeed ]
  76.         if [expr $player-lookrot < -1.55] {
  77.             set global player-lookrot -1.55
  78.         }
  79.         if [expr $player-lookrot > 1.55] {
  80.             set global player-lookrot 1.55
  81.         }
  82.         entity-rotation $player yxz $player-lookrot $player-rotation 0
  83.     } {
  84.         set global player-lookrot 0
  85.     }
  86. }
  87.  
  88. func joy-turn {delta} {
  89.     set delta [expr $delta / 32000.0]
  90.     set global go-turn-left 0
  91.     set global go-turn-right 0
  92.     set global player-turnmul 1
  93.     if [expr $delta > 0.25] {
  94.         set global player-turnmul $delta
  95.         set global go-turn-right 1
  96.     }
  97.     if [expr $delta < -0.25] {
  98.         set global player-turnmul [expr - $delta]
  99.         set global go-turn-left 1
  100.     }
  101. }
  102.  
  103. func joy-look {delta} {
  104.     set delta [expr $delta / 2400.0]
  105.     if [expr $delta > 3 || $delta < -3] {
  106.         set global player-look-delta $delta
  107.     } {
  108.         set global player-look-delta 0
  109.     }
  110. }
  111.  
  112. func joy-move {delta} {
  113.     set delta [expr $delta / 30000.0]
  114.     set global go-forward 0
  115.     set global go-backward 0
  116.     set global player-moveymul 1
  117.     set global player-look-forward 0
  118.     if [expr $delta > 0.25] {
  119.         set global player-moveymul $delta
  120.         set global go-backward 1
  121.     }
  122.     if [expr $delta < -0.25] {
  123.         set global player-moveymul [expr - $delta]
  124.         set global go-forward 1
  125.         if [expr $player-moveymul > 0.8] {
  126.             set global player-look-forward 1
  127.         }
  128.     }
  129. }
  130.  
  131. func joy-strafe {delta} {
  132.     set delta [expr $delta / 30000.0]
  133.     set global go-strafe-left 0
  134.     set global go-strafe-right 0
  135.     set global player-movexmul 1
  136.     if [expr $delta > 0.25] {
  137.         set global player-movexmul $delta
  138.         set global go-strafe-right 1
  139.     }
  140.     if [expr $delta < -0.25] {
  141.         set global player-movexmul [expr - $delta]
  142.         set global go-strafe-left 1
  143.     }
  144. }
  145.  
  146. updater player-updater {
  147.     local doemx emx emz
  148.     if $go-forward {
  149.         set doemx 1
  150.         set emz $player-moveymul
  151.     }
  152.     if $go-backward {
  153.         set doemx 1
  154.         set emz [expr - $player-moveymul]
  155.     }
  156.     if $go-strafe-left {
  157.         set doemx 1
  158.         set emx [expr 0.7 * $player-movexmul]
  159.     }
  160.     if $go-strafe-right {
  161.         set doemx 1
  162.         set emx [expr -0.7 * $player-movexmul]
  163.     }
  164.     if $doemx {
  165.         entity-rotation $player yxz 0 $player-rotation 0
  166.         entity-move $player {$emx 0 $emz} 6
  167.         entity-rotation $player yxz $player-lookrot $player-rotation 0
  168.     }
  169.     if $go-turn-left {
  170.         if [expr $player-rotspeed < 0.15] {
  171.             set global player-rotspeed [expr $player-rotspeed + 0.03 * $player-turnmul]
  172.         }
  173.     }
  174.     if $go-turn-right {
  175.         if [expr $player-rotspeed > -0.15] {
  176.             set global player-rotspeed [expr $player-rotspeed - 0.03 * $player-turnmul]
  177.         }
  178.     }
  179.     if $player-look-delta {
  180.         look $player-look-delta
  181.     }
  182.     if $player-look-forward {
  183.         set global player-lookrot [expr $player-lookrot * 0.9]
  184.     }
  185.     if [expr $player-rotspeed > 0.01 || $player-rotspeed < -0.01] {
  186.         set global player-rotation [expr $player-rotation + $player-rotspeed]
  187.         entity-rotation $player yxz $player-lookrot $player-rotation 0
  188.         set global player-rotspeed [expr $player-rotspeed * 0.65]
  189.     }
  190.     local light
  191.     local stop-light
  192.     set light [eget $player light]
  193.     set stop-light [eget $player stop-light]
  194.     if [streq $light {}] { set light 0 }
  195.     if [streq $stop-light {}] { set stop-light 0 }
  196.     if [expr $light && !$stop-light] {
  197.         dlight-to-entity $light $player {0 8 6} {0 -0.5 1}
  198.     }
  199. }
clone this paste RAW Paste Data