Jump to content
colcrt

[ayuda] funcion create_item

Recommended Posts

hola a [email protected]

 

veran estoy un poco liado con un funcion que necesito algun alma caritativa que me quiera ayudar :D :D  nose como hacer basicamente necesito una funcion create_item que lo que haga es procesar esto

if create_item(Item[1].vnum, Item[1].count, attrs, sockets, cell) == true then

tomando los valores, que recoge de otras funciones

if (cell >= 0) then
	local sockets = {Item[1].socket0, Item[1].socket1, Item[1].socket2}
	local attrs = {{Item[1].attrtype0, Item[1].attrvalue0}, {Item[1].attrtype1, Item[1].attrvalue1}, {Item[1].attrtype2, Item[1].attrvalue2}, {Item[1].attrtype3, Item[1].attrvalue3}, {Item[1].attrtype4, Item[1].attrvalue4}, {Item[1].attrtype5, Item[1].attrvalue5}, {Item[1].attrtype6, Item[1].attrvalue6}} 
	if create_item(Item[1].vnum, Item[1].count, attrs, sockets, cell) == true then
	      game.query("DELETE FROM player.shop_items WHERE shop_id = '"..tonumber(shop_id).."' AND owner_id = '"..pc.get_player_id().."' AND pos = '"..tonumber(pos).."';")
	end

Share this post


Link to post
Share on other sites

Qué es lo que debe chequear esa función para que retorne true?

 

mira esta es la funcion completa en la quest

function getItem(shop_id, pos)
	Item = game.query("SELECT * FROM player.shop_items WHERE shop_id = '"..tonumber(shop_id).."' AND owner_id = '"..pc.get_player_id().."' AND pos = '"..tonumber(pos).."';")
	        if Item == nil or table.getn(Item) == 0 then
		 return
		else
		    if (tonumber(Item[1].status) == 1) then
			syschat("eso seria maravilloso...")
			return
		    else
			local cell = pc.enough_inventory2(Item[1].vnum)
			     if (cell >= 0) then
				local sockets = {Item[1].socket0, Item[1].socket1, Item[1].socket2}
				local attrs = {{Item[1].attrtype0, Item[1].attrvalue0}, {Item[1].attrtype1, Item[1].attrvalue1}, {Item[1].attrtype2, Item[1].attrvalue2}, {Item[1].attrtype3, Item[1].attrvalue3}, {Item[1].attrtype4, Item[1].attrvalue4}, {Item[1].attrtype5, Item[1].attrvalue5}, {Item[1].attrtype6, Item[1].attrvalue6}} 
				     if create_item(Item[1].vnum, Item[1].count, attrs, sockets, cell) == true then
					game.query("DELETE FROM player.shop_items WHERE shop_id = '"..tonumber(shop_id).."' AND owner_id = '"..pc.get_player_id().."' AND pos = '"..tonumber(pos).."';")
					end
				     end
			     end
		    end
	       end

Share this post


Link to post
Share on other sites

 

mira esta es la funcion completa en la quest

function getItem(shop_id, pos)
	Item = game.query("SELECT * FROM player.shop_items WHERE shop_id = '"..tonumber(shop_id).."' AND owner_id = '"..pc.get_player_id().."' AND pos = '"..tonumber(pos).."';")
	        if Item == nil or table.getn(Item) == 0 then
		 return
		else
		    if (tonumber(Item[1].status) == 1) then
			syschat("eso seria maravilloso...")
			return
		    else
			local cell = pc.enough_inventory2(Item[1].vnum)
			     if (cell >= 0) then
				local sockets = {Item[1].socket0, Item[1].socket1, Item[1].socket2}
				local attrs = {{Item[1].attrtype0, Item[1].attrvalue0}, {Item[1].attrtype1, Item[1].attrvalue1}, {Item[1].attrtype2, Item[1].attrvalue2}, {Item[1].attrtype3, Item[1].attrvalue3}, {Item[1].attrtype4, Item[1].attrvalue4}, {Item[1].attrtype5, Item[1].attrvalue5}, {Item[1].attrtype6, Item[1].attrvalue6}} 
				     if create_item(Item[1].vnum, Item[1].count, attrs, sockets, cell) == true then
					game.query("DELETE FROM player.shop_items WHERE shop_id = '"..tonumber(shop_id).."' AND owner_id = '"..pc.get_player_id().."' AND pos = '"..tonumber(pos).."';")
					end
				     end
			     end
		    end
	       end

 

