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

Problem with script (get distance)

kermaxpl

Pora na Nonsens Scripter
Joined
Aug 21, 2012
Messages
121
Reaction score
7
Location
Poland
hi guys i have this code:
Code:
local objekt = {x=5393, y=5163, z=7}
function onThink(interval, lastExecution, thinkInterval)
pos = getCreaturePosition(cid)
punkty = (((pozycja.y-pozycja.x)*(pozycja.y+pozycja.x))+((objekt.y-objekt.x)*(objekt.y+objekt.x)))
dist = math.pow(punkty, (1/2.0))
	if (getPlayerItemCount(cid,2338) > 0) then
		if (dist < 35) then
		doSendAnimatedText(getCreaturePosition(cid), "Cos zaczyna dziac sie z ...", COLOR_GREEN)
		end
	end
	return true
end

And it makes this error:
Code:
[23:31:06.090] [Error - CreatureScript Interface]
[23:31:06.090] data/creaturescripts/scripts/distance.lua:onThink
[23:31:06.090] Description:
[23:31:06.090] data/creaturescripts/scripts/distance.lua:4: attempt to index global 'pozycja' (a nil value)
[23:31:06.090] stack traceback:
[23:31:06.090]  data/creaturescripts/scripts/distance.lua:4: in function <data/creaturescripts/scripts/distance.lua:2>
How can I change this script?

I Really need it.

Sorry for my english
 
I'm looking for script which can check your distance from defined position if u have some item and send/message or sth if your distance is lower than for example 40.
 
i no understand all but i tell you what i understand :D and you say if that true or not ,
not you want script when i stay in X floor and if i have distance 40 or higher , it add for me item?
 
When u stay in X floor and have Y item and have distance 40 or lower to defined position then you got message.
 
when i stay in X floor and have Y item and have distance 40 or lower , it's just make message ? . or teleport to another position , or giving another items , or what :D :p , and tell me that's happen 1 time per player or what? :
 
make message and change item for example from id 1900 to 1901 and it can happen only if your storage id 50000 is 1
 
try this :D , not test :)
Lua:
-- CONFIG
local sirion_old = 1900 -- the items which will get remove
local sirion_new = 1901 -- the items which will get add 
local sirion_storage = 50000 -- the stroage
local sirion_message = "Congratulations you have get item" -- the message when get the item
local sirion_cancel = "you already took the items" -- the message when get cancel
-- CONFIG

function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)

	if getPlayerItemCount(cid, sirion_old) == 1 and getPlayerStorageValue(cid, sirion_storage) ~= 1 then
	
		setPlayerStorageValue(cid, sirion_storage, 1)
		doPlayerAddItem(cid, sirion_new, 1)
		doPlayerRemoveItem(cid, sirion_old)
		doCreatureSay(cid, sirion_message, TALKTYPE_ORANGE_1)
		else
		doCreatureSay(cid, sirion_cancel, TALKTYPE_ORANGE_1)
		
		

	end
return true
end


and put this in movements.xml and put the unique id in the code in the floor :p
XML:
	<movevent event="StepIn" uniqueid="14449" script="NAME.lua"/>
 
Last edited:
I will try this today or tomorrow and i will send reply, but i think it should work.
Btw. very clever solution


It works but i have to use uid 1003 more than one time and i have a lot of "duplitace uniqueId 1003" when server starts.
 
Last edited:
yes and i said, that I have to use uid 1003 on more than one item and i have warning "duplicate uniqueId 1003" when server starts, but script works.

I only have to correct this
Code:
getPlayerItemCount(cid, sirion_old)
to this
Code:
getPlayerItemCount(cid, sirion_old) == 1
. It is small mistake.
 
Widzę, że jesteś Polakiem, a nie chce mi się po angielsku pisać, więc..
pos = getCreaturePosition(cid)
....
punkty = (((pozycja.y-pozycja.x)*(pozycja.y+pozycja.x))+((objekt.y-objekt.x)*(objekt.y+objekt.x)))
Jest "pos" a nie "pozycja" :)
Chyba rozumiesz.
 
yes and i said, that I have to use uid 1003 on more than one item and i have warning "duplicate uniqueId 1003" when server starts, but script works.

I only have to correct this
Code:
getPlayerItemCount(cid, sirion_old)
to this
Code:
getPlayerItemCount(cid, sirion_old) == 1
. It is small mistake.

ops sorry really sorry :p i edited in the main post

+ duplicate uniqueId 1003
that's not error :D , it mean that uid is not in 1 item , it's on more than 1
 
@Sirion_Mido
Thx, everything is ok

@ZiomerOs
To akurat drobny błąd, ponieważ cały skrypt jest do niczego(nawet po poprawce wywala błąd), za to skrypt autorstwa Sirion_Mido działa doskonale, jedyna uciążliwość to dodanie uid jeśli pól jest to można się nieźle naklikać.
 

Similar threads

Back
Top