• 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 [QuestSystem] Chest: Getting Items in Container.

QuaS

Cykotitan Pwned =/
Joined
Sep 11, 2008
Messages
838
Reaction score
28
Location
Poland/ Wroclaw
Hello There. I want to show you one of my old scripts.

Take It:

Lua:
local items = {
--[item_uid] = {items = { {ITEM_ID,COUNT_OF ITEM}, {ITEM_ID,COUNT_OF ITEM} ... }, container = CONTAINER_ID},
[49009] = {itemss = {{2273,2}, {2480,4},{2361,3}}, container = 2365}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local queststatus = getPlayerStorageValue(cid, item.uid)
	if queststatus > 0 then
		canDo = "false"
	else
		canDo = "true"
	end
	stillDo = getBooleanFromString(canDo)
	
	if not stillDo then
		weight = 0
		i = 1
		repeat
			weight = getItemWeightById(items[item.uid].itemss[i][1],items[item.uid].itemss[i][2]) + weight
			i = i + 1
		until i == #items[item.uid].itemss +1
		if getPlayerFreeCap(cid) >= weight then
			conta = doCreateItemEx(items[item.uid].container,1)
			for i = 1,#items[item.uid].itemss do
					doAddContainerItem(conta, items[item.uid].itemss[i][1], items[item.uid].itemss[i][2])
			end
			addItemToPlayer = doPlayerAddItemEx(cid, conta , 0)
				if addItemToPlayer == RETURNVALUE_NOERROR then
				setPlayerStorageValue(cid,item.uid,1)
				doPlayerSendTextMessage(cid,22,"You have found "..getItemArticleById(items[item.uid].container).." "..getItemNameById(items[item.uid].container)..".")
			else
				doPlayerSendTextMessage(cid,22,"You do not have enough space in backpack.")
			end
		else
			doPlayerSendTextMessage(cid,22,"You have found "..getItemArticleById(items[item.uid].container).." "..getItemNameById(items[item.uid].container)..". You do not have enough cap. You need ".. weight .." oz. to carry it.")
		end
	else
	doPlayerSendTextMessage(cid,22,"It is empty.")
	end

return TRUE
end

How It Configure? Look into script, there is a schema.
You are putting Unique_ID to chest or corpse/wall/mailbox(anything)
then adding line into script:
Lua:
[ITEM_UID] = {itemss = {{item1ID,COUNT}, {ITem2ID,count},{ITEM3ID,COUNT}}, container = CONTAINERID}
also for newbies: To actions.xml:

PHP:
	<action uniqueid="UID_OF_CHEST" event="script" value="PATH_TO_FILE.lua" />

How It Works?:

2ykjfy1.jpg


Why am i relasing it? Cuz i am bored.

Regards QuaS~
 
You are using:
Lua:
        local queststatus = getPlayerStorageValue(cid, item.uid)
        if queststatus > 0 then
                canDo = "false"
        else
                canDo = "true"
        end
        stillDo = getBooleanFromString(canDo)
       
        if not stillDo then
	.
	.
	.
        else
		doPlayerSendTextMessage(cid,22,"It is empty.")
        end
Better:
Lua:
        if getPlayerStorageValue(cid, item.uid) > 0 then
                return doPlayerSendTextMessage(cid, 22, "It is empty.")
	end

	.
	.
	.

Else it looks good :peace:.
 
Code:
                canDo = "true"
                canDo = "false"
        stillDo = getBooleanFromString(canDo)
never heard speak in this task
 
You are using:
Lua:
        local queststatus = getPlayerStorageValue(cid, item.uid)
        if queststatus > 0 then
                canDo = "false"
        else
                canDo = "true"
        end
        stillDo = getBooleanFromString(canDo)
       
        if not stillDo then
	.
	.
	.
        else
		doPlayerSendTextMessage(cid,22,"It is empty.")
        end
Better:
Lua:
        if getPlayerStorageValue(cid, item.uid) > 0 then
                return doPlayerSendTextMessage(cid, 22, "It is empty.")
	end

	.
	.
	.

Else it looks good :peace:.


I know that there is this way to make it, but i choosen this one.. I think it looks sweet xD i even make a lua function for it xD:

Lua:
function canPlayerDo(cid, value)
	local queststatus = getPlayerStorageValue(cid,value)
	if queststatus > 0 then
		canDo = "false"
	else
		canDo = "true"
	end
	return getBooleanFromString(canDo)
end
 
Lua:
function canPlayerDo(cid, value)
        local queststatus = getPlayerStorageValue(cid,value)
        if queststatus > 0 then
                canDo = "false"
        else
                canDo = "true"
        end
        return getBooleanFromString(canDo)
end

...
Lua:
function canPlayerDo(cid, value)
        return getPlayerStorageValue(cid, value) > 0 and true or false
end
 
...
Lua:
function canPlayerDo(cid, value)
        return getPlayerStorageValue(cid, value) > 0 and true or false
end

:OOO!!

didn't know that in lua exist some kind of thing like in c++:
PHP:
(a>10)?Do_Sth:DoSthElse;

So in lua is it? :
Lua:
CONDITION and WhatIfConditionIsTrue or WhatIfConditionIsFalse

And to let you know. I know then i can return true or false without "getBooelanFronString" But i wanted as hell to use this function xD
 
smaller?

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if getPlayerStorageValue(cid, 40007) < 1 then
        local bag = doPlayerAddItem(cid, 1987, 1)
			doAddContainerItem(bag, 2171, 1)
                        doAddContainerItem(bag, 2124, 1)
			doAddContainerItem(bag, 2168, 1)
			doAddContainerItem(bag, 2145, 3)
                        doAddContainerItem(bag, 2146, 4)
        setPlayerStorageValue(cid, 40007, 1)
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have found a bag.")
    else
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is empty.")
    end
return TRUE
end
 
Suggestion

Instead of:
Lua:
        if queststatus > 0 then
                canDo = "false"
        else
                canDo = "true"
        end
        stillDo = getBooleanFromString(canDo)

Write:
Lua:
        local stillDo = (queststatus <= 0)

Or maybe:
Lua:
        if not (queststatus <= 0) then
 
smaller?

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if getPlayerStorageValue(cid, 40007) < 1 then
        local bag = doPlayerAddItem(cid, 1987, 1)
			doAddContainerItem(bag, 2171, 1)
                        doAddContainerItem(bag, 2124, 1)
			doAddContainerItem(bag, 2168, 1)
			doAddContainerItem(bag, 2145, 3)
                        doAddContainerItem(bag, 2146, 4)
        setPlayerStorageValue(cid, 40007, 1)
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have found a bag.")
    else
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is empty.")
    end
return TRUE
end


So... If u want to make few chests you make few scripts instead of 1 ?;)

@up i know. But for me it looks preety nice xD i wanted to do it in this way x)
 
Back
Top