• 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!

Windows [LUA] Script not working right

sestorme

Member
Joined
Dec 9, 2011
Messages
272
Reaction score
6
Location
Birmingham, UK
function onUse(cid, item, fromPosition, itemEx, toPosition)
if(itemEx.itemid == 389) then
doTransformItem(itemEx.uid, 388)

doCreateItem(5904, 1, toPosition)
doDecayItem(itemEx.uid)
doPlayerAddSkill(cid, SKILL_SHIELDING, 10)

return true

end

return destroyItem(cid, itemEx, toPosition)

end

Okay, so this script generally works, it does provide items I expected and swaps to another dodoad. However, it does not provide AddSkill - heh, it used to only until the character reached 11 level in shielding, no effect since. I am also finding issues with adding math.random. If anyone could implement an example it would be great.
 
It's SHIELD not SHIELDING:
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if(itemEx.itemid == 389)then
        doCreateItem(5904, 1, toPosition)
        doPlayerAddSkill(cid, SKILL_SHIELD, 10)
        doTransformItem(itemEx.uid, itemEx.itemid - 1)
        doDecayItem(itemEx.uid)
        return true
    end
    return destroyItem(cid, itemEx, toPosition)
end
 
Ive sorted that different way, it's working:

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
if(itemEx.itemid == 389) then
mine = getPlayerSkill(cid,5)
doTransformItem(itemEx.uid, 388)
rand = math.random(1,2000)
doPlayerSay(cid,"Mining!",1)
doSendMagicEffect(toPosition,3)
doCreateItem(5904, 1, toPosition)
doDecayItem(itemEx.uid)
doPlayerAddSkillTry(cid, 5, 2)
return true
end
return destroyItem(cid, itemEx, toPosition)
end

But any time I try to add this: if rand >= 0 then it don't work anymore

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
if(itemEx.itemid == 389) then
mine = getPlayerSkill(cid,5)
doTransformItem(itemEx.uid, 388)
rand = math.random(1,2000)
[B][FONT=Arial Black]if rand >= 0 then[/FONT][/B]
doPlayerSay(cid,"Mining!",1)
doSendMagicEffect(toPosition,3)
doCreateItem(5904, 1, toPosition)
doDecayItem(itemEx.uid)
doPlayerAddSkillTry(cid, 5, 2)
return true
end
return destroyItem(cid, itemEx, toPosition)
end
 
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if(itemEx.itemid == 389)then
        local mine = getPlayerSkillLevel(cid, SKILL_SHIELD)
        doTransformItem(itemEx.uid, itemEx.itemid - 1)
        
        local chance = 50 -- 50% chance of success
        
        -- if mining level is above 10 (skills can't be below 10) and successfull
        if(mine > 10) and (math.random(1, 100) <= chance)then
            doPlayerSay(cid, "Mining!", TALKTYPE_MONSTER_SAY)
            doSendMagicEffect(toPosition, CONST_ME_BLOCKHIT)
            doCreateItem(5904, 1, toPosition)
            doDecayItem(itemEx.uid)
            doPlayerAddSkillTry(cid, SKILL_SHIELD, 2)
            return true
        end
    end
    return destroyItem(cid, itemEx, toPosition)
end
 
Wait, does this actually mean there's a constant 50% chance to succeed? I was after something like checking if rand >= mine as I was after to subtract mine from rand. Constant of any chance amount sounds quite stupid, especially if skill is meant to be leveled up to ensure higher success rate.
 
Wait, does this actually mean there's a constant 50% chance to succeed? I was after something like checking if rand >= mine as I was after to subtract mine from rand. Constant of any chance amount sounds quite stupid, especially if skill is meant to be leveled up to ensure higher success rate.

You can't expect me to know what you want.
 
You can't expect me to know what you want.

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if(itemEx.itemid == 389)then
        local mine = getPlayerSkillLevel(cid, 5)
        doTransformItem(itemEx.uid, 388)
	doPlayerAddSkillTry(cid, SKILL_SHIELD, 2)
 
        if(mine > 10) and (math.random(1, 100) <= mine)then
            doPlayerSay(cid, "Mining!", TALKTYPE_MONSTER_SAY)
            doSendMagicEffect(toPosition, CONST_ME_BLOCKHIT)
            doCreateItem(5904, 1, toPosition)
            doDecayItem(itemEx.uid)
                        return true
        end
    end
    return destroyItem(cid, itemEx, toPosition)
end
I did that for now, during testing :) It does add exp, I just probably didn't met the chance to get the item, thanks a lot for help! I dunno how to add reputation unfortunately.

/edit
I think I just met the requirement and it end up with critical error :/
 
local chance = 20 + (mine * 3) would be more appropriate and if you click here: http://otland.net/reputation.php?do=addreputation&p=1407669

Will that mean I get 80% chance on 30 shield level?
Because I am after to provide as much chance as the shield level.

/edit
Yup, it's crashing the game :/

YAY! WORKS! :D
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if(itemEx.itemid == 389)then
        local mine = getPlayerSkillLevel(cid, 5)
        doTransformItem(itemEx.uid, 388)
	doPlayerAddSkillTry(cid, SKILL_SHIELD, 2)

        local chance = 1 + (mine * 1)
 
        if(mine > 10) and (math.random(1, 100) <= chance)then
            doPlayerSay(cid, "Mining!",1)
            doSendMagicEffect(toPosition,3)
            doCreateItem(5904, 1, toPosition)
            doDecayItem(itemEx.uid)
                        return true
        end
    end
    return destroyItem(cid, itemEx, toPosition)
end

Problem was with TALKTYPE_MONSTER_SAY.
I replaced with TALKTYPE_ORANGE_1, thanks a lot. I wouldn't have done it without you!
 
Last edited:
Back
Top