No me has respondido. Te he preguntado qué es lo que quieres que haga la función create_item, ya que con ese nombre no debería de retornar nada... y tu quieres que retorne true.

Share this post


Link to post
Share on other sites

No me has respondido. Te he preguntado qué es lo que quieres que haga la función create_item, ya que con ese nombre no debería de retornar nada... y tu quieres que retorne true.

 

xD crear el item con los datos que recoge de la db, hay es donde nose por que mira es una shop offline si alguien compra el item que es para este caso lo que aria esa funcio es crear el item entregarlo y retornar true para eliminarlo de la db osea que se vendio y se entrego nose si me explico... creo que ya estoy en mi limite de programacion jejeje

 

pdt ------> olvide mencionar aqui es donde llamo esa funcion

if (private_shops.checkVariables(data, 2) == true and data[1] == "GET_ITEM") then
     if (private_shops.isMyShop(tonumber(data[2])) == true) then
	private_shops.getItem(tonumber(data[2]), tonumber(data[3]))
	private_shops.RefreshItems(tonumber(data[2]))
     end
end

Share this post


Link to post
Share on other sites

No hace falta crear una nueva función para eso. Puedes usar pc.give_item2_select(vnum, count) y luego item.set_value(index, applytype, applyvalue) e item.set_socket(index, socket). Btw, no hace falta chequear el hueco libre que puedes usar en el inventario, la función para dar el item ya lo hace.

 

Saludos!

Share this post


Link to post
Share on other sites

hola, hice esta func rapidamente en lua con las funciones q dice shang, puedes probarla

 

--[[
	Author: PACI
	Description: Creates an item with selected item attributes and sockets.
	Returns two args: boolean, int
	Syntax:
		Example 1 - Without item count (default 1):
			local item_created, errorType = create_item(19)

			if item_created then
				syschat("Item given to the player succesfully")
			else
				syschat("Something wrong happend, errorType is: "..errorType)
			end

			>> Gives the player an item with the vnum 19.

		Example 2 - Without attributes nor sockets:
			local item_created, errorType = create_item(19, 1)
			if item_created then
				syschat("Item given to the player succesfully")
			else
				syschat("Something wrong happend, errorType is: "..errorType)
			end
			>> Gives the player 1x the item 19

		Example 3 - Only Attributes:
			local itemAttributes = {
				{1, 2000}, -- 2.000 MÁX HP
				{17, 15},  -- 15 Half-Humans
			--  {attrType, attrValue},	
			}

			local item_created, errorType = create_item(19, 1, itemAttributes)
			if item_created then
				syschat("Item given to the player succesfully")
			else
				syschat("Something wrong happend, errorType is: "..errorType)
			end

		Example 4 - Attributes and Sockets:
			local itemAttributes = {
				{1, 2000}, -- 2.000 MÁX HP
				{17, 15},  -- 15 Half-Humans
			--  {attrType, attrValue},	
			}

			local itemSockets = {28301, 28317, 28302}

			local item_created, errorType = create_item(19, 1, itemAttributes, itemSockets)
			if item_created then
				syschat("Item given to the player succesfully")
			else
				syschat("Something wrong happend, errorType is: "..errorType)
			end

		Example 5 - Only Sockets:
			local itemSockets = {28301, 28317, 28302}

			local item_created, errorType = create_item(19, 1, {}, itemSockets)
			if item_created then
				syschat("Item given to the player succesfully")
			else
				syschat("Something wrong happend, errorType is: "..errorType)
			end

]]
function create_item(itemVnum, itemCount, itemAttributes, itemSockets)
	local function _error(str, ret)
		if pc.is_gm() then 
			syschat("lua.create_item.error: "..str..": returned "..ret)
			return false, ret
		end
	end

	if not itemVnum or itemVnum == 0 then
		return _error("not enough arg (itemVnum == 0)", -3)
	elseif type(itemCount) ~= "number" then
		return _error("itemCount must be a number", -2)
	elseif not itemCount or itemCount == 0 then
		itemCount = 1
	end

	itemAttributes = itemAttributes or {}
	itemSockets = itemSockets or {}

	pc.give_item2_select(itemVnum, itemCount)

	if table.getn(itemAttributes) > 0 then
		for i = 1, table.getn(itemAttributes) do
			if table.getn(itemAttributes[i]) < 2 then
				return _error("itemAttributes["..i.."] is not fully defined, need 2 arguments: {attrType, attrValue}", -1)
			end
			item.set_value(i-1, itemAttributes[i][1], itemAttributes[i][2])
		end
	end

	if table.getn(itemSockets) > 0 then
		for i = 1, table.getn(itemSockets) do
			if not itemSockets[i] then
				return _error("itemSockets are not fully defined", 0)
			end
			item.set_socket(i-1, itemSockets[i])
		end
	end

	return true, 1
