Jump to content

How to add drop level limit


Go to solution Solved by qAlex,

Recommended Posts

Hello, how can I add a limit level drop, for example only to drop the item if player level is -10 /+10 different from the mob level: 

        when kill with not npc.is_pc() and game.get_event_flag("moonlight_event") == 1 begin
			local chance = number(1, 100)
			local chance_max = game.get_event_flag("moonlight_event_chance")                    
				if chance <= chance_max then						
					pc.give_item2(50011)							
				else
			end
		end

 

Edited by qAlex
Link to comment
https://metin2.dev/topic/33008-how-to-add-drop-level-limit/
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • Active+ Member

try this: 
 

quest moonlight_event_drop begin
    state start begin
        when kill with not npc.is_pc() and game.get_event_flag("moonlight_event") == 1 begin
            local chance = number(1, 100)
            local chance_max = game.get_event_flag("moonlight_event_chance")
            local mob_level = npc.get_level()  -- Get the mob's level
            local player_level = pc.get_level()  -- Get the player's level
            
            -- Check if the player's level is within +/- 10 of the mob's level
            if math.abs(player_level - mob_level) <= 10 then
                if chance <= chance_max then
                    pc.give_item2(50011)  -- Chest 
                end
            end
        end
    end
end


 

12 hours ago, KolenMG said:

try this: 
 

quest moonlight_event_drop begin
    state start begin
        when kill with not npc.is_pc() and game.get_event_flag("moonlight_event") == 1 begin
            local chance = number(1, 100)
            local chance_max = game.get_event_flag("moonlight_event_chance")
            local mob_level = npc.get_level()  -- Get the mob's level
            local player_level = pc.get_level()  -- Get the player's level
            
            -- Check if the player's level is within +/- 10 of the mob's level
            if math.abs(player_level - mob_level) <= 10 then
                if chance <= chance_max then
                    pc.give_item2(50011)  -- Chest 
                end
            end
        end
    end
end


 

doesnt work

-- Moonlight Event - Item Drop Quest
-- The player can only receive the item if the mob is within ±10 levels of the player.

when kill with not npc.is_pc() and game.get_event_flag("moonlight_event") == 1 begin
    -- Define the chance to drop the item
    local drop_chance = number(1, 100)
    local max_chance = game.get_event_flag("moonlight_event_chance")
    
    -- Get player and mob levels
    local player_level = pc.get_level()
    local mob_level = npc.get_level()
    
    -- Calculate level difference (absolute value)
    local level_difference = math.abs(player_level - mob_level)
    
    -- Check if the level difference is within ±10 levels
    if level_difference <= 10 then
        -- If the chance is within the max chance, give the item
        if drop_chance <= max_chance then
            pc.give_item2(50011)
        end
    end
end

Try this, i tested it and it works just fine.

Software Engineer @ CNH Industrial (NAFTA/EMEA)

3 minutes ago, FrenchForeignLegion said:
-- Moonlight Event - Item Drop Quest
-- The player can only receive the item if the mob is within ±10 levels of the player.

when kill with not npc.is_pc() and game.get_event_flag("moonlight_event") == 1 begin
    -- Define the chance to drop the item
    local drop_chance = number(1, 100)
    local max_chance = game.get_event_flag("moonlight_event_chance")
    
    -- Get player and mob levels
    local player_level = pc.get_level()
    local mob_level = npc.get_level()
    
    -- Calculate level difference (absolute value)
    local level_difference = math.abs(player_level - mob_level)
    
    -- Check if the level difference is within ±10 levels
    if level_difference <= 10 then
        -- If the chance is within the max chance, give the item
        if drop_chance <= max_chance then
            pc.give_item2(50011)
        end
    end
end

Try this, i tested it and it works just fine.

SYSERR: Sep 21 19:32:28 :: RunState: LUA_ERROR: [string "moonlight_event"]:4: attempt to call field `get_level' (a nil value)
SYSERR: Sep 21 19:32:28 :: WriteRunningStateToSyserr: LUA_ERROR: quest moonlight_event.start click

 

1 minute ago, qAlex said:
SYSERR: Sep 21 19:32:28 :: RunState: LUA_ERROR: [string "moonlight_event"]:4: attempt to call field `get_level' (a nil value)
SYSERR: Sep 21 19:32:28 :: WriteRunningStateToSyserr: LUA_ERROR: quest moonlight_event.start click

 

Seems like you are missing pc.get_level from quest_functions. Try adding it and try again.

Software Engineer @ CNH Industrial (NAFTA/EMEA)

  • Solution
Just now, FrenchForeignLegion said:

Seems like you are missing pc.get_level from quest_functions. Try adding it and try again.

I have it there already

3 minutes ago, qAlex said:

I have it there already

I found the fix, at local mob_level = npc.get_level() , in quest functions there is no npc.get_level but it is npc.get_level0 🤦‍♂️

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.