• 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 Remove Item-Give Storage-Remove Storage-When Use Door

WhiteOut

OT Builder
Joined
Nov 13, 2013
Messages
53
Reaction score
4
Location
Las Vegas - Loss Wages - Sin City
Very easy script but I haven't scripted in quiet a while and I know I'm doing something wrong.
TFS 0.3.6
I have two scripts that work in one quest and its a rather simple idea and I cannot get it to work.
Action Scripts
This script suppose to take the item, give you a storage (10054), if you have the storage you can't use the item till storage is gone. Item disappeared when used.
Code:
function onUse(cid, item, frompos, item2, topos)

    if (item.itemid == 5809) then
        hasKey = getPlayerStorageValue(cid, 10054)

        elseif ((hasKey == -1) or (hasKey == 0)) then
            print(":: Blah Key used by " .. getPlayerName(cid))
            doPlayerSendTextMessage(cid, 16, "Blah Blah Blah.")
            doPlayerSendTextMessage(cid, 16, "Blah Blah Blah.")
            doPlayerSendTextMessage(cid, 16, "Blah Blah Blah.")
            doPlayerSendTextMessage(cid, 24, "Blah Blah Blahhhhh.")
            doPlayerRemoveItem(cid, 5809, 1)
            setPlayerStorageValue(cid, 10054, 1)
        if
            doPlayerSendTextMessage(cid, 16, "Blah Blah Blahh.")
            doPlayerSendTextMessage(cid, 24, "Blah Blah.")
        end
    end

This script is for the door (door unique ID 5809) if you have the storage (storage 10054) from the previous item (itemid 5809) once you right click door it then spawns a monster and door disappears while blocking other door for access.

Code:
function onUse(cid, item, frompos, item2, topos)

    if (item.uid == 5809) then
        hasKey = getPlayerStorageValue(cid, 10054)
        if ((hasKey == -1) or (hasKey == 0)) then
            doPlayerSendTextMessage(cid,22,"Blah Blah Blah.")
        else
            setPlayerStorageValue(cid, 10054, 0)

            doorPos = {x=163, y=71, z=8, stackpos=1}
            door = getThingfromPos(doorPos)
            doTransformItem(door.uid, 1196)

            doorPos = {x=169, y=68, z=8, stackpos=1}
            door = getThingfromPos(doorPos)
            doRemoveItem(door.uid, 5809)
           
            sBlahPos = {x=165, y=69, z=8, stackpos=1}
            doSummonCreature("skiller", sBlahPos)

            doPlayerSendTextMessage(cid, 16, "Blah Blah.")
            doPlayerSendTextMessage(cid, 24, "Blah Blah.")
        end   
    end
end

Thanks For Viewing
~Sin
 
Your methods and functions are fine, but you failed to construct statement.
Don't start with else if, but only with if and change the if after that to else
 
This structure should be applicable for both your scripts:
Code:
function onUse(cid, item, frompos, item2, topos)
local hasKey = getPlayerStorageValue(cid, 10054)
    if hasKey ~= 1 then
        -- do this if they do not have the storage
    else
        -- do this
    end
return true
end


Are far as checking the itemID or uniqueID in the script you don't need to in this case, just make sure you register them correctly in actions.xml:
Code:
<action uniqueid="8059" event="script" value="script.lua"/>
<action itemid="8059" event="script" value="script.lua"/>
 
This structure should be applicable for both your scripts:
Code:
function onUse(cid, item, frompos, item2, topos)
local hasKey = getPlayerStorageValue(cid, 10054)
    if hasKey ~= 1 then
        -- do this if they do not have the storage
    else
        -- do this
    end
return true
end


Are far as checking the itemID or uniqueID in the script you don't need to in this case, just make sure you register them correctly in actions.xml:
Code:
<action uniqueid="8059" event="script" value="script.lua"/>
<action itemid="8059" event="script" value="script.lua"/>
Being that I haven't scripted in over 2 years could you please do a bit of format for me via where it goes, I understand what you mean just don't recall exactly where to include that.

