Jump to content

[HELP] DayZ - Shop system


Recommended Posts

Hi, I have a problem with a script currently it accepts an elementdata as its currency.

 

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);

 

I tried changing the variable to 

currency_item = getPlayerMoney(source);

 

but I don't see it working. anything I'm missing? Please assist me :) 

Edited by Mischief-1
Link to comment
  • Mischief-1 changed the title to [HELP] DayZ - Shop system

function onClientSuccessBuysItem(target,item,currency,amount,price)

 setElementData(target,item,getElementData(target,item)+amount)

 setElementData(target,"money",getElementData(target,"money")-price) -- or takePlayerMoney(target, price)

end

addEvent("DayZPH:onClientSuccessBuysItem",true)

addEventHandler("DayZPH:onClientSuccessBuysItem",getRootElement(),onClientSuccessBuysItem)

 

  • Thanks 1
Link to comment
Posted (edited)
55 minutes ago, dev645 said:

function onClientSuccessBuysItem(target,item,currency,amount,price)

 setElementData(target,item,getElementData(target,item)+amount)

 setElementData(target,"money",getElementData(target,"money")-price) -- or takePlayerMoney(target, price)

end

addEvent("DayZPH:onClientSuccessBuysItem",true)

addEventHandler("DayZPH:onClientSuccessBuysItem",getRootElement(),onClientSuccessBuysItem)

 

Hello, thanks for the response, I tried doing this code

takePlayerMoney(target, price)

on server side earlier. but the shop stops working. 

 

 

This is the full code I have; can you take a look please? 

client side

clientside - Pastebin.com

 

server side

server side - shop system - Pastebin.com

 

Edited by Mischief-1
code too long
Link to comment
1 hour ago, dev645 said:

If you have a HUD that displays the player's money, then post the code from there here

 

 

addEventHandler("onClientResourceStart", resourceRoot,
    function()    
    end
)
addEventHandler("onClientRender", root,
    function()
	    local cash = getPlayerMoney( getLocalPlayer() )
        dxDrawText("PHP:",   625,   104,  688, 128, tocolor(35, 98, 36, 255), 0.50, "bankgothic", "left", "top", false, false, false, false, false)
        dxDrawText(""..cash,  704,104,796,123, tocolor(255, 255, 255, 255), 0.50, "bankgothic", "left", "top", false, false, false, false, false)
    end
)

 

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

It should work, if there are problems show debug. To enable it, type debugscript 3 in the console

Link to comment
Posted (edited)
41 minutes ago, dev645 said:
function onClientSuccessBuysItem(target,item,currency,amount,price)
 setElementData(target,item,getElementData(target,item)+amount)
 takePlayerMoney(target, price)
end
addEvent("DayZPH:onClientSuccessBuysItem",true)
addEventHandler("DayZPH:onClientSuccessBuysItem",getRootElement(),onClientSuccessBuysItem)

It should work, if there are problems show debug. To enable it, type debugscript 3 in the console

 

here is a snippet when trying to buy

https://ibb.co/fv5JpbZ

edit:

I was able to have it work by removing local variable currency_item on clientside and directly calling the 

getPlayerMoney(source)

 

I am currently trying to fix the gui right now as it currently does not display the money.
will update once finished

Edited by Mischief-1
Link to comment
Posted (edited)
addEventHandler("onClientElementDataChange",root,function(data)
	if getElementData(localPlayer, "logedin") then
		if (string.find(data,getPlayerMoney(source))) then
			guiSetText(shop_gui.label[1], " Pesos (PHP): "..getPlayerMoney(source))
		end
	end
end)

 

Update: this is the code, may I know what I did wrong?

Edited by Mischief-1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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