Jump to content
gunnapong

Killing monsters earns money based on level.

Recommended Posts

I want to know the code, let's say that killing a level 1-20 monster gives 500 gold, a level 20-40 monster gives 1000 gold, and the higher the level, the higher. You only get more money. Help me. Thank you.

Share this post


Link to post
Share on other sites

Hello, @gunnapong!
 

This script should work fine:

-- Player killed monster event
GetExp_PKM__Original = GetExp_PKM
GetExp_PKM = function(monster, role)
	
	-- Call original function GetExp_PKM()
	GetExp_PKM__Original(monster, role)
	
	-- Get killed monster level
	local level = Lv(monster)
	
	-- Gold amount
	local money = 0
	
	
	-- Check the monster level
	if (level < 21) then
		money = 1000 -- 1,000 g
	elseif (level < 41) then
		money = 2000 -- 2,000 g
	end
	
	-- Add gold
	if (money > 0) then
		
		-- Give gold
		role = TurnToCha(role)
		local tmp = GetChaAttr(role, ATTR_GD)
		SetChaAttr(role, ATTR_GD, tmp + money)
		
		-- Show a message
		SystemNotice(
			role, 
			string.format(
				"You killed (%s) and got (%d) gold!", 
				GetChaDefaultName(monster), 
				money
			)
		)
	
	end
	
end

 

  • Thanks 1

Share this post


Link to post
Share on other sites
On 7/26/2022 at 7:17 PM, V3ct0r said:

Hello, @gunnapong!
 

This script should work fine:


-- Player killed monster event
GetExp_PKM__Original = GetExp_PKM
GetExp_PKM = function(monster, role)
	
	-- Call original function GetExp_PKM()
	GetExp_PKM__Original(monster, role)
	
	-- Get killed monster level
	local level = Lv(monster)
	
	-- Gold amount
	local money = 0
	
	
	-- Check the monster level
	if (level < 21) then
		money = 1000 -- 1,000 g
	elseif (level < 41) then
		money = 2000 -- 2,000 g
	end
	
	-- Add gold
	if (money > 0) then
		
		-- Give gold
		role = TurnToCha(role)
		local tmp = GetChaAttr(role, ATTR_GD)
		SetChaAttr(role, ATTR_GD, tmp + money)
		
		-- Show a message
		SystemNotice(
			role, 
			string.format(
				"You killed (%s) and got (%d) gold!", 
				GetChaDefaultName(monster), 
				money
			)
		)
	
	end
	
end

 

It's working very well, I'd like to ask more.  If I use a VIP card to make money*2 times  how should i write @V3ct0r

Share this post


Link to post
Share on other sites
1 hour ago, gunnapong said:

It's working very well, I'd like to ask more.  If I use a VIP card to make money*2 times  how should i write @V3ct0r

If the condition is just having the VIP card in the player bag then it would look like this.

-- Player killed monster event
GetExp_PKM__Original = GetExp_PKM
GetExp_PKM = function(monster, role)
    
    -- Call original function GetExp_PKM()
    GetExp_PKM__Original(monster, role)
    
    -- Get killed monster level
    local level = Lv(monster)
    
    -- Gold amount
    local money = 0
    
    
    -- Check the monster level
    if (level < 21) then
        money = 1000 -- 1,000 g
    elseif (level < 41) then
        money = 2000 -- 2,000 g
    end
    
    -- Add gold
    if (money > 0) then
        -- Has VIP Card
        local VIP_Card_ID = 0001
        local Has_VIP_Card = CheckBagItem(role,VIP_Card_ID)
        local VIP_Card_text = ""
        if Has_VIP_Card > 0 then
            VIP_Card_text = " VIP Card bonus applied!"
            money = money * 2
        end
        -- Give gold
        role = TurnToCha(role)
        local tmp = GetChaAttr(role, ATTR_GD)
        SetChaAttr(role, ATTR_GD, tmp + money)
        
        -- Show a message
        SystemNotice(
            role, 
            string.format(
                "You killed (%s) and got (%d) gold!"..VIP_Card_text, 
                GetChaDefaultName(monster), 
                money
            )
        )
    
    end
    
end

Edited by Saeed

Share this post


Link to post
Share on other sites

And if you want it to delete the VIP Card each time you would change it to


        if Has_VIP_Card > 0 then
            VIP_Card_text = " VIP Card bonus applied!"
            money = money * 2
            DelBagItem(role,VIP_Card_ID,1)
        end

Share this post


Link to post
Share on other sites
On 7/28/2022 at 5:34 AM, Saeed said:

If the condition is just having the VIP card in the player bag then it would look like this.

 


-- Player killed monster event
GetExp_PKM__Original = GetExp_PKM
GetExp_PKM = function(monster, role)
    
    -- Call original function GetExp_PKM()
    GetExp_PKM__Original(monster, role)
    
    -- Get killed monster level
    local level = Lv(monster)
    
    -- Gold amount
    local money = 0
    
    
    -- Check the monster level
    if (level < 21) then
        money = 1000 -- 1,000 g
    elseif (level < 41) then
        money = 2000 -- 2,000 g
    end
    
    -- Add gold
    if (money > 0) then
        -- Has VIP Card
        local VIP_Card_ID = 0001
        local Has_VIP_Card = CheckBagItem(role,VIP_Card_ID)
        local VIP_Card_text = ""
        if Has_VIP_Card > 0 then
            VIP_Card_text = " VIP Card bonus applied!"
            money = money * 2
        end
        -- Give gold
        role = TurnToCha(role)
        local tmp = GetChaAttr(role, ATTR_GD)
        SetChaAttr(role, ATTR_GD, tmp + money)
        
        -- Show a message
        SystemNotice(
            role, 
            string.format(
                "You killed (%s) and got (%d) gold!"..VIP_Card_text, 
                GetChaDefaultName(monster), 
                money
            )
        )
    
    end
    
end

 

it works fine But I need a way to use the VIP card for 1 day, after 1 day, the money*2 will be gone.

Share this post


Link to post
Share on other sites
1 hour ago, gunnapong said:

it works fine But I need a way to use the VIP card for 1 day, after 1 day, the money*2 will be gone.

that would have to be a whole another script to configure VIP cards to disappear after 1 day so the bonus will be gone

Share this post


Link to post
Share on other sites
28 minutes ago, Saeed said:

that would have to be a whole another script to configure VIP cards to disappear after 1 day so the bonus will be gone

Do you know how to write?

Share this post


Link to post
Share on other sites
On 7/29/2022 at 5:31 AM, gunnapong said:

it works fine But I need a way to use the VIP card for 1 day, after 1 day, the money*2 will be gone.

You can check that player have certain item in the bag (CheckBagItem()) or have VIP effect (GetChaStateLv()).


Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...