This procedure gives or takes XP (not level) from a player, but sometimes it seems to bug out, like its giving out too much XP. Could it be this code? I also have a onexpearn plug in operation, could this be the problem?Code:private void SetXP(BasePlayer player, float amt) { var agent = BasePlayer.FindXpAgent(player.userID); float xp = player.xp.SpentXp + player.xp.UnspentXp; if (xp < amt && amt < 0 ) return; var newxp = xp + amt; agent?.Reset(); agent.Add(Rust.Xp.Definitions.Cheat, newxp); }
Thanks in advance!Code:object OnXpEarn(ulong steamId, double amount, string source) { if (string.IsNullOrEmpty(source) ) return null; var bonus = 1f; if (ConVar.Server.hostname.Contains("2X")) bonus = 2f; if (ConVar.Server.hostname.Contains("3X")) bonus = 3f; if (ConVar.Server.hostname.Contains("4X")) bonus = 4f; if (ConVar.Server.hostname.Contains("5X")) bonus = 5f; return (float)(amount * bonus); }
Set a player XP (not level)
Discussion in 'Rust Development' started by Rusty, Sep 16, 2016.
-
You should check to make sure the source isn't "Cheat". XpBooster already does this.
-
What source should i use? Im not interested in 3rd party plugs, i just need this function to work properly 100% of times.
-
Just an example. I think the source is just "Cheat" but I used a tolower and contains in case it isn't. Basically, the code won't execute if it's a "cheat" source.Code:
object OnXpEarn(ulong steamId, double amount, string source) { if (string.IsNullOrEmpty(source) ) return null; if (source.ToLower().Contains("cheat")) return null; var bonus = 1f; if (ConVar.Server.hostname.Contains("2X")) bonus = 2f; if (ConVar.Server.hostname.Contains("3X")) bonus = 3f; if (ConVar.Server.hostname.Contains("4X")) bonus = 4f; if (ConVar.Server.hostname.Contains("5X")) bonus = 5f; return (float)(amount * bonus); } -
Can you answer PM.
