Added actions_on_button_press

This commit is contained in:
Resxt 2022-02-25 22:50:37 +01:00
parent 17c0a362d7
commit 2b84548292
2 changed files with 134 additions and 0 deletions

View File

@ -0,0 +1,34 @@
# Actions On Button Press
This script shows how you can execute functions and change dvars for a player when that player presses a certain button while showing him instructions on his screen using the key defined in his game.
If you use `+melee` and the player's melee key is set to V it'll show V on his screen, if he uses another key it'll show his key.
* The first button lets the player toggle the `camera_thirdPerson` dvar (used to play in third person while keeping the crosshair on and is also better/more configurable than `cg_thirdPerson` in my opinion)
Note that `camera_thirdPerson` is a special case and needs to be changed with `SetDynamicDvar()` but in most cases like with `cg_thirdPerson` you'd use `SetDvar()` instead.
* The second button lets the player suicide using the `Suicide()` function.
If you want to use another button simply change `level.third_person_button` and/or `level.suicide_button` values and it will update the button pressed to start the function and the text displayed on the player's screen.
I used actionslot 6 and 7 because (to my knowledge) they are not used by anything else in the game
Here is a non-exhaustive list of buttons you can use
```
"+usereload"
"weapnext"
"+gostand"
"+melee"
"+actionslot 1"
"+actionslot 2"
"+actionslot 3"
"+actionslot 4"
"+actionslot 5"
"+actionslot 6"
"+actionslot 7"
"+frag"
"+smoke"
"+attack"
"+speed_throw"
"+stance"
"+breathe_sprint"
```

View File

@ -0,0 +1,100 @@
#include maps\mp\gametypes\_hud_util;
Init()
{
level.third_person_button = "+actionslot 6";
level.suicide_button = "+actionslot 7";
DisplayButtonsText();
level thread OnPlayerConnect();
}
OnPlayerConnect()
{
for(;;)
{
level waittill("connected", player);
player thread OnSuicideButtonPressed(level.suicide_button);
player thread OnCameraToggleButtonPressed(level.third_person_button);
player thread OnPlayerSpawn(player);
}
}
OnPlayerSpawn(player)
{
self endon("disconnect");
for(;;)
{
self waittill("spawned_player");
wait 1;
player DisableDof();
}
}
OnCameraToggleButtonPressed(button)
{
self endon("disconnect");
level endon("game_ended");
self notifyOnPlayerCommand("third_person_button", button);
while(1)
{
self waittill("third_person_button");
//self setDepthOfField( 0, 0, 512, 512, 4, 0 );
if (GetDvar("camera_thirdPerson") == "0")
{
SetDynamicDvar( "camera_thirdPerson", 1);
}
else if (GetDvar("camera_thirdPerson") == "1")
{
SetDynamicDvar( "camera_thirdPerson", 0);
}
}
}
OnSuicideButtonPressed(button)
{
self endon("disconnect");
level endon("game_ended");
self notifyOnPlayerCommand("suicide_button", button);
while(1)
{
self waittill("suicide_button");
self Suicide();
}
}
DisplayButtonsText()
{
suicide_text = level createServerFontString( "Objective", 0.65 );
suicide_text setPoint( "RIGHT", "RIGHT", -4, -227.5 );
suicide_text setText("^1Press [{" + level.suicide_button + "}] to suicide");
third_person_text = level createServerFontString( "Objective", 0.65 );
third_person_text setPoint( "RIGHT", "RIGHT", -4, -220 );
third_person_text setText("^1Press [{" + level.third_person_button + "}] to toggle the camera");
}
EnableDof()
{
self setDepthOfField( 0, 110, 512, 4096, 6, 1.8 );
}
DisableDof()
{
self setDepthOfField( 0, 0, 512, 512, 4, 0 );
}
Debug(text)
{
print(text);
}