Hello otland, it is my first longer than 5 lines script, I want to share it because all of my knowledge about writing in lua I earned here, also I used @Limos function from this thered.
If it is possible to make script shorter or i did something wrong feel free to comment.
Also I think it is nothing new but I didnt see script like this here.
So first of all we need to place sleeping bear on our map(id:7175) then give him actionid:xxxx.
2.Create lua file in data/actions/scripts I named it bear.lua. Copy and paste this:
Than register it in actions.xml:
Next step is create kill counter:
Go to data/creaturescipt/scripts and create lua file I made bearcounter.lua
paste this
Credits for this go to Limos.
Then register it in creaturescript.xml
and in creaturescripts/scripts/login.lua
If We copied it correctly it should summon 3 bears, when you right click on sleeping bear. Then if you kill them you can summon bears again.
If it is possible to make script shorter or i did something wrong feel free to comment.
Also I think it is nothing new but I didnt see script like this here.
So first of all we need to place sleeping bear on our map(id:7175) then give him actionid:xxxx.
2.Create lua file in data/actions/scripts I named it bear.lua. Copy and paste this:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local storage = 5005
if item.itemid == 7175 then
doTransformItem(item.uid, item.itemid - 1)
doPlayerSendTextMessage(cid, 22, "You woke up bear!")
setPlayerStorageValue(cid, 5005, 1)
for i= 1,3 do
doSummonCreature('Bear', {x = xxxx, y = yyyy, z = z}) --change it to sleeping bear position
end
elseif item.itemid == 7174 and getPlayerStorageValue(cid, 19005) == 3 then
doTransformItem(item.uid, item.itemid + 1)
setPlayerStorageValue(cid, 5005, 0)
setPlayerStorageValue(cid, 19005, 0)
end
return true
end
Than register it in actions.xml:
Code:
<action actionid="xxxx" script="bear.lua"/>
Next step is create kill counter:
Go to data/creaturescipt/scripts and create lua file I made bearcounter.lua
paste this
Code:
local config = {
['bear'] = {amount = 3, storage = 19005, startstorage = 5005, startvalue = 1}
}
function onKill(player, target)
local monster = config[target:getName():lower()]
if target:isPlayer() or not monster or target:getMaster() then
return true
end
local stor = player:getStorageValue(monster.storage)+1
if stor < monster.amount and player:getStorageValue(monster.startstorage) >= monster.startvalue then
player:setStorageValue(monster.storage, stor)
end
if (stor +1) == monster.amount then
player:setStorageValue(monster.storage, stor +1)
end
return true
end
Then register it in creaturescript.xml
Code:
<event type="kill" name="Bearcounter" script="bearcounter.lua"/>
Code:
player:registerEvent("Miscounter")
If We copied it correctly it should summon 3 bears, when you right click on sleeping bear. Then if you kill them you can summon bears again.