Set Global Variable(keyboardKeys, Array(Custom String("1234567890-=←qwertyuiop[]!asdfghjkl;'┘zxcvbnm,.? ", Null, Null, Null)));
}
}
rule ("Initialize player variables") {
event {
Ongoing - Each Player;
All;
All;
}
actions {
Set Player Variable(Event Player, keyboardPosition, Empty Array);
Set Player Variable(Event Player, keyboardPositions, Empty Array);
Set Player Variable(Event Player, keyboardEnabled, False);
Set Player Variable(Event Player, keyboardInput, Custom String("", Null, Null, Null));
Set Player Variable(Event Player, keyboardKey, Custom String("", Null, Null, Null));
Set Player Variable(Event Player, keyboardEntities, Empty Array);
Set Player Variable(Event Player, keyboardPosition, Empty Array);
}
}
rule ("Subroutine createKeyboard") {
event {
Subroutine;
createKeyboard;
}
actions {
"Align keybaord positions to the front of the player"
Set Player Variable(Event Player, keyboardPosition, Mapped Array(Global.keyboardPosition, First Of(World Vector Of(Current Array Element, Event Player, Rotation))));
"Create keyboard input"
Create In-World Text(All Players(All Teams), (Event Player).keyboardInput, Evaluate Once(World Vector Of(Add(Local Vector Of(Eye Position(Event Player), Event Player, Rotation And Translation), Vector(0, 0.45, 1)), Event Player, Rotation And Translation)), 30, Do Not Clip, Visible To Position and String, Color(White), Default Visibility);
Modify Player Variable(Event Player, keyboardEntities, Append To Array, Last Text ID);
"Create keyboard layout"
Create In-World Text(All Players(All Teams), Custom String("1234567890-=←\nQWERTYUIOP[ ]!\n ASDFGHJKL;' ┘\n ZXCVBNM,.? \n [__]", Null, Null, Null), Evaluate Once(World Vector Of(Add(Local Vector Of(Eye Position(Event Player), Event Player, Rotation And Translation), Vector(0, 0, 1)), Event Player, Rotation And Translation)), 30, Do Not Clip, Visible To Position and String, Color(White), Default Visibility);
Modify Player Variable(Event Player, keyboardEntities, Append To Array, Last Text ID);
Set Player Variable(Event Player, keyboardPositions, Mapped Array(Global.keyboardPositions, First Of(World Vector Of(Current Array Element, Event Player, Rotation))));
"Set keyboard position"
Set Player Variable At Index(Event Player, keyboardPosition, 0, Evaluate Once(World Vector Of(Add(Local Vector Of(Eye Position(Event Player), Event Player, Rotation And Translation), Vector(0, 0.45, 1)), Event Player, Rotation And Translation)));
Set Player Variable At Index(Event Player, keyboardPosition, 1, Evaluate Once(World Vector Of(Add(Local Vector Of(Eye Position(Event Player), Event Player, Rotation And Translation), Vector(0, 0, 1)), Event Player, Rotation And Translation)));
}
}
rule ("Subroutine destroyKeyboard") {
event {
Subroutine;
destroyKeyboard;
}
actions {
"Destroy every in world text"
For Player Variable(Event Player, keyboardIndex, 0, Count Of((Event Player).keyboardEntities), 1);
Destroy In-World Text(Value In Array((Event Player).keyboardEntities, (Event Player).keyboardIndex));
End;
Set Player Variable(Event Player, keyboardPosition, Empty Array);
Set Player Variable(Event Player, keyboardPositions, Empty Array);
Set Player Variable(Event Player, keyboardInput, Custom String("", Null, Null, Null));
Set Player Variable(Event Player, keyboardEntities, Empty Array);
Set Player Variable(Event Player, keyboardPosition, Null);
}
}
rule ("Render Keyboard") {
event {
Ongoing - Global;
}
actions {
"Create keyboard input"
Create In-World Text(If-Then-Else((Local Player).keyboardPosition, Local Player, Null), (Local Player).keyboardInput, First Of((Local Player).keyboardPosition), 30, Do Not Clip, Visible To Position and String, Color(White), Default Visibility);
"Create keyboard layout"
Create In-World Text(If-Then-Else((Local Player).keyboardPosition, Local Player, Null), Custom String("1234567890-=←\nQWERTYUIOP[ ]!\n ASDFGHJKL;' ┘\n ZXCVBNM,.? \n [__]", Null, Null, Null), Value In Array((Local Player).keyboardPosition, 1), 30, Do Not Clip, Visible To Position and String, Color(White), Default Visibility);
}
}
rule ("Hud") {
event {
Ongoing - Each Player;
All;
All;
}
actions {
"Instruction hud"
Create HUD Text(Event Player, Custom String("Press {0} to toggle keyboard", Input Binding String(Button(Interact)), Null, Null), Null, Null, Top, 1, Color(Turquoise), Null, Null, Visible To Sort Order and String, Default Visibility);
}
}
rule ("Toggle Keyboard") {
event {
Ongoing - Each Player;
All;
All;
}
conditions {
Is Button Held(Event Player, Button(Interact)) == True;
}
actions {
"Toggle variable"
Set Player Variable(Event Player, keyboardEnabled, Not((Event Player).keyboardEnabled));
"Run behavior"
If(True);
Skip(Value In Array(Array(4, 0), Add(1, Index Of Array Value(Array(True), (Event Player).keyboardEnabled))));
//__label_switch_2_0__:
Set Status(Event Player, Null, Rooted, 9999);
Set Primary Fire Enabled(Event Player, False);
Call Subroutine(createKeyboard);
Else;
//__label_switch_2_default__:
Call Subroutine(destroyKeyboard);
Clear Status(Event Player, Rooted);
Set Primary Fire Enabled(Event Player, True);
Else;
End;
}
}
rule ("Detect Input") {
event {
Ongoing - Each Player;
All;
All;
}
conditions {
Is Button Held(Event Player, Button(Primary Fire)) == True;
}
actions {
"Check if the player is aiming toward a key"
If(Is True For Any((Event Player).keyboardPosition, Compare(Distance Between(Add(Eye Position(Event Player), Facing Direction Of(Event Player)), Add(Eye Position(Event Player), Current Array Element)), <=, 0.05)));
If(Is True For Any((Event Player).keyboardPositions, Compare(Distance Between(Add(Eye Position(Event Player), Facing Direction Of(Event Player)), Add(Eye Position(Event Player), Current Array Element)), <=, 0.05)));
"Get the key the player is aiming at"
Set Player Variable(Event Player, keyboardKey, String Slice(Global.keyboardKeys, Index Of Array Value((Event Player).keyboardPosition, Filtered Array((Event Player).keyboardPosition, Compare(Distance Between(Add(Eye Position(Event Player), Facing Direction Of(Event Player)), Add(Eye Position(Event Player), Current Array Element)), <=, 0.05))), 1));
Set Player Variable(Event Player, keyboardKey, String Slice(Global.keyboardKeys, Index Of Array Value((Event Player).keyboardPositions, Filtered Array((Event Player).keyboardPositions, Compare(Distance Between(Add(Eye Position(Event Player), Facing Direction Of(Event Player)), Add(Eye Position(Event Player), Current Array Element)), <=, 0.05))), 1));
If(True);
Skip(Value In Array(Array(6, 0, 4), Add(1, Index Of Array Value(Array(Custom String("┘", Null, Null, Null), Custom String("←", Null, Null, Null)), (Event Player).keyboardKey))));