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

Feature [creatureEvent] onMove very advanced

Code:
function onMove(params, go hear)
  maxuid = 5000 -- change with max uid of items (can't be infinite, uids are in use for players, creatures, items, npcs, etc)
  if(item.uid > 0 and item.uid < maxuid) then
     return true
  end
  return false
end

This will mean the player can't move the item in their bag or depot either. Completely unmovable! :p You will need to check if it is to or from the floor then run the unique check I believe.
 
@Cah_ZiN

@Cah_ZiN,
I can fix that problem..

First add this function in data/lib/050-function.lua
function getItemsInContainerById(container, itemid) -- Function By Kydrai
local items = {}
if isContainer(container) and getContainerSize(container) > 0 then
for slot=0, (getContainerSize(container)-1) do
local item = getContainerItem(container, slot)
if isContainer(item.uid) then
local itemsbag = getItemsInContainerById(item.uid, itemid)
for i=0, #itemsbag do
table.insert(items, itemsbag)
end
else
if itemid == item.itemid then
table.insert(items, item.uid)
end
end
end
end
return items
end


now go to your unique item script,
data/creaturescripts/scripts/your script.lua
function onMoveItem(cid, item, formPosition, toPosition, fromItem, toItem, fromGround, toGround, status)
if isContainer(item.uid) then
local itemid = 2531 --- isso eh o id do unique item
local a = getItemsInContainerById(item.uid, itemid)
for _, uid in pairs(a) do
if uid then
if (status.inInv == 0 and status.inInvBag == 3 and status.inDepot == 3) or (status.inDepot == 0 and status.inInv == 3 and status.inInvBag == 3 ) or (status.inInvBag == 0 and status.inDepot == 3 and status.inInv == 3) then
doPlayerSendCancel(cid, "You Can't drop this bag, Have a unique item.")
return false
end
end
end
return true
end
return true
end

Sorry my english, im from Brazil :x
 
It's really cool and I really want this but I can't start my server now. Everything compiled good but now when I start my server (Running Database Manager) It crashes there.
 
Where should i register the lua script? At creature or movements also what should i add for lines to to the xml files! Rep!!
 
Here i a script base I made with help from Cykotitan:

Basically, it only allows users who are invited to a house to be able to move and throw stuff in and out of the house. (Solves etc problems with people trashing houses).

What I want to do, is to give additional limitations to users who are only "guest" in the house, I want them to only be able to:

- Move items between containers in the house
- Pick up items from containers to their character
- Drop down items from their character to containers in house.

Script is similar to "white list", nothing is allowed, unless it i specified in the script:
Lua:
function onMoveItem(cid, item, formPosition, toPosition, fromItem, toItem, fromGround, toGround, status)
	local hid = getHouseFromPos(toPosition)
	if hid == false then
		return true
	end
	
	-- If you are the owner
	if getHouseOwner(hid) == getPlayerGUID(cid) then
		doPlayerSendCancel(cid, "OWNER: OK.")
		return true
	end
	
	-- If you are a guest, allow:
	local me = getCreatureName(cid):lower()
	for _, name in ipairs(getHouseAccessList(hid, 0x100):explode("\n")) do
		if me == name:lower() then
			doPlayerSendCancel(cid, "GUEST: OK.")
			return true -- Allow movement
		end
	end
	
	-- If you are a sub-owner, allow:
	local me = getCreatureName(cid):lower()
	for _, name in ipairs(getHouseAccessList(hid, 0x101):explode("\n")) do
		if me == name:lower() then
			doPlayerSendCancel(cid, "SUB-OWNER: OK.")
			return true -- Allow movement
		end
	end
	
	-- Else return false
	doPlayerSendCancel(cid, "You are not allowed to do that in this house.")
	return false
end
As you see, I am already able to separate owners, sub owners and guests, and I can add custom code for those groups.

Here is one of my fail attempts to do this for the players invited in guest list:
Lua:
function onMoveItem(cid, item, formPosition, toPosition, fromItem, toItem, fromGround, toGround, status)
	
	-- Fetching house id, if toposition is not a house allow movement
	local hid = getHouseFromPos(toPosition)
	if hid == false then
		return true
	end
	doPlayerSendTextMessage(cid, 13, "1. toPosition is inside a house!")
	
	-- If you are the owner
	if getHouseOwner(hid) == getPlayerGUID(cid) then
		doPlayerSendTextMessage(cid, 13, "2. You got full access as owner of the house to move stuff!")
		return true
	end
	
	-- If you are a guest, allow:
	local me = getCreatureName(cid):lower()
	for _, name in ipairs(getHouseAccessList(hid, 0x100):explode("\n")) do
		if me == name:lower() then
			doPlayerSendTextMessage(cid, 13, "3. You are recognized as a  guest!")
			
			-- ------------------------ --
			-- MOVE ITEM FROM CONTAINER --
			-- ------------------------ --
			if fromItem.itemid then
				doPlayerSendTextMessage(cid, 13, "4. fromItem.uid exist!")
				
				if isContainer(fromItem.uid) then
					doPlayerSendTextMessage(cid, 13, "5. fromItem recognized movement from container!")
					
					-- If item you moved to is a slot in character:
					if status.inInv >= 1 or status.inInvBag >= 1 and status.inInv == 0 or status.inInvBag == 0 and status.inInv >= 1 then
						doPlayerSendTextMessage(cid, 13, "6. You moved something to your inventory!")
						return true
					end
					
					--If you moved item to container:
					if toItem.itemid then
						if isContainer(toItem.uid) then
							doPlayerSendTextMessage(cid, 13, "6. You moved something between containers in house!")
							return true
						end
					end
				end
				
				-- ---------------------- --
				-- MOVE ITEM TO CONTAINER --
				-- ---------------------- --
			elseif toItem.itemid then
				if isContainer(toItem.uid) then
					
					-- If you move item to container from container
					if isContainer(fromItem.uid) then
						return true
					
					-- If you move item to container from inventory
					elseif status.inInvBag == 0 then
						return true
					end
					
				end
			end
		end
	end
	
	-- If you are a sub-owner, allow:
	local me = getCreatureName(cid):lower()
	for _, name in ipairs(getHouseAccessList(hid, 0x101):explode("\n")) do
		if me == name:lower() then
			doPlayerSendCancel(cid, "SUB-OWNER: OK.")
			return true -- Allow movement
		end
	end
	
	-- Else return false (deny movement?)
	doPlayerSendCancel(cid, "You are not ALLOWED to do that.")
	return false
end
I am having some problems recognizing and allowing items to be picked up from containers in house and dropped down to containers in house.
 
Last edited:
Fixed somthing in script that make server crashes on moving items at some way. Please all recopy even if u dont get the crash.
 
can you tell me where i should add the lua and what i should write on tbe xml file
 
Update : Another Critical crash fix, please you are required to update.

- - - Updated - - -

@Znote, try this
Lua:
function isGuest(cid,house)
	for _, name in ipairs(getHouseAccessList(house, 0x100):explode("\n")) do
		if getCreatureName(cid):lower() == name:lower() then
			return true
		end
	end
	return false
end
function isSubOwner(cid,house)
	for _, name in ipairs(getHouseAccessList(house, 0x101):explode("\n")) do
		if getCreatureName(cid):lower() == name:lower() then
			return true
		end
	end
	return false
end
function onMoveItem(cid, item, formPosition, toPosition, fromItem, toItem, fromGround, toGround, status)
	local house = getHouseFromPos(toPosition)
 
	if not house then
		return true
	end
 
	if getHouseOwner(house) == getPlayerGUID(cid) or isSubOwner(cid,house) then
		return true
	end
 
	if not isGuest(cid,house) then
		doPlayerSendCancel(cid,"Sorry, You can't move items in this house.")
		return false
	end
 
	if (status.inInv == 0 and status.inInvBag == 3 and status.inDepot == 3) or 
		(status.inDepot == 0 and status.inInv == 3 and status.inInvBag == 3 ) or
		(status.inInvBag == 0 and status.inDepot == 3 and status.inInv == 3) then
 
		if not isContainer(toItem.uid) then
			doPlayerSendCancel(cid,"Sorry, guests only have capability of (adding/taking) items (to/from) house containers.")
			return false
		end
 
	elseif (status.inInv == 3 and status.inInvBag == 3 and status.inDepot == 3) then
		if isContainer(fromItem.uid) and isContainer(toItem.uid) then
			return true
		end
		doPlayerSendCancel(cid,"Sorry, guests only have capability of (adding/taking) items (to/from) house containers.")
		return false
	end
	return true
end
 
Last edited:
cant u tell us what u fixed? so i dont need to re copy everything? :p just the fixed part?
 
Doggybub. I tried this function out and I thought it was good until I saw that you could put the item you cannot throw on the ground, into a bag and then throw it on the ground.
 
I still dont get it what u want ?!! this is a creature script function that is executed every time player move a thing , you do the checks if you dont want a bag to be moved that has a special items, my example in main thread was just a simple one!
 
Update : Another Critical crash fix, please you are required to update.

- - - Updated - - -

@Znote, try this
Lua:
function isGuest(cid,house)
	for _, name in ipairs(getHouseAccessList(house, 0x100):explode("\n")) do
		if getCreatureName(cid):lower() == name:lower() then
			return true
		end
	end
	return false
end
function onMoveItem(cid, item, formPosition, toPosition, fromItem, toItem, fromGround, toGround, status)
	local house = getHouseFromPos(toPosition)
	
	if not house then
		return true
	end
	
	if getHouseOwner(house) == getPlayerGUID(cid) then
		return true
	end
	
	if not isGuest(cid,house) then
		doPlayerSendCancel(cid,"Sorry, You can't move items in this house.")
		return false
	end
	
	if (status.inInv == 0 and status.inInvBag == 3 and status.inDepot == 3) or 
		(status.inDepot == 0 and status.inInv == 3 and status.inInvBag == 3 ) or
		(status.inInvBag == 0 and status.inDepot == 3 and status.inInv == 3) then
		
		if not isContainer(toItem.uid) then
			doPlayerSendCancel(cid,"Sorry, guests only have capability of (adding/taking) items (to/from) house containers.")
			return false
		end
	
	elseif (status.inInv == 3 and status.inInvBag == 3 and status.inDepot == 3) then
		if isContainer(fromItem.uid) and isContainer(toItem.uid) then
			return true
		end
		doPlayerSendCancel(cid,"Sorry, guests only have capability of (adding/taking) items (to/from) house containers.")
		return false
	end
	return true
end

Here its only for guests!
in Znote's script its for sub owner 2 :p!? can u fix that 2 in ur script?!
 
I still dont get it what u want ?!! this is a creature script function that is executed every time player move a thing , you do the checks if you dont want a bag to be moved that has a special items, my example in main thread was just a simple one!

Oh, sorry, how can I check if the bag contains the undropable item?
 
Well I had this scripted to my server it should be just perfect:
Lua:
--$$ Undropable Items $$--
local items = {2222}	-- item ids that is undropable

--[[ Script]]--
function searchContainers(uid,itemss)
	local items = itemss
	local containers = {}
	local check = false
	for i = 0, getContainerSize(uid)-1 do
		local item = getContainerItem(uid,i)
		if not isContainer(item.uid) then
			if isInArray(items,item.itemid) then
				check = true
			end
		else
			table.insert(containers,item.uid)
		end
	end
	for _, container in ipairs(containers) do
		if searchContainers(container,items) then
			check = true
			break
		end
	end
	return check
end	
function onMoveItem(cid, item, formPosition, toPosition, fromItem, toItem, fromGround, toGround, status)
	if status.inInv == 1 and status.inInvBag == 3 and status.inDepot == 3 and isInArray(items,getPlayerSlotItem(cid,status.slot).itemid ) then
		doPlayerSendCancel(cid,"You can't drop a special item on the ground.")
		doSendMagicEffect(getThingPos(cid),2)
		return false
	end
	
	if (status.inInv == 0 and status.inInvBag == 3 and status.inDepot == 3) or 
		(status.inDepot == 0 and status.inInv == 3 and status.inInvBag == 3 ) or
		(status.inInvBag == 0 and status.inDepot == 3 and status.inInv == 3) then
		
		if not isContainer(item.uid) then
			if isInArray(items,item.itemid) then
				doPlayerSendCancel(cid,"You can't drop a special item on the ground.")
				doSendMagicEffect(getThingPos(cid),2)
				return false
			end
		else
			if searchContainers(item.uid,items) then
				doPlayerSendCancel(cid,"You can't throw this bag that contains special item[s] on ground")
				doSendMagicEffect(getThingPos(cid),2)
				return false
			end
		end
	end
		
	return true
end
 
Another 2 Critical crach fixes : please you are reqired to copy the game.cpp part. [0.3.6 not fixed yet]


Note: Only the 0.4 version is fully fixed now and shouldn't have any future bugs.
 
Back
Top