• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Problem with Script; Local and Global Confused by the Server.

Obsdark

Member
Joined
Sep 25, 2011
Messages
213
Reaction score
9
¡¡¡Hey oh!!!

I have a problem, you see, i have this code:

LUA:
local tid = {
[5011] = {{x = 3021, y = 3085, z = 8}, {x = 3017, y = 3085, z = 8}, {x = 3029, y = 3076, z = 8}, {x = 3030, y = 3076, z = 8}, 25, 5}
}

--- item.actionid :=: Posicion(from), Posicion(to), Posicion(Pago Peaje), posicion (Lector) id's_castillo, Cobros(Peaje), Comision(Castillo). ---

local CastilloWare = {[2674] = {x = 3105, y = 3101, z = 8},
}

--- [2674] (Manzana (es), Reemplazar cuando los items esten hechos) ;) ---

--- item.itemid (Castillo id's) :=: Coords de paga Castillo ---

local Plyrps = tid[item.actionid]
local CastilloWare = CW[item.itemid]
Money = getPlayerMoney(cid)
Players = getPlayerPosition(cid)
vis = getTileItemById(Plyrps[4], CW)

--- doRemoveItem(getTileItemById(2148, Plyrps[3])).uid, Plyrps[6])

--- doRemoveItem((getTileItemById(2148, Plyrps[3]))uid, Plyrps[6])

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if item.itemid == 1945 and item.actionid == Plyrps and Players == Plyrps[1] and Money >= Plyrps[5] then
		doPlayerRemoveMoney(cid, Plyrps[5])
		doTransformItem(item.uid, item.itemid + 1)
		doTeleportPlayer(cid, Plyrps[2])
		doCreateItem(2148,(Plyrps[5] - Plyrps[6]), Plyrps[3])
		doCreateItem(2148,Plyrps[6], CW[1])
	elseif item.itemid == 1945 and item.actionid == Plyrps and Players == Plyrps[1] and vis and Money >= Plyrps[5] then
		doPlayerRemoveMoney(cid, Plyrps[5])
		doTransformItem(item.uid, item.itemid + 1)
		doTeleportThing(cid, Plyrps[2])
		doCreateItem(2148,Plyrps[5], Plyrps[3])
	elseif item.itemid == 1945 and item.actionid == Plyrps and Players == Plyrps[2] and Money >= Plyrps[5] then
		doPlayerRemoveMoney(cid, Plyrps[5])
		doTransformItem(item.uid, item.itemid + 1)
		doTeleportPlayer(cid, Plyrps[1])
		doCreateItem(2148,(Plyrps[5] - Plyrps[6]), Plyrps[3])
		doCreateItem(2148,Plyrps[6], CW[1])
	elseif item.itemid == 1945 and item.actionid == Plyrps and Players == Plyrps[2] and CW == Plyrps[4] and Money >= Plyrps[5] then
		doPlayerRemoveMoney(cid, Plyrps[5])
		doTransformItem(item.uid, item.itemid + 1)
		doTeleportThing(cid, Plyrps[1])
		doCreateItem(2148,Plyrps[5], Plyrps[3])
	elseif item.itemid == 1946 and item.uid == Plyrps then
		doTransformItem(item.uid, item.itemid - 1)
	else
		doPlayerSendCancel(cid,"No tienes suficiente dinero")
	end
	return 1
end

The problem is specificaly this line of the code (14)

LUA:
local tid = {
[5011] = {{x = 3021, y = 3085, z = 8}, {x = 3017, y = 3085, z = 8}, {x = 3029, y = 3076, z = 8}, {x = 3030, y = 3076, z = 8}, 25, 5}
}

(...)

local Plyrps = tid[item.actionid]
(...)
Like you can see, i'm definin 'tid' like a local thing, but for some reason this error shows up in the console:



Tnx you very much for your help and attention to my problem.

¡Have a Good Day and Several Bless!
(Y)(Y)


-Obsdark-
 
'item' is not defined in the global scope (or local outside of onUse), which is very normal.
'item' is a given argument in the global function onUse. If you want to use the variabele 'item', you have to use it WITHIN the function onUse, currently you do it outside of it.
So putting
Code:
local Plyrps = tid[item.actionid]
local CastilloWare = CW[item.itemid]
Money = getPlayerMoney(cid)
Players = getPlayerPosition(cid)
vis = getTileItemById(Plyrps[4], CW)
after
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
would probably fix it.
 
Back
Top