Jump to content
Croqueta

[Q]Itemshop without Mysql

Recommended Posts

Informacion:

Hola a todos aca les traigo una quest de una item shop en el juego. realizada en su totalidad por mi :D

Contiene:

-Historial de Compras(log)

-Historial De Donaciones (log)

-Ingreso Como administrador (Agregar artículos / y quitarlos)

-Tienda: Lecto de coins (Este archivo ha de ser creado manualmente)

-Imagenes:

 

Importante:

 

Dentro de la descarga hay un archivo llamado vnumUtype.txt este se le modifica la extencion a .lua

 

pathti="/usr/home/game/share/locale/germany/quest/test/" <<-- en esta ruta la tabla de la item shop y el vnumUtype.lua

pathtc="/usr/home/game/share/locale/germany/quest/coins/"

 

Se crea una nueva carpeta en las rutas anteriores, que depende de usted.

Más importante aún es un punto que hay que generar la tabla en el juego,

como un ejemplo de la matriz que me queda, por lo que puede orientarse a la misma.

 

special thx on stein20 for help to translate

 

imagen

 

Imagen enviada

 

 

Quest

 

quest ingameshop begin
	state start begin
		when 20006.chat."recharge ccoins" begin
			say_title(mob_name(npc.get_race()))
			spenden()
		end
		when 20006.chat."generate table" with pc.is_gm() begin
			--if pc.get_gm_level()!=5 then return end
			say("really generate table?")
			if select("Yes","No")==2 then return end
			local ingameshop={
			--[[
				if you use this first time, push Yes
			]]
				{--weapons
					{item1,item2},--ids
					{coins1,cois2}--coins
				},
				{--armor
					{item1,item2},--ids
					{coins1,coins2}--coins
				},
				{--special tems
					{item1,item2},--ids
					{coins1,item2}--coins
				}
			}
			table.save(ingameshop,pathti.."testtabelle.lua")
		end
		when 20006.chat."ItemShop" begin
			local name_items={}
			local ingameshop=table.load(pathti.."testtabelle.lua")
			say_title(mob_name(npc.get_race()))
			say()
			say("Choose your category")
			local auswahl=select3(itemshopk)
			for i=1,table.getn(ingameshop[auswahl][1]) do
				table.insert(name_items,tostring(item_name(ingameshop[auswahl][1][i])))
			end
			say_title(mob_name(npc.get_race()))
			say()
			say("select the item ")
			say()
			local itemshop_i = select3(name_items)
			if itemshop_i == table.getn(name_items) then return end
			say_title(string.format("Coins :%d ", get_coins()))
			say()
			say("Would you really buy the item?")
			say()
			say_gold("it cost  "..ingameshop[auswahl][2][itemshop_i].." Coins")
			say_item_vnum(ingameshop[auswahl][1][itemshop_i])
			say("")
			if select("Yes","No") == 2 then return end
			if get_coins()<ingameshop[auswahl][2][itemshop_i] then
				say("not enough coins ")
				return
			end
			say_green("you have buy "..item_name(ingameshop[auswahl][1][itemshop_i]).." for- ")
			say_green(ingameshop[auswahl][2][itemshop_i].." Coins")
			say_item_vnum(ingameshop[auswahl][1][itemshop_i])
			coins_write((get_coins()-ingameshop[auswahl][2][itemshop_i]))
			pc.give_item2(ingameshop[auswahl][1][itemshop_i])
			write_log(ingameshop[auswahl][1][itemshop_i],ingameshop[auswahl][2][itemshop_i])
		end
		when 20006.chat."Manage Itemshop" with pc.is_gm() begin
			local tabelle=table.load(pathti.."vnumUtype.lua")
			local i_shop=table.load(pathti.."testtabelle.lua")
			say_title(mob_name(npc.get_race()))
			say()
			say("Hello "..string.format("%s",pc.get_name()))
			say("What would you like do?")
			local s=select("add new items","removing Items","Nothig")
			if s==3 then return end
			if s==1 then
				say_title(mob_name(npc.get_race()))
				say()
				say("Choose a category")
				say("where you want to add the item")
				local auswahl=select3(itemshopk)
				say_title(mob_name(npc.get_race()))
				say()
				say(itemshopk[auswahl]..": insert into this category?")
				if select("Yes","No") == 2 then return end
				say_title(mob_name(npc.get_race()))
				say()
				say("Which item you wish to add?")
				say("Enter the vnum")
				local vnum= tonumber(input())
				if vnum ==nil then say("You have to enter something") return end
				if auswahl== 1 then
					if tabelle[vnum][1] != 1 then
						say("This is not a weapon")
						return
					end
				elseif auswahl == 2 then
					if tabelle[vnum][1] != 2 then
						say("This is not a amor")
						return
					end
				elseif auswahl == 3 then
					if tabelle[vnum][1] == 1 or tabelle[vnum][1]==2 then
						say("only for special items")
						return
					end
				end
				say_title(mob_name(npc.get_race()))
				say()
				say("Give the price of that item")
				say()
				local money= tonumber(input())
				if money==nil then say("You have to enter something") return end
				say_title(mob_name(npc.get_race()))
				say()
				say("keeping?")
				say()
				say("Item: "..item_name(vnum).." Price: "..money)
				say_item_vnum(vnum)
				if select("Yes","No") == 2 then return end				
				i_shop[auswahl][1][table.getn(i_shop[auswahl][1])+1]=vnum
				i_shop[auswahl][2][table.getn(i_shop[auswahl][2])+1]=money
				--table.insert(i_shop[auswahl][1],vnum)
				--table.insert(i_shop[auswahl][2],money)
				table.save(i_shop,pathti.."testtabelle.lua")
				say("you have add "..item_name(vnum))
			elseif s==2 then
				local auswahl_items={}
				say("Choose the item that you wish to remove")
				say()
				local a=select3(itemshopk)
				for i=1,table.getn(i_shop[a][1]) do
					table.insert(auswahl_items,tostring(item_name(i_shop[a][1][i])))
				end
				say("Choose the item that you wish to remove")
				say()
				local itemshop_r = select3(auswahl_items)
				if itemshop_r==table.getn(auswahl_items) then return end
				table.remove(i_shop[a][1],i_shop[a][1][itemshop_r])
				table.remove(i_shop[a][2],i_shop[a][2][itemshop_r])
				table.save(i_shop,pathti.."testtabelle.lua")
				--[[for i= 1,table.getn(ingameshop[auswahl][1]) do
					say(i_shop[auswahl][1][i].."\t"..i_shop[auswahl][2][i])
				end]]
			end
		end
	end
