Name | Type | is_array | initial_value |
AI_No | button | No | |
AI_Slender_Spawn | location | No | |
AI_Yes | button | No | |
Alex | unit | No | |
Angle | real | Yes | |
AnimationSpeed | real | Yes | |
AutoWalk | boolean | Yes | |
Birds_Eye | button | No | |
Cast_Spell | integer | No | |
Chase | unit | No | |
DialogMenu | dialog | No | |
DiaolgButton_Players | button | Yes | |
DiaolgButton_Slender | button | Yes | |
First_Person | button | No | |
Flare_Dummy | unit | No | |
Flare_Point | location | No | |
Four_Player | button | No | |
Four_Spawn | location | No | |
Hanna | unit | No | |
Heigth | real | No | |
Hikers | group | Yes | |
Human_Slender_Spawn | location | No | |
IsRunning | boolean | Yes | |
Left | boolean | Yes | |
LeftTrue | boolean | Yes | |
Location | location | Yes | |
Move | integer | No | |
No | button | No | |
No_Fog_Rain | button | No | |
Note_1 | location | No | |
Note_2 | location | No | |
Note_3 | location | No | |
Note_4 | location | No | |
Note_5 | location | No | |
Note_6 | location | No | |
Note_Status | multiboard | No | |
Notes_Found | integer | No | |
Number_Of_Humans | integer | No | |
One_Player | button | No | |
One_Spawn | location | No | |
p | location | No | |
Ping_Pos | location | No | |
PlayersHero | unit | Yes | |
Playerss | player | Yes | |
Rain | button | No | |
Random_Human | integer | No | |
Random_Note_Spawn | integer | No | |
Random_Piano_Number | integer | No | |
Rect | rect | No | |
Right | boolean | Yes | |
RightTrue | boolean | Yes | |
Skip_No | button | No | |
Skip_Yes | button | No | |
Slender | unit | No | |
Speed | real | Yes | |
TempPoint | location | Yes | |
Three_Player | button | No | |
Three_Spawn | location | No | |
total | integer | No | |
Two_Player | button | No | |
Two_Spawn | location | No | |
u | unit | No | |
u2 | unit | No | |
u3 | unit | No | |
u4 | unit | No | |
Unit | unit | Yes | |
units | unit | Yes | |
Up | boolean | Yes | |
UpTrue | boolean | Yes | |
Yes | button | No | |
Zoe | unit | No |
//TESH.scrollpos=0
//TESH.alwaysfold=0
library KeyboardSystem initializer Init
// Keyboard System by The_Witcher
// This System helps you to get rid of all the triggers
// you would need for creating an effective arrow key
// system.
// This system has aditionally the power to add a key twice press event to a trigger
// you just need to adjust this little variable:
globals
// this is the time the player has to "double press" a key
// if a key is pressed twice in this time the registered triggers are executed
private constant real DELAY = 0.2
endglobals
// Use this function to see which keys are hold down:
//
// IsKeyDown( key, pl) returns boolean
// string player
//
// key can be KEY_LEFT, KEY_RIGHT, KEY_UP or KEY_DOWN
// pl is the player who is checked
// if the function returns true the key is hold down by player pl
//
// And this 2 functions to register a double press event to a trigger
//
// TriggerRegisterKeyDoublePressEvent(t, key)
//
// TriggerRegisterPlayerKeyDoublePressEvent(t, key, pl)
//
// TriggerRegisterKeyDoubleInterruptEvent(t, key)
//
// TriggerRegisterPlayerKeyDoubleInterruptEvent(t, key, pl)
//
// t is the trigger you want to register that event to
// key is the pressed key (again can be KEY_LEFT, KEY_RIGHT, KEY_UP or KEY_DOWN)
// pl is in the second function the player who has to press
// the keys to fire the trigger
// the first function fires the trigger regardless of which player pressed the key
//
//
//--------------Don't edit anything below---------------------------
globals
private timer array time[13]
private trigger array TRIGGERS
private trigger array TRIGGERS2
private integer total = 0
private integer total2 = 0
private integer array PLAYER
private integer array PLAYER2
private string array KEY
private string array KEY2
constant string KEY_LEFT = "left"
constant string KEY_RIGHT = "right"
constant string KEY_UP = "up"
constant string KEY_DOWN = "down"
private hashtable h = InitHashtable()
endglobals
function IsKeyDown takes string key, player pl returns boolean
return LoadBoolean(h,GetPlayerId(pl),StringHash(key))
endfunction
function TriggerRegisterKeyDoublePressEvent takes trigger t, string key returns nothing
set TRIGGERS[total] = t
set KEY[total] = key
set PLAYER[total] = 100
set total = total + 1
endfunction
function TriggerRegisterPlayerKeyDoublePressEvent takes trigger t, string key, player pl returns nothing
set TRIGGERS[total] = t
set KEY[total] = key
set PLAYER[total] = GetPlayerId(pl)
set total = total + 1
endfunction
function TriggerRegisterKeyDoubleInterruptEvent takes trigger t, string key returns nothing
set TRIGGERS2[total2] = t
set KEY2[total2] = key
set PLAYER2[total2] = 100
set total2 = total2 + 1
endfunction
function TriggerRegisterPlayerKeyDoubleInterruptEvent takes trigger t, string key, player pl returns nothing
set TRIGGERS2[total2] = t
set KEY2[total2] = key
set PLAYER2[total2] = GetPlayerId(pl)
set total2 = total2 + 1
endfunction
//! textmacro TriggerActions takes NAME, VarTrue, VarFalse
private function $NAME$press takes nothing returns nothing
local integer i = GetPlayerId(GetTriggerPlayer())
local integer x = 0
call SaveBoolean(h,i,StringHash("$VarTrue$"),true)
call SaveBoolean(h,i,StringHash("$VarFalse$"),false)
if LoadStr(h,i,StringHash("LastKey")) != "$VarTrue$" then
call TimerStart(time[i],0,false,null)
endif
if TimerGetRemaining(time[i]) > 0 and LoadStr(h,i,StringHash("LastKey")) == "$VarTrue$" then
call SaveInteger(h,i,StringHash("Debug"),0)
call SaveBoolean(h,i,StringHash("$VarTrue$Double"),true)
loop
exitwhen x >= total
if TriggerEvaluate(TRIGGERS[x]) and KEY[x] == "$VarTrue$" and (PLAYER[x] == 100 or PLAYER[x] == i) then
call TriggerExecute(TRIGGERS[x])
endif
set x = x + 1
endloop
endif
if LoadInteger(h,i,StringHash("Debug")) == 1 then
call TimerStart(time[i],DELAY,false,null)
else
call SaveInteger(h,i,StringHash("Debug"),1)
endif
call SaveStr(h,i,StringHash("LastKey"),"$VarTrue$")
endfunction
private function $NAME$release takes nothing returns nothing
local integer i = GetPlayerId(GetTriggerPlayer())
local integer x = 0
call SaveBoolean(h,i,StringHash("$VarTrue$"),false)
if LoadBoolean(h,i,StringHash("$VarTrue$Double")) then
call SaveBoolean(h,i,StringHash("$VarTrue$Double"),false)
loop
exitwhen x >= total2
if TriggerEvaluate(TRIGGERS2[x]) and KEY2[x] == "$VarTrue$" and (PLAYER2[x] == 100 or PLAYER2[x] == i) then
call TriggerExecute(TRIGGERS2[x])
endif
set x = x + 1
endloop
endif
endfunction
//! endtextmacro
//! runtextmacro TriggerActions("LEFT","left","right")
//! runtextmacro TriggerActions("RIGHT","right","left")
//! runtextmacro TriggerActions("UP","up","down")
//! runtextmacro TriggerActions("DOWN","down","up")
//! textmacro Initiate takes NAME
set i = 0
set t = CreateTrigger()
set tt = CreateTrigger()
call TriggerAddAction(t,function $NAME$press)
call TriggerAddAction(tt,function $NAME$release)
loop
exitwhen i > 12
call TriggerRegisterPlayerEvent(t,Player(i),EVENT_PLAYER_ARROW_$NAME$_DOWN)
call TriggerRegisterPlayerEvent(tt,Player(i),EVENT_PLAYER_ARROW_$NAME$_UP)
set i = i + 1
endloop
//! endtextmacro
private function Init takes nothing returns nothing
local trigger t
local trigger tt
local integer i
//! runtextmacro Initiate("LEFT")
//! runtextmacro Initiate("RIGHT")
//! runtextmacro Initiate("UP")
//! runtextmacro Initiate("DOWN")
set i = 0
loop
exitwhen i > 12
set time[i] = CreateTimer()
set i = i + 1
endloop
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library ArrowKeyMovement initializer Init requires KeyboardSystem, ArrowKeyMovementPlugins
// Arrow key movement by The_Witcher
// this system allows each player to control 1 unit
// with his arrow keys even if he doesn't own the unit!
// It features turning on the left and right arrow, walking foreward
// by pressing the up arrow and walking backwards by pressing the down arrow...
//
// You can improve this system with plugins but you need vJass knowledge for that!
//
// --> The TurnRate of a unit inside the object editor STILL influences the turn rate from this system <--
//
// Included functions:
//
// SetMovementUnit ( whichunit, forWhichPlayer, walkAnimationIndex )
// unit player integer
// this gives the player the arrow key movement control over the unit
// while the unit moves the animation of the given index is played
// (just try around to find the index... start at 0 and increase
// by 1 until you find the walk index of that unit)
//
//
// ReleaseMovementUnit ( fromWhichPlayer )
// player
// this function removes the control from a player
//
//
// GetMovementUnit ( fromWhichPlayer ) returns unit
// player
// I think its self explaining...
//
//
// SetMovementUnitAnimation ( fromWhichPlayer, animation )
// player integer
// this function allows ingame changing of the played animation of a unit
// ------- SETUP PART ---------
globals
// the timer interval... increase if laggy
private constant real INTERVAL = 0.02
// the facing change in degrees each interval (must be a positive value)
private constant real DEFAULT_VIEW_CHANGE = 4
// when you move backwards you move slower than normal...
private constant real BACKWARDS_MOVING_FACTOR = 0.7
// if the unit turns it will turn faster the longer it does...
// some people may need that but then it should be 1.02 (1.0 means disabled)
private constant real TURN_ACCELERATION = 1
// (can only be 1 or -1) if you walk backwards you have 2 ways of turning
// 1. way: pressing left will make the char turn left
// 2. way: pressing left will make the char turn so he moves to the left
private constant integer REVERSED_BACKWARDS_MOVING = -1
endglobals
// whenever this function returns false for a unit it won't be moved even if the player
// presses the keys! change to create your own "No Movement" conditions
private function MoveConditions takes unit u returns boolean
return not IsUnitType(u,UNIT_TYPE_SLEEPING) and not IsUnitType(u,UNIT_TYPE_STUNNED) and not (IsUnitType(u,UNIT_TYPE_DEAD) or GetUnitTypeId(u) == 0 )
endfunction
// --------- don't modify anything below this line ------------
struct ArrowKeyMovement
private static ArrowKeyMovement array all [12] // = bj_MAX_PLAYERS
private static timer tim
integer walking
unit u
integer animation
real SpeedFactor
real SpecialDirection
real ViewChange
boolean SpecialDirectionActive
static method operator [] takes player p returns ArrowKeyMovement
local integer i = GetPlayerId(p)
if .all[i] == 0 then
set .all[i] = ArrowKeyMovement.create()
set .all[i].SpeedFactor = 1
set .all[i].SpecialDirection = 0
set .all[i].SpecialDirectionActive = false
set .all[i].ViewChange = DEFAULT_VIEW_CHANGE
endif
return .all[i]
endmethod
private static method Walking takes nothing returns nothing
local integer i = 0
local real x
local real y
local real X
local real Y
local boolean boolX
local boolean boolY
local boolean left
local boolean right
local boolean up
local boolean down
local ArrowKeyMovement mov
loop
exitwhen i >= 12 // = bj_MAX_PLAYERS
set mov = .all[i]
if mov.u != null and MoveConditions(mov.u) then
// special movement <-- plugins
if mov.SpecialDirectionActive then
if mov.walking != 1 then
call SetUnitTimeScale(mov.u,mov.SpeedFactor)
call SetUnitAnimationByIndex(mov.u,mov.animation)
set mov.walking = 1
else
call SetUnitTimeScale(mov.u,mov.SpeedFactor)
endif
set x = GetUnitX(mov.u)
set y = GetUnitY(mov.u)
set X = x + GetUnitMoveSpeed(mov.u)*INTERVAL * Cos(mov.SpecialDirection*bj_DEGTORAD) * mov.SpeedFactor
set Y = y + GetUnitMoveSpeed(mov.u)*INTERVAL * Sin(mov.SpecialDirection*bj_DEGTORAD) * mov.SpeedFactor
call SetUnitPosition(mov.u,X,Y)
if (RAbsBJ(GetUnitX(mov.u)-X)>0.5)or(RAbsBJ(GetUnitY(mov.u)-Y)>0.5)then
call SetUnitPosition(mov.u,X,y)
set boolX = RAbsBJ(GetUnitX(mov.u)-X)<=0.5
call SetUnitPosition(mov.u,x,Y)
set boolY = RAbsBJ(GetUnitY(mov.u)-Y)<=0.5
if boolX then
call SetUnitPosition(mov.u,X,y)
elseif boolY then
call SetUnitPosition(mov.u,x,Y)
else
call SetUnitPosition(mov.u,x,y)
endif
endif
else
// Normal movement
set left = IsKeyDown(KEY_LEFT,Player(i))
set right = IsKeyDown(KEY_RIGHT,Player(i))
set up = IsKeyDown(KEY_UP,Player(i))
set down = IsKeyDown(KEY_DOWN,Player(i))
//right down
if right then
if down then
call SetUnitFacing(mov.u,GetUnitFacing(mov.u)-mov.ViewChange * -REVERSED_BACKWARDS_MOVING)
else
call SetUnitFacing(mov.u,GetUnitFacing(mov.u)-mov.ViewChange)
endif
set mov.ViewChange = mov.ViewChange * TURN_ACCELERATION
elseif not left then
set mov.ViewChange = DEFAULT_VIEW_CHANGE
endif
//left down
if left then
if down then
call SetUnitFacing(mov.u,GetUnitFacing(mov.u)+mov.ViewChange * -REVERSED_BACKWARDS_MOVING)
else
call SetUnitFacing(mov.u,GetUnitFacing(mov.u)+mov.ViewChange)
endif
set mov.ViewChange = mov.ViewChange * TURN_ACCELERATION
elseif not right then
set mov.ViewChange = DEFAULT_VIEW_CHANGE
endif
if mov.ViewChange > 179 then
set mov.ViewChange = 179
endif
//up down
if up then
if mov.walking != 1 then
call SetUnitTimeScale(mov.u,mov.SpeedFactor)
call SetUnitAnimationByIndex(mov.u,mov.animation)
set mov.walking = 1
else
call SetUnitTimeScale(mov.u,mov.SpeedFactor)
endif
set x = GetUnitX(mov.u)
set y = GetUnitY(mov.u)
set X = x + GetUnitMoveSpeed(mov.u)*INTERVAL * Cos(GetUnitFacing(mov.u)*bj_DEGTORAD) * mov.SpeedFactor
set Y = y + GetUnitMoveSpeed(mov.u)*INTERVAL * Sin(GetUnitFacing(mov.u)*bj_DEGTORAD) * mov.SpeedFactor
//down down
elseif down then
if mov.walking != 2 then
call SetUnitTimeScale(mov.u,-BACKWARDS_MOVING_FACTOR * mov.SpeedFactor)
call SetUnitAnimationByIndex(mov.u,mov.animation)
set mov.walking = 2
else
call SetUnitTimeScale(mov.u,-BACKWARDS_MOVING_FACTOR * mov.SpeedFactor)
endif
set x = GetUnitX(mov.u)
set y = GetUnitY(mov.u)
set X = x - GetUnitMoveSpeed(mov.u) * INTERVAL * Cos(GetUnitFacing(mov.u)*bj_DEGTORAD) * BACKWARDS_MOVING_FACTOR * mov.SpeedFactor
set Y = y - GetUnitMoveSpeed(mov.u) * INTERVAL * Sin(GetUnitFacing(mov.u)*bj_DEGTORAD) * BACKWARDS_MOVING_FACTOR * mov.SpeedFactor
endif
//move
if down or up then
call SetUnitPosition(mov.u,X,Y)
if (RAbsBJ(GetUnitX(mov.u)-X)>0.5)or(RAbsBJ(GetUnitY(mov.u)-Y)>0.5)then
call SetUnitPosition(mov.u,X,y)
set boolX = RAbsBJ(GetUnitX(mov.u)-X)<=0.5
call SetUnitPosition(mov.u,x,Y)
set boolY = RAbsBJ(GetUnitY(mov.u)-Y)<=0.5
if boolX then
call SetUnitPosition(mov.u,X,y)
elseif boolY then
call SetUnitPosition(mov.u,x,Y)
else
call SetUnitPosition(mov.u,x,y)
endif
endif
else
if mov.walking != 0 then
call SetUnitAnimation(mov.u,"stand")
call SetUnitTimeScale(mov.u,1)
set mov.walking = 0
endif
endif
endif
endif
set i = i + 1
endloop
endmethod
static method onInit takes nothing returns nothing
set .tim = CreateTimer()
call TimerStart(.tim,INTERVAL,true,function ArrowKeyMovement.Walking)
endmethod
endstruct
function GetMovementUnit takes player p returns unit
return ArrowKeyMovement[p].u
endfunction
function SetMovementUnitAnimation takes player p, integer animation returns nothing
set ArrowKeyMovement[p].animation = animation
endfunction
function ReleaseMovementUnit takes player p returns nothing
if ArrowKeyMovement[p].u != null then
set ArrowKeyMovement[p].walking = 0
call SetUnitAnimation(ArrowKeyMovement[p].u,"stand")
call SetUnitTimeScale(ArrowKeyMovement[p].u,1)
set ArrowKeyMovement[p].u = null
endif
endfunction
function SetMovementUnit takes unit u, player p, integer anim returns nothing
if u == null then
call ReleaseMovementUnit(p)
return
endif
if ArrowKeyMovement[p].u != null then
call ReleaseMovementUnit(p)
endif
call SetUnitAnimation(ArrowKeyMovement[p].u,"stand")
set ArrowKeyMovement[p].u = u
set ArrowKeyMovement[p].animation = anim
endfunction
//! runtextmacro ArrowKeyMovement_Plugins_Functions()
private function Init takes nothing returns nothing
//! runtextmacro Init_ArrowKeyMovement_Plugins()
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library ArrowKeyMovementPlugins
// code your own plugins for my Arrow key movement system!
// how you do that is explained in detail in the "How to use the Movement System Plugins"
// comment included in this map
//
//
// the plugins I coded for the test map are:
// 1. running fast/dashing when double pressing up
// 2. turning around (180°) when double pressing down
// 3. moving left without changing face direction when double pressing left
// 4. moving right without changing face direction when double pressing right
//! textmacro Init_ArrowKeyMovement_Plugins
local trigger t
// This is the initialization for turning around on double down press
set t = CreateTrigger()
call TriggerAddAction(t, function OnDoubleDownPress)
call TriggerRegisterKeyDoublePressEvent(t,KEY_DOWN)
// This is the initialization for dashing on double up press
set t = CreateTrigger()
call TriggerAddAction(t, function OnDoubleUpPress)
call TriggerRegisterKeyDoublePressEvent(t,KEY_UP)
// This is the initialization for sliding left on double left press
set t = CreateTrigger()
call TriggerAddAction(t, function OnDoubleLeftPress)
call TriggerRegisterKeyDoublePressEvent(t,KEY_LEFT)
// This is the initialization for sliding right on double right press
set t = CreateTrigger()
call TriggerAddAction(t, function OnDoubleRightPress)
call TriggerRegisterKeyDoublePressEvent(t,KEY_RIGHT)
// This is the initialization for stoping the dash of double up press
set t = CreateTrigger()
call TriggerAddAction(t, function OnDoubleUpRelease)
call TriggerRegisterKeyDoubleInterruptEvent(t,KEY_UP)
// This is the initialization for stoping slide of double left press
set t = CreateTrigger()
call TriggerAddAction(t, function OnDoubleLeftRelease)
call TriggerRegisterKeyDoubleInterruptEvent(t,KEY_LEFT)
// This is the initialization for stoping slide of double right press
set t = CreateTrigger()
call TriggerAddAction(t, function OnDoubleRightRelease)
call TriggerRegisterKeyDoubleInterruptEvent(t,KEY_RIGHT)
//! endtextmacro
//! textmacro ArrowKeyMovement_Plugins_Functions
// This is the function for turning around on double down press
private function OnDoubleDownPress takes nothing returns nothing
local ArrowKeyMovement mov = ArrowKeyMovement[GetTriggerPlayer()]
set mov.SpecialDirectionActive = false
call SetUnitFacing(mov.u,GetUnitFacing(mov.u)-180)
endfunction
// This is the function for dashing on double up press
private function OnDoubleUpPress takes nothing returns nothing
local ArrowKeyMovement mov = ArrowKeyMovement[GetTriggerPlayer()]
set mov.SpecialDirectionActive = false
set mov.SpeedFactor = 2
endfunction
// This is the function for sliding left on double left press
private function OnDoubleLeftPress takes nothing returns nothing
local ArrowKeyMovement mov = ArrowKeyMovement[GetTriggerPlayer()]
set mov.SpecialDirectionActive = true
set mov.SpecialDirection = GetUnitFacing(mov.u) + 90
set mov.SpeedFactor = 0.6
endfunction
// This is the function for sliding right on double right press
private function OnDoubleRightPress takes nothing returns nothing
local ArrowKeyMovement mov = ArrowKeyMovement[GetTriggerPlayer()]
set mov.SpecialDirectionActive = true
set mov.SpecialDirection = GetUnitFacing(mov.u) - 90
set mov.SpeedFactor = 0.6
endfunction
// This is the function for stoping the dash of double up press
private function OnDoubleUpRelease takes nothing returns nothing
set ArrowKeyMovement[GetTriggerPlayer()].SpeedFactor = 1
endfunction
// This is the function for stoping slide of double left press
private function OnDoubleLeftRelease takes nothing returns nothing
local ArrowKeyMovement mov = ArrowKeyMovement[GetTriggerPlayer()]
set mov.SpecialDirectionActive = false
set mov.SpeedFactor = 1
endfunction
// This is the function for stoping slide of double right press
private function OnDoubleRightRelease takes nothing returns nothing
local ArrowKeyMovement mov = ArrowKeyMovement[GetTriggerPlayer()]
set mov.SpecialDirectionActive = false
set mov.SpeedFactor = 1
endfunction
//! endtextmacro
endlibrary