I'm attempting at making a points system, so when a player kills another player they get given a set amount of points. How would i start?
How to get players killsSolved
I want to make a points tracker this is my code:
private int eloPointsPerKill = 0;
private void OnPlayerDeath(BasePlayer victim, HitInfo info)
{
BasePlayer killer = info?.Initiator?.ToPlayer();
if (killer == victim)
{
return;
}
else {
eloPointsPerKill += 50;
Puts("You have earnt <color=red>50</color> ELO points from that kill!");
}
return;
}
[Command("elo")]
private void EloCommand(IPlayer player, string Command, string[] args)
{
player.Reply($"You've got <color=red>{eloPointsPerKill.ToString()}</color> ELO!");
}Whats wrong about it is that the ELO is shared to all players in the server, how could i go around this?
There are a number of ways to do this, but the simplest way would be to implement a Dictionary...
Dictionary<string, int> eloPointsPerKill = new Dictionary<string, int>();
private void OnPlayerDeath(BasePlayer victim, HitInfo info)
{
BasePlayer killer = info?.Initiator?.ToPlayer();
if (killer == victim)
{
return;
}
else {
if(eloPointsPerKill.Contains(killer.UserIDString))
{
eloPointsPerKill[killer.UserIDString] += 50;
}
else
{
eloPointsPerKill.Add(killer.UserIDString, 50);
}
Puts("You have earnt <color=red>50</color> ELO points from that kill!");
}
return;
}
[Command("elo")]
private void EloCommand(IPlayer player, string Command, string[] args)
{
eloPointsPerKill.TryGetValue(player.Id, out int points);
player.Reply($"You've got <color=red>{points.ToString()}</color> ELO!");
} Calytic
There are a number of ways to do this, but the simplest way would be to implement a Dictionary...
Dictionary<string, int> eloPointsPerKill = new Dictionary<string, int>(); private void OnPlayerDeath(BasePlayer victim, HitInfo info) { BasePlayer killer = info?.Initiator?.ToPlayer(); if (killer == victim) { return; } else { if(eloPointsPerKill.Contains(killer.UserIDString)) { eloPointsPerKill[killer.UserIDString] += 50; } else { eloPointsPerKill.Add(killer.UserIDString, 50); } Puts("You have earnt <color=red>50</color> ELO points from that kill!"); } return; } [Command("elo")] private void EloCommand(IPlayer player, string Command, string[] args) { eloPointsPerKill.TryGetValue(player.Id, out int points); player.Reply($"You've got <color=red>{points.ToString()}</color> ELO!"); }
I seem to be getting this error when using that code
(39,56): error CS1644: Feature `declaration expression' cannot be used because it is not part of the C# 6.0 language specification
Locked automatically