User Tools

Site Tools


developer_center:developer_editor:script:minishop

How to tutorial mini shop

How to: Display a message when a player buys an item in devshop

To display a message when the player buys something in the developer shop, we use the Developer.BuyItem event and we put it in the handler function, this event returns the eventobjid (The id of the player who triggered the event) and the id of the item that was bought (id of the item in the developer shop, not itemid)

We then add the Chat:sendSystemMsg() method with the message that we want to send to the player, in this case we will use the color codes, in this case, B for blue, and this will make our message appear in blue, instead of the normal orange

ScriptSupportEvent:registerEvent([=[Developer.BuyItem]=], function(e) 
    
    local playerid = e['eventobjid']
    local itembought = e['itemid']
    
    Chat:sendSystemMsg( "#B Thanks for your purchase! :)", playerid)


end)

This should work, but what if we want to create a message with for example, the name of the player? then we can use the Player:getNickname() method to do so, it returns the ErrorCode and the nickname of the player, this also opens a new window of opportunity because we can also create custom messages for each item


ScriptSupportEvent:registerEvent([=[Developer.BuyItem]=], function(e) 
    
    local playerid = e['eventobjid']
    local itembought = e['itemid']
        
    local _,playernick = Player:getNickname(playerid)
    Chat:sendSystemMsg( "#B Thanks for your purchase, "..playernick, playerid)   
end)

Now, if we want to create custom messages for each item, we can get the id using the game's built-in id library

Example

ScriptSupportEvent:registerEvent([=[Developer.BuyItem]=], function(e) 
    
    local playerid = e['eventobjid']
    local itembought = e['itemid']
    
    local _,playernick = Player:getNickname(playerid)
    
    if itembought == 4098 then

    Chat:sendSystemMsg( "#B Thanks for your purchase, "..playernick, playerid)

    end

    if itembought == 4097 then 
        
        Chat:sendSystemMsg( "#B Thanks for donating, "..playernick, playerid) 
        
    end
    
end)
developer_center/developer_editor/script/minishop.txt · Last modified: 2024/03/06 23:08 by notsopro