By completing this guide, you should be able to trigger NPC shop purchase success 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: _OnNPCShopPurchaseSuccess
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 send a text notification after purchasing [HP Recovery Herb] successfully using _Char_SendTextNotification to ensure that the trigger works fine for us.
USE [vPlus]
GO
/****** Object: StoredProcedure [dbo].[_OnNPCShopPurchaseSuccess] Script Date: 1/18/2024 11:57:06 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[_OnNPCShopPurchaseSuccess]
@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 successfully
purchases 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, 'You have purchased Hp Recovery Herb successfully!', 1, 0, 0;
END
END