I have EquippedHandlerBase and EquippedHanderServer and GunItemEquippedState, how can i get the player session?
Code:void OnFire(EquippedHandlerServer handler, GunItemEquippedState state) { EquippedHandlerBase equippedHandler = handler as EquippedHandlerBase; hurt.BroadcastChat("OnTakeDamage"); }
Getting session in custom hook?
Discussion in 'Hurtworld Development' started by DJDiamonD, Mar 19, 2016.
-
Wulf Community Admin
Look for GetSession in either Oxide's source of the game's Assembly-CSharp.dll. You'd need some way to convert what you have available to a session, so you'd need to dig around EquippedHandlerServer or GunItemEquippedState to see if there are any entity or other player references that could be used to get a session linked to those.
-
Code:PlayerSession player = GameManager.Instance.GetSession(handler.networkView.owner);
Code:13:36 [Error] Failed to call hook 'OnFire' on plugin 'AdminFunctions v0.2.0' (NullReferenceException: Object reference not set to an instance of an object) 13:36 [Debug] at Oxide.Plugins.AdminFunctions.OnFire (.EquippedHandlerServer handler, .GunItemEquippedState state) [0x00000] in <filename unknown>:0 at Oxide.Plugins.AdminFunctions.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00000] in <filename unknown>:0 at Oxide.Plugins.CSharpPlugin.InvokeMethod (System.Reflection.MethodInfo method, System.Object[] args) [0x00000] in <filename unknown>:0 at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x00000] in <filename unknown>:0 at Oxide.Core.Plugins.Plugin.CallHook (System.String hookname, System.Object[] args) [0x00000] in <filename unknown>:0 13:36 [Warning] CallHook 'OnFire' on plugin 'AdminFunctions v0.2.0' took: 1549ms
-
Wulf Community Admin
-
-
Guys i need to get session in this function, changes in method name are impossible!
Code:protected virtual void FireServer(EquippedHandlerServer handler, GunItemEquippedState state) { Vector3 point = state.CamPivot.rotation * Vector3.forward; Vector3 position = state.CamPivot.position; IProjectile projectile = state.PreloadedProjectile.Dequeue(); projectile.GetImpactBehavior().EntityEffects = this._entityEffects; Quaternion inacuracyDirection = this.GetInacuracyDirection(state); projectile.Launch(position, Quaternion.identity, inacuracyDirection * point * this._shotPower, handler.gameObject, false, 0f); state.TimeTillReady = this._refireTime; state.Character.DisableSprintTimeout(this._refireTime); state.NotifyOnEmpty = true; }
Code:if(handler.networkView.owner == null) { hurt.BroadcastChat("null"); } PlayerSession session = Singleton<GameManager>.Instance.GetSession(handler.networkView.owner); //PlayerIdentity identity = Singleton<GameManager>.Instance.GetIdentity(handler.networkView.owner); hurt.BroadcastChat("OnFire");
Code:Failed to call hook 'OnFire' on plugin 'AdminFunctions v0.2.0' (NullReferenceException: Object reference not set to an instance of an object)
-
EquippedHandlerServer doesn't have "networkView" variable
-
-
Guys, i have made i hook with help of Oxide Patcher. But this hook doesn't contain PlayerSession, how can i add this argument? In Oxide Patcher i can not edit my hook.
[DOUBLEPOST=1458499688,1458401962][/DOUBLEPOST]UP -
Wulf Community Admin
-
Wulf Community Admin
If PlayerSession does not exist in the hook location, you'd need to wrap the hook in HurtworldCore like I mentioned before and try to convert it from what is available in the hooked location. You may never be able to get PlayerSession if there is nothing to reference though.
-
-
Wulf Community Admin
-
[DOUBLEPOST=1458506336][/DOUBLEPOST]
Code of hook:
Code:public void TakeDamage(Vector3 direction, float amount) { this._hasDirection = direction.sqrMagnitude > 0.1f; direction = direction.normalized; this._focusedPlayer = Singleton<GameManager>.Instance.FocusedPlayer.GetComponent<CharacterMotorSimple>(); if (this._hasDirection) { Quaternion quaternion = Quaternion.LookRotation(-direction); this._directionalOffset = quaternion.eulerAngles.y; } this.SetLevel(1f); this._level = 2f; this._targetLevel = 0f; }