Skip to content

Commit

Permalink
fix: dices do not return a string but parameters for string replaceme…
Browse files Browse the repository at this point in the history
…nts only
  • Loading branch information
derkalle4 committed Nov 23, 2024
1 parent 67b7e29 commit c44c5cb
Show file tree
Hide file tree
Showing 24 changed files with 188 additions and 87 deletions.
8 changes: 7 additions & 1 deletion src/RollTheDice+Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ public void CommandRollTheDice(CCSPlayerController player, CommandInfo command)
return;
}
// execute dice function
var message = _dices[dice](player, playerPawn);
Dictionary<string, string> data = _dices[dice](player, playerPawn);
// send message
string message = Localizer[data["_translation"]].Value;
foreach (var kvp in data)
{
message = message.Replace($"{{{kvp.Key}}}", kvp.Value);
}
SendGlobalChatMessage(message);
player.ExecuteClientCommand("play sounds/ui/coin_pickup_01.vsnd");
}
Expand Down
11 changes: 7 additions & 4 deletions src/RollTheDice+DiceBigTaserBattery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ public partial class RollTheDice : BasePlugin
{
private Dictionary<CCSPlayerController, int> _playersWithBigTaserBattery = new();

private string DiceBigTaserBattery(CCSPlayerController player, CCSPlayerPawn playerPawn)
private Dictionary<string, string> DiceBigTaserBattery(CCSPlayerController player, CCSPlayerPawn playerPawn)
{
int battery = _random.Next(2, 10);
_playersWithBigTaserBattery.Add(player, battery);
player.GiveNamedItem("weapon_taser");
return Localizer["DiceBigTaserBattery"].Value
.Replace("{playerName}", player.PlayerName)
.Replace("{batterySize}", battery.ToString());
return new Dictionary<string, string>
{
{"_translation", "DiceBigTaserBattery"},
{ "playerName", player.PlayerName },
{ "batterySize", battery.ToString() }
};
}

private void CreateDiceBigTaserBatteryEventHandler()
Expand Down
11 changes: 7 additions & 4 deletions src/RollTheDice+DiceChangeName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public partial class RollTheDice : BasePlugin
private List<CCSPlayerController> _playersWithChangedNames = new();
private Dictionary<CCSPlayerController, string> _playersWithChangedNamesOldNames = new();

private string DiceChangeName(CCSPlayerController player, CCSPlayerPawn playerPawn)
private Dictionary<string, string> DiceChangeName(CCSPlayerController player, CCSPlayerPawn playerPawn)
{
// select random string from list
var names = new List<string>
Expand All @@ -28,9 +28,12 @@ private string DiceChangeName(CCSPlayerController player, CCSPlayerPawn playerPa
_playersWithChangedNames.Add(player);
_playersWithChangedNamesOldNames[player] = player.PlayerName;
player.PlayerName = randomName;
return Localizer["DiceChangeName"].Value
.Replace("{playerName}", _playersWithChangedNamesOldNames[player])
.Replace("{randomName}", randomName);
return new Dictionary<string, string>
{
{"_translation", "DiceBigTaserBattery"},
{ "playerName", _playersWithChangedNamesOldNames[player] },
{ "randomName", randomName }
};
}

private void ResetDiceChangeName()
Expand Down
9 changes: 6 additions & 3 deletions src/RollTheDice+DiceChickenLeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace RollTheDice
{
public partial class RollTheDice : BasePlugin
{
private string DiceChickenLeader(CCSPlayerController player, CCSPlayerPawn playerPawn)
private Dictionary<string, string> DiceChickenLeader(CCSPlayerController player, CCSPlayerPawn playerPawn)
{
var amountChickens = 16;
// spawn chickens
Expand Down Expand Up @@ -44,8 +44,11 @@ private string DiceChickenLeader(CCSPlayerController player, CCSPlayerPawn playe
});
}
}
return Localizer["DiceChickenLeader"].Value
.Replace("{playerName}", player.PlayerName);
return new Dictionary<string, string>
{
{"_translation", "DiceBigTaserBattery"},
{ "playerName", player.PlayerName }
};
}
}
}
11 changes: 7 additions & 4 deletions src/RollTheDice+DiceDecreaseHealth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ namespace RollTheDice
{
public partial class RollTheDice : BasePlugin
{
private string DiceDecreaseHealth(CCSPlayerController player, CCSPlayerPawn playerPawn)
private Dictionary<string, string> DiceDecreaseHealth(CCSPlayerController player, CCSPlayerPawn playerPawn)
{
var healthDecrease = _random.Next(10, 30);
playerPawn.Health -= healthDecrease;
Utilities.SetStateChanged(playerPawn, "CBaseEntity", "m_iHealth");
return Localizer["DiceDecreaseHealth"].Value
.Replace("{playerName}", player.PlayerName)
.Replace("{healthDecrease}", healthDecrease.ToString());
return new Dictionary<string, string>
{
{"_translation", "DiceBigTaserBattery"},
{ "playerName", player.PlayerName },
{ "healthDecrease", healthDecrease.ToString() }
};
}
}
}
24 changes: 16 additions & 8 deletions src/RollTheDice+DiceFastBombAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,33 @@ public partial class RollTheDice : BasePlugin
private List<CCSPlayerController> _playersCanInstantDefuse = new();
private List<CCSPlayerController> _playersCanInstantPlant = new();

