moved tables outside of function
removed unnecessary loops
LUA:local discovery = MoveEvent() -- Store the discoveries and rewards globally to avoid re-initializing them in the function. local discoveries = { [23001] = {name = "Rook Temple", experience = 50}, [23002] = {name = "Rook Shop Tower", experience = 25}, [23003] = {name = "Weapon Dealer Shop", experience = 25}, [23004] = {name = "Woodlow", experience = 100}, [23005] = {name = "Elary", experience = 100}, [23006] = {name = "Smallville", experience = 250}, [23007] = {name = "Emerald Town", experience = 100}, [23008] = {name = "Caver Town", experience = 500}, [23009] = {name = "Toros Town", experience = 1000}, } local rewards = { [10] = { experience = 500, items = {{id = 2160, count = 5}}, -- 5 crystal coins outfit = {lookType = 128, addon = nil}, -- Only outfit, no addon }, [15] = { experience = 1000, items = {{id = 2160, count = 10}}, -- 10 crystal coins outfit = {lookType = 129, addon = 1}, -- Outfit with first addon }, [20] = { experience = 2000, items = {{id = 2152, count = 100}}, -- 100 platinum coins outfit = {lookType = 130, addon = 2}, -- Outfit with second addon }, } local globalStorageKey = 23000 -- Key to store total discoveries count function discovery.onStepIn(player, item, position, fromPosition) if not player:isPlayer() then return true -- If it's not a player, do nothing end local discovery = discoveries[item.actionid] if discovery then local storageValue = player:getStorageValue(item.actionid) if storageValue == -1 then -- Mark the discovery as found player:setStorageValue(item.actionid, 1) player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have discovered " .. discovery.name .. ".") player:addExperience(discovery.experience, true) -- Increase the count of total discoveries local totalDiscoveries = player:getStorageValue(globalStorageKey) or 0 totalDiscoveries = totalDiscoveries + 1 player:setStorageValue(globalStorageKey, totalDiscoveries) -- Check for rewards at specific milestones local reward = rewards[totalDiscoveries] if reward then player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Congratulations! You have discovered " .. totalDiscoveries .. " places and earned a reward.") -- Add experience player:addExperience(reward.experience, true) -- Add items for _, item in ipairs(reward.items) do player:addItem(item.id, item.count) end -- Add outfit and/or addons local lookType = reward.outfit.lookType local addon = reward.outfit.addon if addon then player:addOutfitAddon(lookType, addon) else player:addOutfit(lookType) end end end end return true end -- Register the discovery events for aid in pairs(discoveries) do discovery:aid(aid) end discovery:type("stepin") discovery:register()
@berkecuk:
discovery place discovery experience reward (https://otland.net/resources/discovery-place-discovery-experience-reward.45/)
can we change this reward experience to for example discover 5 places reward unlock outfit discover 10 places reward unlock addon 1 and discover 15 places reward full outfit addons?
LUA:local discovery = MoveEvent() function discovery.onStepIn(player, item, position, fromPosition) if not player:isPlayer() then return true -- If it's not a player, do nothing end local discoveries = { {aid = 23001, name = "Rook Temple", experience = 50}, {aid = 23002, name = "Rook Shop Tower", experience = 25}, {aid = 23003, name = "Weapon Dealer Shop", experience = 25}, {aid = 23004, name = "Woodlow", experience = 100}, {aid = 23005, name = "Elary", experience = 100}, {aid = 23006, name = "Smallville", experience = 250}, {aid = 23007, name = "Emerald Town", experience = 100}, {aid = 23008, name = "Caver Town", experience = 500}, {aid = 23009, name = "Toros Town", experience = 1000}, } -- Reward milestones local rewards = { [10] = { experience = 500, items = {{id = 2160, count = 5}}, -- 5 crystal coins outfit = {lookType = 128, addon = nil}, -- Only outfit, no addon }, [15] = { experience = 1000, items = {{id = 2160, count = 10}}, -- 10 crystal coins outfit = {lookType = 129, addon = 1}, -- Outfit with first addon }, [20] = { experience = 2000, items = {{id = 2152, count = 100}}, -- 100 platinum coins outfit = {lookType = 130, addon = 2}, -- Outfit with second addon }, } local globalStorageKey = 23000 -- Key to store total discoveries count for _, discovery in pairs(discoveries) do if item.actionid == discovery.aid then local storageValue = player:getStorageValue(discovery.aid) if storageValue == -1 then -- Mark the discovery as found player:setStorageValue(discovery.aid, 1) player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have discovered " .. discovery.name .. ".") player:addExperience(discovery.experience, true) -- Increase the count of total discoveries local totalDiscoveries = player:getStorageValue(globalStorageKey) or 0 totalDiscoveries = totalDiscoveries + 1 player:setStorageValue(globalStorageKey, totalDiscoveries) -- Check for rewards at specific milestones local reward = rewards[totalDiscoveries] if reward then player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Congratulations! You have discovered " .. totalDiscoveries .. " places and earned a reward.") -- Add experience if reward.experience then player:addExperience(reward.experience, true) end -- Add items if reward.items then for _, item in ipairs(reward.items) do player:addItem(item.id, item.count) end end -- Add outfit and/or addons if reward.outfit then local lookType = reward.outfit.lookType local addon = reward.outfit.addon if addon then if addon == 1 or addon == 2 then player:addOutfitAddon(lookType, addon) elseif addon == 3 then player:addOutfitAddon(lookType, 1) player:addOutfitAddon(lookType, 2) end else -- No addon specified, just give the outfit player:addOutfit(lookType) end end end end break end end return true end -- Register the discovery events local discoveryAids = {23001, 23002, 23003, 23004, 23005, 23006, 23007, 23008, 23009} for _, aid in ipairs(discoveryAids) do discovery:aid(aid) end discovery:type("stepin") discovery:register()