Thanks
~Sin
 
Being that I haven't scripted in over 2 years could you please do a bit of format for me via where it goes, I understand what you mean just don't recall exactly where to include that.

Thanks
~Sin

The KEY script for example:
Code:
function onUse(cid, item, frompos, item2, topos)
local hasKey = getPlayerStorageValue(cid, 10054)
    if hasKey ~= 1 then
        doPlayerSendTextMessage(cid, 24, "Blah Blah Blahhhhh.")
        doPlayerRemoveItem(cid, 5809, 1)
        setPlayerStorageValue(cid, 10054, 1)
    else
        doPlayerSendTextMessage(cid, 24, "You already used this key... blah baaaaaaaah to the maximum blah.")
    end
return true
end
 
Nevermind I got it, thank you!!!

Code:
function onUse(cid, item, frompos, item2, topos)
local hasKey = getPlayerStorageValue(cid, 10054)
    if hasKey ~= 1 then
            print(":: Blag Key used by " .. getPlayerName(cid))
            doPlayerSendTextMessage(cid, 16, "Blah.")
            doPlayerSendTextMessage(cid, 16, "YBlah!")
            doPlayerSendTextMessage(cid, 16, "Blah.")
            doPlayerSendTextMessage(cid, 24, "Blah?")
            doPlayerRemoveItem(cid, 5809, 1)
            setPlayerStorageValue(cid, 10054, 1)           
    else
            doPlayerSendTextMessage(cid, 16, "Blah.")
            doPlayerSendTextMessage(cid, 24, "Blah!")       
    end
return true
end

Code:
function onUse(cid, item, frompos, item2, topos)
local hasKey = getPlayerStorageValue(cid, 10054)
    if hasKey ~= 1 then
        doPlayerSendTextMessage(cid,22,"Blah.")
        else
            setPlayerStorageValue(cid, 10054, 0)

            doorPos = {x=163, y=71, z=8, stackpos=1}
            door = getThingfromPos(doorPos)
            doTransformItem(door.uid, 1196)

            doorPos = {x=169, y=68, z=8, stackpos=1}
            door = getThingfromPos(doorPos)
            doRemoveItem(door.uid, 5809)
           
            sBlahPos = {x=165, y=69, z=8, stackpos=1}
            doSummonCreature("sBlah", sBlahPos)

            doPlayerSendTextMessage(cid, 16, "Blah.")
            doPlayerSendTextMessage(cid, 24, "Blah.")

    end
return true
end

Thanks to both you guys and mostly @imkingran
~Sin
 
The KEY script for example:
Code:
function onUse(cid, item, frompos, item2, topos)
local hasKey = getPlayerStorageValue(cid, 10054)
    if hasKey ~= 1 then
        doPlayerSendTextMessage(cid, 24, "Blah Blah Blahhhhh.")
        doPlayerRemoveItem(cid, 5809, 1)
        setPlayerStorageValue(cid, 10054, 1)
    else
        doPlayerSendTextMessage(cid, 24, "You already used this key... blah baaaaaaaah to the maximum blah.")
    end
return true
end
Your the man, didn't even see this post but I'm glad it looks the same^^ Thanks bro!

~Sin
 
Your the man, didn't even see this post but I'm glad it looks the same^^ Thanks bro!

~Sin

One thing that you might want to change:
Code:
doPlayerRemoveItem(cid, 5809, 1)
to:
Code:
doRemoveItem(item.uid, 1)

Otherwise the player could use the key on the ground and it wouldn't be removed I believe, you can double check to make sure.
 
One thing that you might want to change:
Code:
doPlayerRemoveItem(cid, 5809, 1)
to:
Code:
doRemoveItem(item.uid, 1)

Otherwise the player could use the key on the ground and it wouldn't be removed I believe, you can double check to make sure.
Great catch, you were right it didn't go away. Fixed : )

~Sin
 
Back
Top