You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
I’m trying to create a system which takes a finished game’s statistics and calculates the reward due to each player based on particular categories (players hit, players killed, highest killstreak).
-
What is the issue? Include screenshots / videos if possible!
So i’m calculating for XP and coins acquired by each player. The output shows that the treatment functions calculate those amounts correctly in respect to the worth tables that are being passed.
Although the final print always shows that coins[“Players”] always has the same values as XP[“Players”], this is not the same for coins[“TopPlayers”] and XP["TopPlayers].
For some reason XP[“Players”] and coins[“Players”] share the same values although going through different treatments. Something must be going wrong in the CalcGameResults function.
I’m certain theres a simple mistake somewhere but i’m having a lot of troubles at finding it.
3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
local coins_worth = {
["PlayersKilled"] = 2,
["PartsDestroyed"] = 1/30,
["SpawnpointsDestroyed"] = 5,
["TopPlayers"] = {
["PlayersKilled"] = 15,
["PartsDestroyed"] = 15,
["SpawnpointsDestroyed"] = 15
}
}
local xp_worth = {
["PlayersKilled"] = 10,
["PartsDestroyed"] = 5/30,
["SpawnpointsDestroyed"] = 25,
["TopPlayers"] = {
["PlayersKilled"] = 100,
["PartsDestroyed"] = 100,
["SpawnpointsDestroyed"] = 100
}
}
local default_player_stats = {
["PlayersKilled"] = 0,
["PartsDestroyed"] = 0,
["SpawnpointsDestroyed"] = 0,
}
local treatment = {
["Players"] = function(GameStats, worth)
local retVal = {}
for user_id, player_stats in GameStats do
retVal[user_id] = default_player_stats
for stat, value in player_stats do
print("Calc results", stat, value, worth[stat], value * worth[stat])
retVal[user_id][stat] = value * worth[stat]
end
end
print("treatment ret val - ", retVal)
return retVal
end,
["TopPlayers"] = function(GameStats, worth)
local retVal = {}
for stat, user_id in GameStats do
retVal[stat] = {["user_id"] = user_id, ["worth"] = worth["TopPlayers"][stat] }
end
return retVal
end,
}
function GameReward:CalcGameResults(GameStats)
local retVal = {["coins"] = {}, ["XP"] = {}}
print("game vals - ", GameStats)
for i, v in GameStats do
retVal["coins"][i] = treatment[i](v, coins_worth)
retVal["XP"][i] = treatment[i](v, xp_worth)
end
print("ret val - ", retVal)
return retVal
end
The output is as follows:
23:07:13.845 Calc results SpawnpointsDestroyed 0 5 0 - Server - GameReward:44
23:07:13.845 Calc results PlayersKilled 0 2 0 - Server - GameReward:44
23:07:13.846 Calc results PartsDestroyed 3109 0.03333333333333333 103.63333333333333 - Server - GameReward:44
23:07:13.846 treatment ret val - ▶ {...} - Server - GameReward:49
23:07:13.846 Calc results SpawnpointsDestroyed 0 25 0 - Server - GameReward:44
23:07:13.846 Calc results PlayersKilled 0 10 0 - Server - GameReward:44
23:07:13.846 Calc results PartsDestroyed 3109 0.16666666666666666 518.1666666666666 - Server - GameReward:44
23:07:13.847 treatment ret val - ▶ {...} - Server - GameReward:49
23:07:13.847 ret val - ▼ {
["XP"] = ▼ {
["Players"] = ▼ {
[1045238997] = ▼ {
["PartsDestroyed"] = 518.1666666666666,
["PlayersKilled"] = 0,
["SpawnpointsDestroyed"] = 0
}
},
["TopPlayers"] = ▼ {
["PartsDestroyed"] = ▼ {
["user_id"] = 1045238997,
["worth"] = 100
}
}
},
["coins"] = ▼ {
["Players"] = ▼ {
[1045238997] = ▼ {
["PartsDestroyed"] = 518.1666666666666,
["PlayersKilled"] = 0,
["SpawnpointsDestroyed"] = 0
}
},
["TopPlayers"] = ▼ {
["PartsDestroyed"] = ▼ {
["user_id"] = 1045238997,
["worth"] = 15
}
}
}
} - Server - GameReward:102