mirror of
https://github.com/Resxt/Plutonium-IW5-Scripts.git
synced 2025-04-19 20:52:54 +00:00
actions_on_button_press 1.1
- Splitted the old script into 2 different scripts - Fixed camera_thirdPerson changing for all players when a player presses the button by turning it into a vote instead
This commit is contained in:
parent
db886926ad
commit
f5c649124e
@ -1,16 +1,10 @@
|
||||
# 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.
|
||||
These scripts allow players on the server to press a button (displayed on screen) to trigger a function
|
||||
Note that if you combine several scripts you will have to change the texts positions so that they don't overlap by changing the last value in `setPoint()`
|
||||
You can also change the text's position in `setPoint()` and the size and font type in `createServerFontString()`
|
||||
|
||||
* 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 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.
|
||||
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
|
||||
Changing the button in `Init()` will change both the button displayed on screen and the button used to trigger the function.
|
||||
Here is a non-exhaustive list of buttons you can use
|
||||
```
|
||||
"+usereload"
|
||||
@ -31,3 +25,13 @@ Here is a non-exhaustive list of buttons you can use
|
||||
"+stance"
|
||||
"+breathe_sprint"
|
||||
```
|
||||
|
||||
## suicide_on_button_press.gsc
|
||||
|
||||
The player dies when pressing the button
|
||||
|
||||
## camera_switch_vote_on_button_press.gsc
|
||||
|
||||
Allows the players to toggle their vote to change the `camera_thirdPerson` dvar on the server (players vote no by default)
|
||||
When everyone votes yes the server changes the dvar and resets the vote counts.
|
||||
Bots are ignored for the votes.
|
@ -1,98 +0,0 @@
|
||||
#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");
|
||||
|
||||
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);
|
||||
}
|
148
actions_on_button_press/camera_switch_vote_on_button_press.gsc
Normal file
148
actions_on_button_press/camera_switch_vote_on_button_press.gsc
Normal file
@ -0,0 +1,148 @@
|
||||
#include maps\mp\gametypes\_hud_util;
|
||||
|
||||
Init()
|
||||
{
|
||||
level.camera_switch_vote_button = "+actionslot 6";
|
||||
|
||||
DisplayButtonsText();
|
||||
|
||||
level thread DisplayVoteCount();
|
||||
level thread OnPlayerConnected();
|
||||
}
|
||||
|
||||
OnPlayerConnected()
|
||||
{
|
||||
for(;;)
|
||||
{
|
||||
level waittill("connected", player);
|
||||
|
||||
player.pers["camera_switch_vote"] = false;
|
||||
|
||||
player thread OnCameraSwitchVoteButtonPressed(level.camera_switch_vote_button);
|
||||
|
||||
player thread OnPlayerSpawned(player);
|
||||
}
|
||||
}
|
||||
|
||||
OnPlayerSpawned(player)
|
||||
{
|
||||
self endon("disconnect");
|
||||
|
||||
for(;;)
|
||||
{
|
||||
self waittill("spawned_player");
|
||||
|
||||
player DisableDof();
|
||||
}
|
||||
}
|
||||
|
||||
OnCameraSwitchVoteButtonPressed(button)
|
||||
{
|
||||
self endon("disconnect");
|
||||
level endon("game_ended");
|
||||
|
||||
self notifyOnPlayerCommand("camera_switch_vote_button", button);
|
||||
while(1)
|
||||
{
|
||||
self waittill("camera_switch_vote_button");
|
||||
self.pers["camera_switch_vote"] = !self.pers["camera_switch_vote"];
|
||||
if (self.pers["camera_switch_vote"])
|
||||
{
|
||||
CustomPrintLn("You voted to switch the camera");
|
||||
}
|
||||
else
|
||||
{
|
||||
CustomPrintLn("You removed your vote to switch the camera");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DisplayButtonsText()
|
||||
{
|
||||
camera_switch_vote_text = level createServerFontString( "Objective", 0.65 );
|
||||
camera_switch_vote_text setPoint( "RIGHT", "RIGHT", -4, -227.5 );
|
||||
camera_switch_vote_text setText("^1Press [{" + level.camera_switch_vote_button + "}] to toggle vote for camera switch");
|
||||
}
|
||||
|
||||
DisplayVoteCount()
|
||||
{
|
||||
level.camera_switch_vote_count_text = level createServerFontString( "Objective", 0.65 );
|
||||
level.camera_switch_vote_count_text setPoint( "RIGHT", "RIGHT", -4, -220 );
|
||||
|
||||
while(true)
|
||||
{
|
||||
yes_votes = 0;
|
||||
human_players = [];
|
||||
|
||||
foreach (player in level.players)
|
||||
{
|
||||
if (player.pers["camera_switch_vote"])
|
||||
{
|
||||
yes_votes++;
|
||||
}
|
||||
|
||||
if (!isDefined(player.pers["isBot"]))
|
||||
{
|
||||
human_players[human_players.size] = player;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!player.pers["isBot"])
|
||||
{
|
||||
human_players[human_players.size] = player;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
level.camera_switch_vote_count_text setText("^1Votes to switch camera: " + yes_votes + "/" + human_players.size);
|
||||
|
||||
if (yes_votes == human_players.size && human_players.size > 0)
|
||||
{
|
||||
// Logic here
|
||||
setDvar( "camera_thirdPerson", !getDvarInt( "camera_thirdPerson" ) );
|
||||
|
||||
// Mention changes to all players (if there is more than one player)
|
||||
if (human_players.size > 1)
|
||||
{
|
||||
if (getDvarInt( "camera_thirdPerson" ) == 0)
|
||||
{
|
||||
CustomPrintLn("Everyone voted to switch to 1st person");
|
||||
}
|
||||
else
|
||||
{
|
||||
CustomPrintLn("Everyone voted to switch to 3rd person");
|
||||
}
|
||||
}
|
||||
|
||||
// Reset votes variables
|
||||
yes_votes = 0;
|
||||
|
||||
foreach (player in human_players)
|
||||
{
|
||||
player.pers["camera_switch_vote"] = false;
|
||||
}
|
||||
}
|
||||
|
||||
wait 0.01;
|
||||
}
|
||||
}
|
||||
|
||||
EnableDof()
|
||||
{
|
||||
self setDepthOfField( 0, 110, 512, 4096, 6, 1.8 );
|
||||
}
|
||||
|
||||
DisableDof()
|
||||
{
|
||||
self setDepthOfField( 0, 0, 512, 512, 4, 0 );
|
||||
}
|
||||
|
||||
CustomPrintLn(text)
|
||||
{
|
||||
IPrintLn("^1" + text);
|
||||
}
|
||||
|
||||
Debug(text)
|
||||
{
|
||||
print(text);
|
||||
}
|
46
actions_on_button_press/suicide_on_button_press.gsc
Normal file
46
actions_on_button_press/suicide_on_button_press.gsc
Normal file
@ -0,0 +1,46 @@
|
||||
#include maps\mp\gametypes\_hud_util;
|
||||
|
||||
Init()
|
||||
{
|
||||
level.suicide_button = "+actionslot 7";
|
||||
|
||||
DisplayButtonsText();
|
||||
|
||||
level thread OnPlayerConnected();
|
||||
}
|
||||
|
||||
OnPlayerConnected()
|
||||
{
|
||||
for(;;)
|
||||
{
|
||||
level waittill("connected", player);
|
||||
|
||||
player thread OnSuicideButtonPressed(level.suicide_button);
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
Debug(text)
|
||||
{
|
||||
print(text);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user