• 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 lever that gives crystal coin once

sharpy

New Member
Joined
Jan 4, 2010
Messages
77
Reaction score
0
Im teaching myself how to script and so far ive made a few small scripts and got them working but this one im stumped on script loads and i dont get any errors in the server console but the switch doesnt move and nothing happens here is the code ive wrote
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if item.uid == 10103 then
		if getPlayerStorageValue(cid, 30040) == -1 then
			if (item.itemid == 1946) and getPlayerLevel(cid) >=8 then
				doPlayerAddItem(cid, 2160, 1)
				doPlayerSetStorageValue(30040, 1)
				doPlayerSendCancel(cid, "You recieved a crystal coin.")
				doTransformItem(item.uid, 1945)
			elseif(item.itemid == 1945) and getPlayerLevel(cid) >=8 then
				doPlayerAddItem(cid, 2160, 1)
				doPlayerSetStorageValue(30040, 1)
				doPlayerSendCancel(cid, "You recieved a crystal coin.")
				doTransformItem(item.uid, 1946)
			elseif(item.itemid == 1946) and getPlayerLevel(cid) < 8 then
				doPlayerSendCancel(cid, "You do not have enough level.")
			elseif(item.itemid == 1945) and getPlayerLevel(cid) < 8 then
				doPlayerSendCancel(cid, "You do not have enough level.")
			end
		elseif getPlayerStorageValue(cid, 30040) > 0 then
			doPlayerSendCancel(cid, "You have already pulled this lever.")
		end
	end
			
	return 1
end

can anyone tell me what Im doing wrong??
 
Lua:
local storage = 30040
local level = 8
local id = 0

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if getPlayerStorageValue(cid, storage) < 0 then
		if getPlayerLevel(cid) >= level then
			id = doCreateItemEx(2160, 1)
			if(doPlayerAddItemEx(cid, id, true) ~= RETURNVALUE_NOERROR) then
				return doPlayerSendCancel(cid, "Sorry, you cannot carry this reward."), doSendMagicEffect(getThingPos(cid, CONST_ME_POFF)
			end
			
			doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
			setPlayerStorageValue(cid, storage, 1)
		else
			doPlayerSendCancel(cid, "Sorry, your level is not high enough.")
		end
	else
		doPlayerSendCancel(cid, "Sorry, not possible.")
	end
	
	return doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945)
end
 
Lua:
local s,i = 30045,{1945,1946,2160}
function onUse(cid,item,frompos,itemEx,topos)
local v = getThingPos(cid)
	if getPlayerStorageValue(cid,s) < 1 then
		if getPlayerLevel(cid) >= 8 then
			if item.itemid == i[2] then
				doTransformItem(item.uid,i[1])
			else
				doTransformItem(item.uid,i[2])
			end
			doPlayerAddItem(cid,i[3],1)
			setPlayerStorageValue(cid,s,1)
			doPlayerSendTextMessage(cid,MESSAGE_LAST,'You received a crystal coin.')
		else
			doPlayerSendCancel(cid,'You need level 8 to use this.')
			doSendMagicEffect(v,CONST_ME_POFF)
		end
	else
		doPlayerSendCancel(cid,'You can only use this lever once.')
		doSendMagicEffect(v,CONST_ME_POFF)
	end
	return true
end

too late :/
 
TY it worked i see now the problem is im not using tables and arrays since i havnt quite figured them out that well yet also noticed the way i wrote the script was kinda ineffectient
 
TY it worked i see now the problem is im not using tables and arrays since i havnt quite figured them out that well yet also noticed the way i wrote the script was kinda ineffectient

Well, keep trying. I think a lot of people have problems scripting because they think too hard about it. Just be chill and code!
 
ya i aways overthink stuff it helps me too when i can look at other working codes and see how they are scripted i understand them alot better now :p
 
Back
Top