So i have a plugin, which calls your dev api functions to remove rp, when they upgrade an item. the plugin then can also give back the rp, when the item is destroyed. here is the problem.
your api calls do not save the users rp, to the player_data.json file, except on the plugin unloading (at least i think that is the problem)
so what happens is this.
user has 10k rp
user spends 5k rp on upgrades
user balance now shows 5k as expected. all is good at this point.
server owner (me) sends the server console the restart command, which puts a 5 minute timer on rust, and annouces to the users its going to restart
as this gets closer to zero, it annouces it more and more.
if the user then spends his remaining rp, at say around the <60 second mark before the server restarts, he will get it all back, when the server restarts.
now the server has restarted, and his balance is 5k, not 0
The other mod that requested the api call to deduct the rp, now has his item showing 10k rp upgrades, and he essentially is able to get that back, plus the 5k he seemed to start back with, resulting in him having now 15k of rp.
its like the call that is made to save the players current balance when the plugin is unloading, is not actually working correctly, when the server is restarted with the global.restart() function, and relying on the unload to save it. maybe a timing issue? could you maybe make an api call to save?
could this be ?
Kind of a bug with
to be clear, this seems to happen if the rp is deducted during the global restart function timing, i have replicated it a few times, where i spend the rp at about 60 seconds from restart
Merged post
private object TakePoints(object userID, int amount, string item = "")
{
ulong ID;
object success = GetUserID(userID);
if (success is bool)
return false;
else ID = (ulong)success;
if (!playerRP.ContainsKey(ID)) return null;
playerRP[ID] -= amount;
if (configData.Options.Logs)
{
string message = string.Empty;
BasePlayer player = BasePlayer.FindByID(ID);
if (player != null)
message = $"{ID} - {player.displayName} has spent {amount}x RP{(string.IsNullOrEmpty(item) ? string.Empty : $" on: {item}")}";
else message = $"(offline){ID} has spent {amount}x RP";
LogToFile($"SpentRP", $"[{DateTime.Now.ToString("hh:mm:ss")}] {message}", this);
}
//added to force db update when called from api
SaveRP();
return true;
}
âi have fixed this for myself, but encourage you to put this into a patch in the future. I added the call to save the player data, at the end of the take points api function, so it will save when someone takes points with an api. There is a built in save timer, but setting that to 5 seconds makes unneeded file io traffic, when it really only needs to be updated, at least in my case, when the api is called.