end

Share this post


Link to post
Share on other sites

hola, hice esta func rapidamente en lua con las funciones q dice shang, puedes probarla

 

[spoiler]--[[
Author: PACI
Description: Creates an item with selected item attributes and sockets.
Returns two args: boolean, int
Syntax:
Example 1 - Without item count (default 1):
local item_created, errorType = create_item(19)

if item_created then
syschat("Item given to the player succesfully")
else
syschat("Something wrong happend, errorType is: "..errorType)
end

>> Gives the player an item with the vnum 19.

Example 2 - Without attributes nor sockets:
local item_created, errorType = create_item(19, 1)
if item_created then
syschat("Item given to the player succesfully")
else
syschat("Something wrong happend, errorType is: "..errorType)
end
>> Gives the player 1x the item 19

Example 3 - Only Attributes:
local itemAttributes = {
{1, 2000}, -- 2.000 MÁX HP
{17, 15}, -- 15 Half-Humans
-- {attrType, attrValue},
}

local item_created, errorType = create_item(19, 1, itemAttributes)
if item_created then
syschat("Item given to the player succesfully")
else
syschat("Something wrong happend, errorType is: "..errorType)
end

Example 4 - Attributes and Sockets:
local itemAttributes = {
{1, 2000}, -- 2.000 MÁX HP
{17, 15}, -- 15 Half-Humans
-- {attrType, attrValue},
}

local itemSockets = {28301, 28317, 28302}

local item_created, errorType = create_item(19, 1, itemAttributes, itemSockets)
if item_created then
syschat("Item given to the player succesfully")
else
syschat("Something wrong happend, errorType is: "..errorType)
end

Example 5 - Only Sockets:
local itemSockets = {28301, 28317, 28302}

local item_created, errorType = create_item(19, 1, {}, itemSockets)
if item_created then
syschat("Item given to the player succesfully")
else
syschat("Something wrong happend, errorType is: "..errorType)
end

]]
function create_item(itemVnum, itemCount, itemAttributes, itemSockets)
local function _error(str, ret)
if pc.is_gm() then
syschat("lua.create_item.error: "..str..": returned "..ret)
return false, ret
end
end

if not itemVnum or itemVnum == 0 then
return _error("not enough arg (itemVnum == 0)", -3)
elseif type(itemCount) ~= "number" then
return _error("itemCount must be a number", -2)
elseif not itemCount or itemCount == 0 then
itemCount = 1
end

itemAttributes = itemAttributes or {}
itemSockets = itemSockets or {}

pc.give_item2_select(itemVnum, itemCount)

if table.getn(itemAttributes) > 0 then
for i = 1, table.getn(itemAttributes) do
if table.getn(itemAttributes[i]) < 2 then
return _error("itemAttributes["..i.."] is not fully defined, need 2 arguments: {attrType, attrValue}", -1)
end
item.set_value(i-1, itemAttributes[i][1], itemAttributes[i][2])
end
end

if table.getn(itemSockets) > 0 then
for i = 1, table.getn(itemSockets) do
if not itemSockets[i] then
return _error("itemSockets are not fully defined", 0)
end
item.set_socket(i-1, itemSockets[i])
end
end

return true, 1
end[/spoiler]

 

la voy a probar, pero esta genial gracias PACI :D

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...