Cookies


Vsroplus only uses the cookies it needs to keep you signed in and remember your language. No ads, no tracking.

Got it

Need to learn more? Privacy policy

Our guides are in English for now.

NPC Purchase Request

By completing this guide, you should be able to trigger NPC shop purchase requests to function and build your own custom systems.

You will have to obtain the NPC ID for activating the trigger. You may use the following query to obtain the NPC ID from the database.

SELECT ID
FROM SRO_VT_SHARD.dbo._RefObjCommon
WHERE CodeName128 = 'NPC_CodeName128';

Then, you will have to add the NPC ID to the filter panel and allow the trigger in the NPCs window.

Stored Procedure: _OnNPCShopPurchaseRequest
Parameters:

@CharID INT - Character ID
@CharName16 VARCHAR(64) - Character name
@RefNPCCodeName VARCHAR(129) - NPC CodeName128
@RefItemCodeName VARCHAR(129) - Item CodeName128
@Quantity SMALLINT - Quantity

Let's block buying an [Hp Recovery Herb] from Jangan potion NPC and send a text notification using _Char_SendTextNotification to ensure that the trigger works fine for us.

USE [vPlus]
GO

/****** Object: StoredProcedure [dbo].[_OnNPCShopPurchaseRequest] Script Date: 1/18/2024 11:26:35 AM ******/

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:      <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================

ALTER PROCEDURE [dbo].[_OnNPCShopPurchaseRequest]
    @CharID INT,
    @CharName16 VARCHAR(64),
    @RefNPCCodeName VARCHAR(129),
    @RefItemCodeName VARCHAR(129),
    @Quantity SMALLINT
AS
BEGIN
    SET NOCOUNT ON;

    /*
        This procedure is executed whenever a player tries
        to purchase an item from an NPC shop.

        Note: You will have to enable TriggerShopPurchase
        in the _RefNPC table.
    */

    --------- Your code starts here --------

    -- Checking the item
    IF (@RefItemCodeName = 'ITEM_ETC_HP_POTION_01')
    BEGIN
        EXEC _Char_SendTextNotification @CharID, 'Purchasing this item is disabled at the moment!', 1, 0, 0;

        RETURN 0; -- Block the character from purchasing the item
    END

    -- RETURN 0; -- Cancel the request
    RETURN 1; -- Create the request
END

Last updated: 18 January, 2024

An error has occurred. This application may no longer respond until reloaded. Reload 🗙