Jump to content

[HELP] DayZ - Shop system


Recommended Posts

Olá, estou com um problema com um script que atualmente aceita elementdata como moeda.

 

local currency_item = "zombieskilled";


if (guiGridListGetSelectedItem(shop_gui.gridlist[2] ) == -1) then
		guiSetText(shop_gui.label[4],"Please select an item")
		guiLabelSetColor (shop_gui.label[4],255,0,0)
	else
		if (shop_marker_type == "supply") then
			local target = localPlayer;
			local item = guiGridListGetItemText(shop_gui.gridlist[2], guiGridListGetSelectedItem(shop_gui.gridlist[2]),1)
			local amount,price,itemdata = unpack(guiGridListGetItemData(shop_gui.gridlist[2], guiGridListGetSelectedItem(shop_gui.gridlist[2]),2))
			guiLabelSetColor(shop_gui.label[4],255,0,0)

			if (getElementData(localPlayer, currency_item) >= price) then
				guiSetText(shop_gui.label[4],"You successfully bought "..item..".")
				guiLabelSetColor (shop_gui.label[4],0,149,14,255)
				triggerServerEvent("DayZPH:onClientSuccessBuysItem",localPlayer,target,itemdata,currency_item,amount,price)
			else
				guiSetText(shop_gui.label[4],"You don't have enough money (PHP) to buy utilities")
			end
		elseif (shop_marker_type == "vehicle") then
			local target = localPlayer;
			local vehicleName = guiGridListGetItemText(shop_gui.gridlist[2], guiGridListGetSelectedItem(shop_gui.gridlist[2]),1)
			local id,engine,rotor,tires,tankparts,scrap,slots,fuel,price = unpack(guiGridListGetItemData(shop_gui.gridlist[2],guiGridListGetSelectedItem(shop_gui.gridlist[2]),1))
			local x,y,z,rx,ry,rz = unpack(vehicle_spawn_position)
			guiLabelSetColor(shop_gui.label[4],255,0,0)
			if (getElementData(localPlayer,currency_item) >= price) then
				for i,v in ipairs(getElementsWithinColShape(vehicle_spawn_position_col[shop_marker],"vehicle")) do
					guiSetText(shop_gui.label[4],"Vehicle spawn area is taken, clear it before buying vehicle.")
					return
				end
				guiSetVisible(shop_gui.window[1],false)
				showCursor(false)
				outputChatBox("You successfully bought "..vehicleName..".",0,255,0)
				triggerServerEvent("DayZPH:onClientSuccessBuysVehicle",localPlayer,target,currency_item,price,x,y,z,rx,ry,rz,id,engine,rotor,tires,tankparts,scrap,slots,fuel)
			else
				guiSetText(shop_gui.label[4], "You don't have enough money (PHP) to buy a car")
			end
		end
	end

 

server side

function onClientSuccessBuysItem(target,item,currency,amount,price)
	setElementData(target,item,getElementData(target,item)+amount)
	setElementData(target,currency,getElementData(target,currency)-price)
end
addEvent("DayZPH:onClientSuccessBuysItem",true)
addEventHandler("DayZPH:onClientSuccessBuysItem",getRootElement(),onClientSuccessBuysItem)



addEventHandler("onPlayerLogin",root,function()
	triggerClientEvent(source,"load_shop",source);
end);

 

Eu tentei mudar a variável para

currency_item = getPlayerMoney(source);

 

mas não vejo isso funcionando. alguma coisa que estou perdendo? Por favor me ajude :)

 

veja o código completo

 

client

  Reveal hidden contents

server

  Reveal hidden contents

 

Edited by Lord Henry
Links dos códigos convertidos em código Lua.
Link to comment
  • Other Languages Moderators

Olha... vc só mudou 1 variável. Mas não trocou os getElementData/setElementData para getPlayerMoney/setPlayerMoney.

Além disso, getPlayerMoneysetPlayerMoney devem ser feitos server-side somente. Então você precisará de triggerServerEvent ali no script client-side para chamar um evento lá no server-side para mexer no dinheiro no jogador. Até pq tentar setar dinheiro no jogador via client-side só mudará na Hud, mas não vai mudar no servidor, então o dinheiro que aparece na Hud não será a quantidade real que ele tem no servidor.

Edited by Lord Henry
  • Like 1
Link to comment
  • Other Languages Moderators

Client:

  Reveal hidden contents

Server:

  Reveal hidden contents

 

Link to comment
  On 09/04/2024 at 18:56, Lord Henry said:

Client:

  Reveal hidden contents

Server:

  Reveal hidden contents

 

Expand  

Agradeço sua resposta, também consegui descobrir isso.

o que fiz foi chamar "getPlayerMoney (source)" pelo resto do tempo, em vez de criar uma variável local.

este tópico pode ser fechado agora :)

foi assim que eu fiz, trecho de exemplo

if (getPlayerMoney(source) >= price) then
				guiSetText(shop_gui.label[4],"You successfully bought "..item..".")
				guiLabelSetColor (shop_gui.label[4],0,149,14,255)
				triggerServerEvent("DayZPH:onClientSuccessBuysItem",localPlayer,target,itemdata,getPlayerMoney(source),amount,price)
			else
				guiSetText(shop_gui.label[4],"You don't have enough money (PHP) to buy utilities")

 

Edited by Mischief-1
Link to comment
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...