I took a look at Rust.Xp.dll in decompiler and wrote these functions that let you tap into the new functionality in addition to the callbacks listed at Oxide API for Rust. Remember to put the following at the top of your code. All credit to Wolf for his help in other threads.
Code:using Rust.Xp;There's more functionality in there than this, but not sure what some of the other stuff does yet.Code:float GetCurrentLevel(BasePlayer player) { return player.xp.CurrentLevel; } float GetEarnedXp(BasePlayer player) { return player.xp.EarnedXp; } float GetSpentXp(BasePlayer player) { return player.xp.SpentXp; } float GetUnspentXp(BasePlayer player) { return player.xp.UnspentXp; } float GetCurrentTime(BasePlayer player) { return player.xp.CurrentTime; } void ResetXP(BasePlayer player) { player.xp.Reset(); } void AddXP(BasePlayer player, float amount) { player.xp.Add(Rust.Xp.Definitions.Cheat, amount); } void SetXP(BasePlayer player, float amount) { ResetXP(player); AddXP(player,amount); } bool SpendXp(BasePlayer player,int xpCount, string Category) { return player.xp.SpendXp(xpCount,Category); } void AddLevel(BasePlayer player, int level) { float currentlevel = GetCurrentLevel(player); float leveltoxp = LevelToXp((int)currentlevel+level); ResetXP(player); AddXP(player,leveltoxp); } void SetLevel(BasePlayer player, int level) { ResetXP(player); AddXP(player,LevelToXp(level)); } /* Utility functions to return the amounts based on the input */ float LevelToXp(int level) { return Rust.Xp.Config.LevelToXp(level); } float XpToLevel(float xp) { return Rust.Xp.Config.XpToLevel(xp); }
New Xp Functions
Discussion in 'Rust Development' started by Caffeine, Jul 8, 2016.
-
How to up player level? and how to give xp ?
-
So for example if you wanted to increase every awake player on the servers level by 1 you could do
Code:var Active = BasePlayer.activePlayerList as List<BasePlayer>; foreach( BasePlayer player in Active ) { AddLevel(player,1); }
Code:var Active = BasePlayer.activePlayerList as List<BasePlayer>; foreach( BasePlayer player in Active ) { AddXp(player,50); }
Code:var Active = BasePlayer.activePlayerList as List<BasePlayer>; foreach( BasePlayer player in Active ) { if(isAuth(player)) SetLevel(player,300); }/* credit to whoever originally wrote this */ bool isAuth(BasePlayer player) { if (player.net.connection != null) if (player.net.connection.authLevel < 1) return false; return true; }
Last edited by a moderator: Jul 8, 2016 -
Wulf Community Admin
You don't need the // Reference at the top anymore, it's already referenced in the last Oxide build.
[DOUBLEPOST=1467985686,1467985516][/DOUBLEPOST] -
-
Wulf Community Admin
That is basically for leveling to X level by adding the required XP needed. -
Just tested it, here's why your code is abit off
[Oxide] 10:30 [Info] [XPTest] level 10: 81 xp
[Oxide] 10:30 [Info] [XPTest] level 5: 16 xp
so simply adding level 5 worth of xp to existing level 5 wouldn't be right, have to set to level 10 xp instead 16+16 != 81xp
Sorry for the block of text before, this should summarize all of it though. My existing AddLevel appears to work right.Last edited by a moderator: Jul 8, 2016 -
Code:void AddLevel(BasePlayer player, int levels = 1) => player.xp.Add(Definitions.Cheat, Rust.Xp.Config.LevelToXp((int)player.xp.CurrentLevel + levels) - player.xp.EarnedXp);
-
-
-
-
-
Wulf Community Admin
-
What's the name of the variable to get the player level ?
level = player.xp.CurrentLevel;
Code:if (crafter.xp.CurrentLevel<50) { AddLevel(crafter,1); } AddXp(crafter,50);
error CS0103: The name `AddXp' does not exist in the current contextLast edited by a moderator: Jul 8, 2016 -
You should add to your code:
Code:void AddXP(BasePlayer player, float amount) { player.xp.Add(Rust.Xp.Definitions.Cheat, amount); }
-
Wulf Community Admin
-
Code:
float currentlevel = crafter.xp.CurrentLevel; if (currentlevel<=51) {crafter.xp.Add(Definitions.Cheat, 10);}
[DOUBLEPOST=1468003829][/DOUBLEPOST]Ok, now How i can test in cs code if Arg[2] is an int ? -
-
Wulf Community Admin
-
Or float.Parse([2]) works I think