private string DiceFastBombAction(CCSPlayerController player, CCSPlayerPawn playerPawn)
private Dictionary<string, string> DiceFastBombAction(CCSPlayerController player, CCSPlayerPawn playerPawn)
{
if (playerPawn.TeamNum == (int)CsTeam.Terrorist)
{
_playersCanInstantPlant.Add(player);
return Localizer["DiceFastBombActionT"].Value
.Replace("{playerName}", player.PlayerName);

return new Dictionary<string, string>
{
{"_translation", "DiceFastBombActionT"},
{ "playerName", player.PlayerName }
};
}
else if (playerPawn.TeamNum == (int)CsTeam.CounterTerrorist)
{
_playersCanInstantDefuse.Add(player);
return Localizer["DiceFastBombActionCT"].Value
.Replace("{playerName}", player.PlayerName);
return new Dictionary<string, string>
{
{"_translation", "DiceFastBombActionCT"},
{ "playerName", player.PlayerName }
};
}
else
{
return Localizer["command.rollthedice.error"].Value
.Replace("{playerName}", player.PlayerName);
return new Dictionary<string, string>
{
{"_translation", "command.rollthedice.error"},
{ "playerName", player.PlayerName }
};
}
}

Expand Down
11 changes: 7 additions & 4 deletions src/RollTheDice+DiceGiveHealthShot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ namespace RollTheDice
{
public partial class RollTheDice : BasePlugin
{
private string DiceGiveHealthShot(CCSPlayerController player, CCSPlayerPawn playerPawn)
private Dictionary<string, string> DiceGiveHealthShot(CCSPlayerController player, CCSPlayerPawn playerPawn)
{
int amount = _random.Next(1, 5);
for (int i = 0; i < amount; i++)
{
player.GiveNamedItem("weapon_healthshot");
}
return Localizer["DiceGiveHealthShot"].Value
.Replace("{playerName}", player.PlayerName)
.Replace("{amount}", amount.ToString());
return new Dictionary<string, string>
{
{"_translation", "DiceGiveHealthShot"},
{ "playerName", player.PlayerName },
{ "amount", amount.ToString() }
};
}
}
}
11 changes: 7 additions & 4 deletions src/RollTheDice+DiceIncreaseHealth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace RollTheDice
{
public partial class RollTheDice : BasePlugin
{
private string DiceIncreaseHealth(CCSPlayerController player, CCSPlayerPawn playerPawn)
private Dictionary<string, string> DiceIncreaseHealth(CCSPlayerController player, CCSPlayerPawn playerPawn)
{
var healthIncrease = _random.Next(10, 30);
if (playerPawn.Health + healthIncrease > playerPawn.MaxHealth)
Expand All @@ -15,9 +15,12 @@ private string DiceIncreaseHealth(CCSPlayerController player, CCSPlayerPawn play
playerPawn.Health += healthIncrease;
Utilities.SetStateChanged(playerPawn, "CBaseEntity", "m_iHealth");
Utilities.SetStateChanged(playerPawn, "CBaseEntity", "m_iMaxHealth");
return Localizer["DiceIncreaseHealth"].Value
.Replace("{playerName}", player.PlayerName)
.Replace("{healthIncrease}", healthIncrease.ToString());
return new Dictionary<string, string>
{
{"_translation", "DiceIncreaseHealth"},
{ "playerName", player.PlayerName },
{ "healthIncrease", healthIncrease.ToString() }
};
}
}
}
11 changes: 7 additions & 4 deletions src/RollTheDice+DiceIncreaseSpeed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ public partial class RollTheDice : BasePlugin
{
private List<CCSPlayerController> _playersWithIncreasedSpeed = new();

private string DiceIncreaseSpeed(CCSPlayerController player, CCSPlayerPawn playerPawn)
private Dictionary<string, string> DiceIncreaseSpeed(CCSPlayerController player, CCSPlayerPawn playerPawn)
{
_playersWithIncreasedSpeed.Add(player);
var speedIncrease = _random.NextDouble() * (2.0 - 1.5) + 1.5;
playerPawn.VelocityModifier *= (float)speedIncrease;
Utilities.SetStateChanged(playerPawn, "CCSPlayerPawn", "m_flVelocityModifier");
var percentageIncrease = (speedIncrease - 1.0) * 100;
return Localizer["DiceIncreaseSpeed"].Value
.Replace("{playerName}", player.PlayerName)
.Replace("{percentageIncrease}", Math.Round(percentageIncrease, 2).ToString());
return new Dictionary<string, string>
{
{"_translation", "DiceIncreaseSpeed"},
{ "playerName", player.PlayerName },
{ "percentageIncrease", Math.Round(percentageIncrease, 2).ToString() }
};
}

private void ResetDiceIncreaseSpeed()
Expand Down
17 changes: 12 additions & 5 deletions src/RollTheDice+DiceNoExplosives.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,22 @@ public partial class RollTheDice : BasePlugin
("models/food/vegetables/zucchini01a.vmdl", 1.0f),
};

private string DiceNoExplosives(CCSPlayerController player, CCSPlayerPawn playerPawn)
private Dictionary<string, string> DiceNoExplosives(CCSPlayerController player, CCSPlayerPawn playerPawn)
{
if (_playersWithoutExplosives.Contains(playerPawn)) return Localizer["DiceNoExplosives"].Value
.Replace("{playerName}", player.PlayerName);
if (_playersWithoutExplosives.Contains(playerPawn))
return new Dictionary<string, string>
{
{"_translation", "DiceNoExplosives"},
{ "playerName", player.PlayerName }
};
// register listener
if (_playersWithoutExplosives.Count == 0) RegisterListener<Listeners.OnEntitySpawned>(DiceNoExplosivesOnEntitySpawned);
_playersWithoutExplosives.Add(playerPawn);
return Localizer["DiceNoExplosives"].Value
.Replace("{playerName}", player.PlayerName);
return new Dictionary<string, string>
{
{"_translation", "DiceNoExplosives"},
{ "playerName", player.PlayerName }
};
}

private void ResetDiceNoExplosives()
Expand Down
16 changes: 12 additions & 4 deletions src/RollTheDice+DicePlayerAsChicken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ public partial class RollTheDice : BasePlugin
"Chicken.Panic",
};

