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

Action 8.4 castle doors (black walls)

Spoking

Oldschool Developer
Joined
Sep 4, 2007
Messages
434
Reaction score
34
script:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)

		if item.itemid == 9169 then
			doTransformItem(item.uid, 9170)
		elseif item.itemid == 9170 then
			doTransformItem(item.uid, 9169)
		return TRUE
	end
	
		if item.itemid == 9165 then
			doTransformItem(item.uid, 9167)			
		elseif item.itemid == 9167 then
			doTransformItem(item.uid, 9165)
		return TRUE
	end
	
		if item.itemid == 9171 then
			doTransformItem(item.uid, 9172)			
		elseif item.itemid == 9172 then
			doTransformItem(item.uid, 9171)
		return TRUE
	end
	
		if item.itemid == 9173 then
			doTransformItem(item.uid, 9174)			
		elseif item.itemid == 9174 then
			doTransformItem(item.uid, 9173)
		return TRUE
	end
end

in actions.xml:
Code:
	<action itemid="9169" script="newdoor.lua"/>
	<action itemid="9170" script="newdoor.lua"/>
	<action itemid="9165" script="newdoor.lua"/>
	<action itemid="9167" script="newdoor.lua"/>
	<action itemid="9171" script="newdoor.lua"/>
	<action itemid="9172" script="newdoor.lua"/>
	<action itemid="9173" script="newdoor.lua"/>
	<action itemid="9174" script="newdoor.lua"/>

use the ID"s that are in the actions.xml
 
Your script but optimized :p

PHP:
local config = {
    [9169] = {9170}, 
    [9170] = {9169}, 
    [9165] = {9167}, 
    [9167] = {9165}, 
    [9171] = {9172}, 
    [9172] = {9171}, 
    [9173] = {9174}, 
    [9174] = {9173}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
	for type, variable(config) do
		if item.itemid == type then
			doTransformItem(item.uid, variable[1])
		return TRUE
		end
	end
end
 
ur dont work pitufo :) because you wrote for type, variable(config), while it should be for type, variable in pairs(config)

PHP:
local config = {
    {9169, 9170}, 
    {9165, 9167}, 
    {9171, 9172}, 
    {9173, 9174}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    for _, v in ipairs(config) do
        if item.itemid == v[1] then
            doTransformItem(item.uid, v[2])
            return TRUE
        elseif item.itemid == v[2] then
            doTransformItem(item.uid, v[1])
            return TRUE
        end
    end
end
 
@Colandus, could you explain this part for me:

Code:
for [COLOR="Red"][B]_, v[/B][/COLOR] in ipairs(config) do
 
_ is a normal variable, most oftenly used when forced to declare a variable while you dont need it... the "_" is the key while "v" is the value... in this case i only need "v" so i just declare the key "_"

try in scripts instead thats easier than asking :)
 
_ is a normal variable, most oftenly used when forced to declare a variable while you dont need it... the "_" is the key while "v" is the value... in this case i only need "v" so i just declare the key "_"

try in scripts instead thats easier than asking :)

Ah, now I see. Thank you. :)
 
Back
Top