1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Request OnCardSwiped Hook (Rust)

Discussion in 'Feature Suggestions' started by Slydelix, Jun 8, 2018.

  1. Slydelix

    Slydelix Plugin Developer

    Would it be possible to add this for the update coming out today, possibly object so we can prevent doors from getting opened



    (CardReader class)
    Code (Text):
    public void ServerCardSwiped(BaseEntity.RPCMessage msg)
        {
            if (!base.IsPowered())
            {
                return;
            }
            if (Vector3Ex.Distance2D(msg.player.transform.position, base.transform.position) > 1f)
            {
                return;
            }
            if (base.IsInvoking(new Action(this.GrantCard)) || base.IsInvoking(new Action(this.FailCard)))
            {
                return;
            }
            uint num = msg.read.UInt32();
            Keycard keycard = BaseNetworkable.serverEntities.Find(num) as Keycard;
            Effect.server.Run(this.swipeEffect.resourcePath, this.audioPosition.position, Vector3.up, msg.player.net.connection, false);
            if (keycard != null)
            {
                Item item = keycard.GetItem();
                if (item == null || keycard.accessLevel != this.accessLevel || item.conditionNormalized <= 0f)
                {
                    base.Invoke(new Action(this.FailCard), 0.5f);
                }
                else
                {
             
                    if (Interface.CallHook("OnCardSwiped", this, msg.player) != null)
                    {
                         return;
                    }
                    base.Invoke(new Action(this.GrantCard), 0.5f);
                    item.LoseCondition(1f);
                }
            }
        }
    Edit: possible mistakes because I did this in a text editor
    Edit 2: Possibly multiple hooks, one at the top for when player swipes and 2 for when the swipe was "successful" (opens doors) and when it was not
     
    Last edited: Jun 8, 2018
  2. FuJiCuRa

    FuJiCuRa Plugin Developer

    Or keep it simple...
    Code (C#):
    // CardReader
    [global::BaseEntity.RPC_Server, global::BaseEntity.RPC_Server.IsVisible(3f)]
    public void ServerCardSwiped(global::BaseEntity.RPCMessage msg)
    {
        if (!base.IsPowered())
        {
            return;
        }
        if (Vector3Ex.Distance2D(msg.player.transform.position, base.transform.position) > 1f)
        {
            return;
        }
        if (base.IsInvoking(new Action(this.GrantCard)) || base.IsInvoking(new Action(this.FailCard)))
        {
            return;
        }
        uint uid = msg.read.UInt32();
        global::Keycard keycard = global::BaseNetworkable.serverEntities.Find(uid) as global::Keycard;
        global::Effect.server.Run(this.swipeEffect.resourcePath, this.audioPosition.position, Vector3.up, msg.player.net.connection, false);
        if (keycard != null)
        {
            if (Interface.CallHook("OnCardSwiped", new object[]
            {
                this,
                keycard,
                msg.player
            }) != null)
            {
                return;
            }
            global::Item item = keycard.GetItem();
            if (item != null && keycard.accessLevel == this.accessLevel && item.conditionNormalized > 0f)
            {
                base.Invoke(new Action(this.GrantCard), 0.5f);
                item.LoseCondition(1f);
                return;
            }
            base.Invoke(new Action(this.FailCard), 0.5f);
        }
    }