private string DicePlayerAsChicken(CCSPlayerController player, CCSPlayerPawn playerPawn)
private Dictionary<string, string> DicePlayerAsChicken(CCSPlayerController player, CCSPlayerPawn playerPawn)
{
if (_playersAsChicken.ContainsKey(player)) return Localizer["command.rollthedice.error"].Value.Replace("{playerName}", player.PlayerName);
if (_playersAsChicken.ContainsKey(player))
return new Dictionary<string, string>
{
{"_translation", "command.rollthedice.error"},
{ "playerName", player.PlayerName }
};
// create listener if not exists
if (_playersAsChicken.Count() == 0)
{
Expand All @@ -28,8 +33,11 @@ private string DicePlayerAsChicken(CCSPlayerController player, CCSPlayerPawn pla
_playersAsChicken[player]["next_sound"] = $"{(int)Server.CurrentTime + 2}";
_playersAsChicken[player]["prop"] = SpawnProp(player, _playersAsChickenModel, 5.2f).ToString();
MakePlayerInvisible(player);
return Localizer["DicePlayerAsChicken"].Value
.Replace("{playerName}", player.PlayerName);
return new Dictionary<string, string>
{
{"_translation", "DicePlayerAsChicken"},
{ "playerName", player.PlayerName }
};
}

private void ResetDicePlayerAsChicken()
Expand Down
16 changes: 12 additions & 4 deletions src/RollTheDice+DicePlayerCloak.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,26 @@ public partial class RollTheDice : BasePlugin
{
private Dictionary<CCSPlayerController, int> _playersWithCloak = new();

private string DicePlayerCloak(CCSPlayerController player, CCSPlayerPawn playerPawn)
private Dictionary<string, string> DicePlayerCloak(CCSPlayerController player, CCSPlayerPawn playerPawn)
{
if (_playersWithCloak.ContainsKey(player)) return Localizer["command.rollthedice.error"].Value.Replace("{playerName}", player.PlayerName);
if (_playersWithCloak.ContainsKey(player))
return new Dictionary<string, string>
{
{"_translation", "command.rollthedice.error"},
{ "playerName", player.PlayerName }
};
// create listener if not exists
if (_playersWithCloak.Count() == 0)
{
RegisterListener<Listeners.OnTick>(EventDicePlayerCloakOnTick);
}
// add player to list
_playersWithCloak.Add(player, 255);
return Localizer["DicePlayerCloak"].Value
.Replace("{playerName}", player.PlayerName);
return new Dictionary<string, string>
{
{"_translation", "DicePlayerCloak"},
{ "playerName", player.PlayerName }
};
}

private void RemoveDicePlayerCloakListeners()
Expand Down
18 changes: 13 additions & 5 deletions src/RollTheDice+DicePlayerDisguiseAsPlant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ public partial class RollTheDice : BasePlugin
{ "Airport/Plant", new Dictionary<string, object> { { "model", "models/props_plants/plantairport01.vmdl" } } },
{ "MailDropbox", new Dictionary<string, object> { { "model", "models/props_street/mail_dropbox.vmdl" } } },
};
private string DicePlayerDisguiseAsPlant(CCSPlayerController player, CCSPlayerPawn playerPawn)
private Dictionary<string, string> DicePlayerDisguiseAsPlant(CCSPlayerController player, CCSPlayerPawn playerPawn)
{
if (_playersDisguisedAsPlants.ContainsKey(player)) return Localizer["command.rollthedice.error"].Value.Replace("{playerName}", player.PlayerName);
if (_playersDisguisedAsPlants.ContainsKey(player))
return new Dictionary<string, string>
{
{"_translation", "command.rollthedice.error"},
{ "playerName", player.PlayerName }
};
// create listener if not exists
if (_playersDisguisedAsPlants.Count == 0) RegisterListener<Listeners.OnTick>(EventDicePlayerDisguiseAsPlantOnTick);
// add player to list
Expand All @@ -35,9 +40,12 @@ private string DicePlayerDisguiseAsPlant(CCSPlayerController player, CCSPlayerPa
).ToString();
_playersDisguisedAsPlants[player]["offset_z"] = _playersDisguisedAsPlantsModels[randomKey].ContainsKey("offset_z") ? (string)_playersDisguisedAsPlantsModels[randomKey]["offset_z"] : "0";
_playersDisguisedAsPlants[player]["offset_angle"] = _playersDisguisedAsPlantsModels[randomKey].ContainsKey("offset_angle") ? (string)_playersDisguisedAsPlantsModels[randomKey]["offset_angle"] : "0";
return Localizer["DicePlayerDisguiseAsPlant"].Value
.Replace("{playerName}", player.PlayerName)
.Replace("{model}", randomKey);
return new Dictionary<string, string>
{
{"_translation", "DicePlayerDisguiseAsPlant"},
{ "playerName", player.PlayerName },
{ "model", randomKey }
};
}

private void ResetDicePlayerDisguiseAsPlant()
Expand Down
9 changes: 6 additions & 3 deletions src/RollTheDice+DicePlayerHighGravity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ namespace RollTheDice
{
public partial class RollTheDice : BasePlugin
{
private string DicePlayerHighGravity(CCSPlayerController player, CCSPlayerPawn playerPawn)
private Dictionary<string, string> DicePlayerHighGravity(CCSPlayerController player, CCSPlayerPawn playerPawn)
{
playerPawn.GravityScale = 4f;
return Localizer["DicePlayerHighGravity"].Value
.Replace("{playerName}", player.PlayerName);
return new Dictionary<string, string>
{
{"_translation", "DicePlayerHighGravity"},
{ "playerName", player.PlayerName }
};
}
}
}
9 changes: 6 additions & 3 deletions src/RollTheDice+DicePlayerInvisible.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ public partial class RollTheDice : BasePlugin
{
private List<CCSPlayerController> _playersThatAreInvisible = new();

private string DicePlayerInvisible(CCSPlayerController player, CCSPlayerPawn playerPawn)
private Dictionary<string, string> DicePlayerInvisible(CCSPlayerController player, CCSPlayerPawn playerPawn)
{
_playersThatAreInvisible.Add(player);
playerPawn.Render = Color.FromArgb(125, 255, 255, 255);
Utilities.SetStateChanged(playerPawn, "CBaseModelEntity", "m_clrRender");
return Localizer["DicePlayerInvisible"].Value
.Replace("{playerName}", player.PlayerName);
return new Dictionary<string, string>
{
{"_translation", "DicePlayerInvisible"},
{ "playerName", player.PlayerName }
};
}

private void ResetDicePlayerInvisible()
Expand Down
Loading

0 comments on commit c44c5cb

Please sign in to comment.