Hi,
so I am using ZLevels and ZoneManager + EventManager. I set up an deathmatch arena but when players are dying they lose XP from ZLevels. What I want to do now is access ZoneManager from ZLevels to check if player is in the zone and if yes, not decrease the XP.
In ZLevels there is this OnEntityDeath method that lowers the XP on death
and in ZoneManager there is are quite some flags I could use. For example I could use ZoneFlags.NoPveCode:void OnEntityDeath(BaseCombatEntity entity, HitInfo hitInfo) { if (entity is BasePlayer) { BasePlayer player = (BasePlayer)entity; if (!inPlayerList(player.userID)) return; string penaltyText ="<color=#FF0000>You have lost XP for dying:"; bool penaltyExist = false; foreach (string skill in Skills.ALL) { if (!IsSkillDisabled(skill)) { int penalty = GetPenalty(player, skill); if(penalty > 0) { penaltyText += "\n* -" + penalty + " " + messages[skill + "Skill"] + " XP."; removePoints(player.userID, skill, penalty); penaltyExist = true; } } } penaltyText += "</color>"; if(penaltyExist) PrintToChat(player,penaltyText); SetPlayerLastDeathDate(player.userID); RenderUI(player); } }
which is stored in the following function
What I want to do is check if NoPve is active and if yes, not trigger removePoints().Code:if (HasZoneFlag(zone, ZoneFlags.NoPve)) { CancelDamage(hitinfo); }
But how ca I access the ZoneManager flags in ZLevels? I have no idea.
Access another plugin
Discussion in 'Rust Development' started by ttrism, Apr 27, 2016.
-
Wulf Community Admin
There are quite a few examples floating around, ie. Solved - Calling my core plugin? (C#) | Oxide.
-
thanks! Okay so to ZoneManager I now added
Code:[PluginReference] Plugin ZoneManager;private bool CheckPveFlag(Zone zone) { if (HasZoneFlag(zone, ZoneFlags.NoPve)) return true; return false; }
Code:if (!IsSkillDisabled(skill) && !ZoneManager?.Call("CheckPveFlag"))
[Oxide] 14:03 [Error] ZLevelsRemastered.cs(1088,52): error CS0023: The `!' operator cannot be applied to operand of type `object'
why is it considered an object?Last edited by a moderator: Apr 28, 2016 -
Wulf Community Admin
-
tried
bool PveZoneFlag = ZoneManager?.Call("CheckPveFlag", this);
but now get
[Oxide] 14:22 [Error] ZLevelsRemastered.cs(1088,46): error CS0266: Cannot implicitly convert type `object' to `bool'. An explicit conversion exists (are you missing a cast?)
Sorry 3rd day on C# and OOP isn't my best. -
Wulf Community Admin
Code:bool PveZoneFlag = (bool)ZoneManager?.Call("CheckPveFlag", this);
-
just got it! but thanks
[DOUBLEPOST=1461792689][/DOUBLEPOST][Oxide] 14:30 [Error] Failed to call hook 'CheckPveFlag' on plugin 'ZoneManager v2.4.2' (InvalidCastException: Cannot cast from source type to destination type.)
[DOUBLEPOST=1461792773][/DOUBLEPOST]I don't even get why I have to cast at all here if I declare CheckPveFlag() as bool in ZoneManager -
If its for events why not use the check in event manager?
I think it's (bool) inEvent(ulong id) but you have to check to confirm.
Code:void OnEntityDeath(BaseCombatEntity entity, HitInfo hitInfo) { if (entity is BasePlayer) { BasePlayer player = (BasePlayer)entity; var isPlaying = EventManager?.Call("inEvent", player.userid); //Check if player is in event if (isPlaying is bool) //check if what was returned is bool if ((bool)isPlaying)// Checknif the returned bool is true return; //the bool is true so return before zlevels does any calculations if (!inPlayerList(player.userID)) return; string penaltyText ="<color=#FF0000>You have lost XP for dying:"; bool penaltyExist = false; foreach (string skill in Skills.ALL) { if (!IsSkillDisabled(skill)) { int penalty = GetPenalty(player, skill); if(penalty > 0) { penaltyText += "\n* -" + penalty + " " + messages[skill + "Skill"] + " XP."; removePoints(player.userID, skill, penalty); penaltyExist = true; } } } penaltyText += "</color>"; if(penaltyExist) PrintToChat(player,penaltyText); SetPlayerLastDeathDate(player.userID); RenderUI(player); } }
-
tested. Works like a charm! Well with one small change: It needs to be player.userID no player.userid.
Thanks a lot!
final code:
Code:[PluginReference] Plugin EventManager;void OnEntityDeath(BaseCombatEntity entity, HitInfo hitInfo) { if (entity is BasePlayer) { BasePlayer player = (BasePlayer)entity; if (!inPlayerList(player.userID)) return; string penaltyText ="<color=#FF0000>You have lost XP for dying:"; bool penaltyExist = false; foreach (string skill in Skills.ALL) { //ttrism var isPlaying = EventManager?.Call("inEvent", player.userID); //Check if player is in event if (isPlaying is bool)//check if what was returned is bool if ((bool)isPlaying) return; // Checknif the returned bool is true if (!IsSkillDisabled(skill)) { int penalty = GetPenalty(player, skill); if(penalty > 0) { penaltyText += "\n* -" + penalty + " " + messages[skill + "Skill"] + " XP."; removePoints(player.userID, skill, penalty); penaltyExist = true; } } } penaltyText += "</color>"; if(penaltyExist) PrintToChat(player,penaltyText); SetPlayerLastDeathDate(player.userID); RenderUI(player); } }
Last edited by a moderator: Apr 28, 2016 -
It was a phone edit lol, at least it works
-
proves that you are a god
-
If only, I would smite them all haha
[DOUBLEPOST=1461914068,1461840801][/DOUBLEPOST]@ttrism
I was just having a look through EventManager and I noticed the hook is actually 'bool isPlaying(BasePlayer player)' inEvent is a variable attached to the EventPlayer component. If it works for you (I'm not sure how) then by all means use it, but if you find later that there's issues with it swap it over
-
it worked but I guess because I made a huge mistake when testing causing me to think it works, when it actually didnt.
Didn't had the time yet to ask again. Very cool you checked it again! I will run another test later on and give feedback
[DOUBLEPOST=1461921891][/DOUBLEPOST]alright! pritty sure this is working now
had to change the param though from "player.userID" to "player" as initialized above.
var isPlaying = EventManager?.Call("isPlaying", player); //Check if player is in event
final code snippet:
Code:void OnEntityDeath(BaseCombatEntity entity, HitInfo hitInfo) { if (entity is BasePlayer) { BasePlayer player = (BasePlayer)entity; if (!inPlayerList(player.userID)) return; string penaltyText ="<color=#FF0000>You have lost XP for dying:"; bool penaltyExist = false; foreach (string skill in Skills.ALL) { //ttrism var isPlaying = EventManager?.Call("isPlaying", player); //Check if player is in event if (isPlaying is bool) if ((bool)isPlaying) return;//check if what was returned is bool if (!IsSkillDisabled(skill)) { int penalty = GetPenalty(player, skill); if(penalty > 0) { penaltyText += "\n* -" + penalty + " " + messages[skill + "Skill"] + " XP."; removePoints(player.userID, skill, penalty); penaltyExist = true; } } } penaltyText += "</color>"; if(penaltyExist) PrintToChat(player,penaltyText); SetPlayerLastDeathDate(player.userID); RenderUI(player); } }