end

questlib.lua

 

pathti="/usr/home/game/share/locale/germany/quest/test/"--ruta de la tabla
pathtc="/usr/home/game/share/locale/germany/quest/coins/"--ruta de los coins
itemshopk={"Waffe","Rüstungen","Sonstiges"}
function write_log(vnum,coins)
	local i_name=item_name(vnum)
	datei = io.open(pathti.."shop_log.lua", "a+")
	if datei==nil then
		say("Error loading the file")
		return
	end
	datei:write("PLayerID:\t"..pc.get_player_id().."\tPlayerName:\t"..pc.get_name().."\tItemName:\t"..i_name.."\tDate/Time:\t"..os.date("%c").."\tCoins:\t"..coins.."\n")
	datei:close()
end

function get_coins()
	local file = io.open(pathtc..""..pc.get_player_id()..".txt",'r')
	if file==nil then
		return 0
	end
	for line in file:lines() do
		return line
	end
	file:close()
end
function coins_write(coins)
	file = io.open(pathtc..""..pc.get_player_id()..".txt","w")
	file:write(coins)
	file:close()
end
function spenden()
	say()
	say("How much you want to donate?")
	say_reward("Online Paysafecard will not be accepted")
	say()
	s = select("10","25","50","100","cancel")
	wert = { 10 , 25 , 50 , 100}
	if s==table.getn(wert)+1 then return end
	say_title(mob_name(20006))
	say()
	say("Now give the PSC numbers")
	say()
	eing2= input()
	if string.len(eing2)~=16 then
		say("Your input has no 16 numbers")
		return
	end
	if string.sub(eing2,0,1)=='1' or string.sub(eing2,0,2)=='00' then
		say("Online Paysafecard will not be accepted")
		return
	end
	say_title(mob_name(20006))
	say()
	say('The PSC is protected with a password?')
	if select("Yes","No")==2 then
		eing3=0
	else
		say("Enter the password")
		eing3 = input()
		if eing3=='' then say("You have to enter something") return end
	end
	say()
	say("Your input:")
	say("cash: "..wert[s])
	say("PSC: "..eing2)
	if eing3 == 0 then
		say("PW: /")
	else
		say("PW: "..eing3)
	end
	say("Keeping?")
	say()
	if select("Yes","No") == 2 then return end
	say("your Coins will be credited to you after the control")
	file = io.open(pathti.."psc_log.lua","a+")
	--file:write("PlayerName:\t"..pc.get_name().."\tCash:\t"..wert[s].."\tPSC:\t"..eing2.."\tPW:\t"..eing3.."\tDate/Time:\t"..os.date("%c").."\n")
	file:write("ID:\t"..pc.get_player_id().."PlayerName:\t"..pc.get_name().."\tCash:\t"..wert[s].."\tPSC:\t"..eing2.."\tPW:\t"..eing3.."\tDate:\t"..os.date("%c").."\t\n")
	file:close()
end

