• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua* Need help with mining script

brendan2

Sensation black
Joined
Feb 19, 2009
Messages
507
Reaction score
1
Ok anyways i dont no how to make the mining script give players mining skill? I dont want a npc to give players mining skill i just want people to have it.

PHP:
--- Mining V3.2 all credits by Virgel
--- Player need to learn mining
--- Player has miningskill and trys
--- Pick will break after a while
--- field to mine can become empty (empty field will change to mining ground after x.minutes)
--- talkaction with command !mining

function onUse(cid, item, frompos, item2, topos)
playerCanMine = getPlayerStorageValue(cid,40001) --- player can mine yes 1 or no 0
playerSkillMine = getPlayerStorageValue(cid,40002) --- Miningskill from player
playerSkillTry = getPlayerStorageValue(cid,40003) --- this counts the efective trys
playerPickBroken = getPlayerStorageValue(cid,40004) --- counts how often you work with a pick
multipler = 1.5 --- when its higher peoples need to mine longer for next skillup, remember to change this in talkactions also!
brokePick = math.random(20,40) --- how many trys before a pick will break
needSkillTry = math.ceil(playerSkillMine * playerSkillMine * multipler - 1)

	if playerCanMine > 0 and item2.itemid == 4328 then

------- miningskills start here ------

		if playerSkillMine >= 1 and playerSkillMine<= 10 then
			if playerPickBroken < brokePick then
				newPlayerPickBroken = playerPickBroken+1
				setPlayerStorageValue(cid,40004, newPlayerPickBroken)
				rand = math.random(1,100)
				if rand <= 20 then
					newPlayerSkillTry = playerSkillTry + 1
					setPlayerStorageValue(cid,40003, newPlayerSkillTry)
					doPlayerAddItem(cid,5880,1)
					doPlayerSendTextMessage(cid,22,"You have found 1 iron ore!")
						if playerSkillTry >= needSkillTry then
							newPlayerSkillMine = playerSkillMine + 1
							
							setPlayerStorageValue(cid,40003,0)
							nowPlayerSkillMine = getPlayerStorageValue(cid,40002)
							doPlayerSendTextMessage(cid,22,"You advanced in mining! You Miningskill is "..nowPlayerSkillMine.." now!")
						end
				elseif rand >20 and rand <=50 then
					doPlayerSendTextMessage(cid,22,"Found nothing!")
				elseif rand >50 and rand <=73 then
					newPlayerSkillTry = playerSkillTry + 1
					setPlayerStorageValue(cid,40003, newPlayerSkillTry)
					doPlayerAddItem(cid,5880,2)
					doPlayerSendTextMessage(cid,22,"You have found 2 iron ore!")
						if playerSkillTry >= needSkillTry then
							newPlayerSkillMine = playerSkillMine + 1
							setPlayerStorageValue(cid,40002,newPlayerSkillMine)
							setPlayerStorageValue(cid,40003,0)
							nowPlayerSkillMine = getPlayerStorageValue(cid,40002)
							doPlayerSendTextMessage(cid,22,"You advanced in mining! You Miningskill is "..nowPlayerSkillMine.." now!")
						end
				elseif rand >73 and rand <=78 then
					doPlayerAddItem(cid,1294,2)
					doPlayerSendTextMessage(cid,22,"You have found 2 stones!")
				elseif rand >78 and rand <85 then
					doTransformItem(item2.uid, 4329)
					doDecayItem(item2.uid)
					doPlayerSendTextMessage(cid,22,"This mine is empty!")
				elseif rand >=85 and rand <=100 then
					doPlayerSendTextMessage(cid,22,"Found nothing!")
				end
			else
				doRemoveItem(item.uid,1)
				doSendMagicEffect(topos,2)
				setPlayerStorageValue(cid,40004,0)
				doPlayerSendTextMessage(cid,22,"Your pick has been damaged and broke...")			
			end
			

------- start next miningskill stage here (start with elseif) ------

------- miningskills end here

		end
	elseif item2.itemid == 4329 then
		doPlayerSendTextMessage(cid,22,"This mine is empty!")
	elseif playerSkillMine < 1 then
		doPlayerSendTextMessage(cid,22,"You need to learn mining first!")
	else
	doPlayerSendTextMessage(cid,22,"You need to be in a Mine!")
	end
end
 
this is the npc script
PHP:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

-- OTServ event handling functions start
function onCreatureAppear(cid)				npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) 			npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) 	npcHandler:onCreatureSay(cid, type, msg) end
function onThink() 						npcHandler:onThink() end
-- OTServ event handling functions end

function creatureSayCallback(cid, type, msg)
	if(npcHandler.focus ~= cid) then
		return false
	end
    
    if msgcontains(msg,'spells') or msgcontains(msg,'help') then
            selfSay('Hello i can teach you mining for free. If you would like to learn mining please say mining')

    elseif msgcontains(msg,'mining') then
            setPlayerStorageValue(cid,40001,1)
            setPlayerStorageValue(cid,40002,1)
            setPlayerStorageValue(cid,40003,1)
            setPlayerStorageValue(cid,40004,1)
            npcHandler:say('Here you go!')
    end
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

this is my npc

PHP:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Mining dwarf" script="data/npc/scripts/mining.lua" autowalk="1" floorchange="0">
<health now="100" max="100"/>
<look type="69"/>
<parameters>
    if msgcontains(msg,'spells') or msgcontains(msg,'help') then
            selfSay('Hello i can teach you mining for free. If you would like to learn mining please say mining')

    elseif msgcontains(msg,'mining') then
            setPlayerStorageValue(cid,40001,1)
            setPlayerStorageValue(cid,40002,1)
            setPlayerStorageValue(cid,40003,1)
            setPlayerStorageValue(cid,40004,1)
            npcHandler:say('Here you go!')
</parameters>
</npc>
 
Haha long time since I saw a mining script last time... That was one of the first scripts I tried to edit, and I was very proud when I could change the chance and ID of stuff you got from mining... ;D
 
Back
Top