function select3(...)
	arg.n = nil
	local tp,max = arg,5
	if type(tp[1]) == 'number' then
		max = tp[1]
		if type(tp[2]) == 'table' then
			tp = tp[2]
		else
			table.remove(tp,1)
		end
	elseif type(tp[1]) == 'table' then
		if type(tp[1][1]) == 'number' then
			max = tp[1][1]
			table.remove(tp[1],1)
			tp = tp[1]
		end
		tp = tp[1]
	end
	local str = '{'
	local tablen,act,incit = table.getn(tp),0,0
	table.foreach(tp,function(i,l)
		act = act + 1
		if act == 1 then
			str = str .. '{'..string.format('%q',l)
		elseif act == max+1 and tablen > act+incit then
			if tablen ~= act+incit+1 then
				str = str..'},{'..string.format('%q',l)
			else
				str=str..','..string.format('%q',l)
			end
			incit = incit + max
			act = 1
		else
			str=str..','..string.format('%q',l)
		end
	end)
	local px = loadstring('return '..str ..'}}')()
	local function copy_tab(t) local p= {} for i = 1,table.getn(t) do p[i] = t[i] end return p end
	local pe = {}
	for i = 1,table.getn(px) do pe [i] = copy_tab(px[i]) end
	local function init(i,ip)
		pe[i] = copy_tab(px[i])
		local next,back,exit = 0,0,0
		if i < table.getn(pe) and table.getn(pe) ~=1 then  table.insert(pe[i],table.getn(pe[i])+1,'Para alante Pagina '..(i+1)); next = table.getn(pe[i]) end
		if i > 1 then table.insert(pe[i],table.getn(pe[i])+1,'Para atraz pagina '..(i-1)); back = table.getn(pe[i]) end
		table.insert(pe[i],table.getn(pe[i])+1,'Cerrar'); exit = table.getn(pe[i])
		if table.getn(pe) > 1 then
			say('pagina '..i..' de '..table.getn(pe))
		end
		local e = select_table(pe[i])
		if e == next then return init(i+1,ip+max)
		elseif e == back then return init(i-1,ip-max)
		elseif e == exit then return -1
		else return e+ip,pe[i][e] end
	end
	return init(1,0) or -1
end
local function exportstring( s )
	return string.format("%q", s)
end
function table.save(  tbl,filename )
	local charS,charE = "   ","\n"
	local file,err = io.open( filename, "wb" )
	if err then return err end
	local tables,lookup = { tbl },{ [tbl] = 1 }
	file:write( "return {"..charE )
	for idx,t in ipairs( tables ) do
		file:write( "-- Table: {"..idx.."}"..charE )
		file:write( "{"..charE )
		local thandled = {}
		for i,v in ipairs( t ) do
			thandled[i] = true
			local stype = type( v )
			if stype == "table" then
				if not lookup[v] then
					table.insert( tables, v )
					lookup[v] = table.getn(tables)
				end
				file:write( charS.."{"..lookup[v].."},"..charE )
			elseif stype == "string" then
				file:write(  charS..exportstring( v )..","..charE )
			elseif stype == "number" then
				file:write(  charS..tostring( v )..","..charE )
			end
		end
		for i,v in pairs( t ) do
			if (not thandled[i]) then
				local str = ""
				local stype = type( i )
				if stype == "table" then
					if not lookup[i] then
						table.insert( tables,i )
						lookup[i] = table.getn(tables)
					end
					str = charS.."[{"..lookup[i].."}]="
				elseif stype == "string" then
					str = charS.."["..exportstring( i ).."]="
				elseif stype == "number" then
					str = charS.."["..tostring( i ).."]="
				end
				if str ~= "" then
					stype = type( v )
					if stype == "table" then
						if not lookup[v] then
							table.insert( tables,v )
							lookup[v] = table.getn(tables)
						end
						file:write( str.."{"..lookup[v].."},"..charE )
					elseif stype == "string" then
						file:write( str..exportstring( v )..","..charE )
					elseif stype == "number" then
						file:write( str..tostring( v )..","..charE )
					end
				end
			end
		end
		file:write( "},"..charE )
	end
	file:write( "}" )
	file:close()
end
function table.load( sfile )
	local ftables,err = loadfile( sfile )
	if err then return _,err end
	local tables = ftables()
		for idx = 1,table.getn(tables) do
			local tolinki = {}
			for i,v in pairs( tables[idx] ) do
				if type( v ) == "table" then
					tables[idx][i] = tables[v[1]]
				end
				if type( i ) == "table" and tables[i[1]] then
					table.insert( tolinki,{ i,tables[i[1]] } )
				end
			end
			for _,v in ipairs( tolinki ) do
				tables[idx][v[2]],tables[idx][v[1]] =  tables[idx][v[1]],nil
			end
		end
	return tables[1]
end

quest_function

 

write_log
get_coins
coins_write
spenden
select3
table.save
table.load

http-~~-//www.youtube.com/watch?v=5avAKriuCTg

Debes iniciar sesión para ver el contenido del enlace en esta publicación.

Share this post


Link to post
Share on other sites

como el lo queria aser si la quest la escribi yo?

 

Debes iniciar sesión para ver el contenido del enlace en esta publicación.

Pues esta ahí.

Share this post


Link to post
Share on other sites

Hola está muy interesante esta quest, pero tengo una duda, solo se puede usar si se recarga las coins por el método que trae? No se podría poner que lea y descuente las coins desde la tabla account?Muchas gracias de antemano.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...