Jump to content

[HELP] problem whit GUI and some events


Recommended Posts

Hello everyone, I am trying to design a script for selling drugs, I have 6 types of drugs, which have names in Spanish, they are saved through the setElementData and setAccountData of each user.

To make my drug sales system, the buyer attaches himself to the marker, so he can reference it later when calling other events and get all his information, then when the buyer hits the marker he obtains the information of the seller through the getElementData of the marker and the buyer obtain the seller who is attached to the marker.

At the moment I only made the sale of a drug, the "Bareta" (Weed), it works the first time you make a purchase, then when you click again the following error appears on lines 26-31, which is where you get the numbers from the buyer's panel, and you can not sell more drugs.

https://i.imgur.com/YNAguMT.jpg

I'm a bit overwhelmed, it's my first script that manages to synchronize two users. With all my heart, I would really appreciate the help, thank you very much!

Heres the scripts

--setup_c.lua (client: when the seller sets the price and the ammount to sell whit the command /venderdroga (selldrug) and stop whit /pararventa)

UIEditor = {
    label = {}
}
addEventHandler("onClientResourceStart", resourceRoot,
    function()
        sellDrugsWin = guiCreateWindow(527, 250, 339, 322, "Vender Drogas", false)
        guiWindowSetSizable(sellDrugsWin, false)

        wLabel = guiCreateLabel(27, 54, 63, 17, "Bareta:", false, sellDrugsWin)
        GUIEditor.label[1] = guiCreateLabel(92, 26, 74, 18, "Cantidad", false, sellDrugsWin)
        GUIEditor.label[2] = guiCreateLabel(198, 26, 80, 16, "Precio/unidad", false, sellDrugsWin)
        bQty = guiCreateEdit(90, 54, 72, 17, "0", false, sellDrugsWin)
        bPrice = guiCreateEdit(196, 54, 72, 17, "0", false, sellDrugsWin)
        GUIEditor.label[3] = guiCreateLabel(27, 86, 63, 17, "Popper:", false, sellDrugsWin)
        popperQty = guiCreateEdit(90, 86, 72, 17, "0", false, sellDrugsWin)
        popperPrice = guiCreateEdit(196, 86, 72, 17, "0", false, sellDrugsWin)
        GUIEditor.label[4] = guiCreateLabel(27, 118, 63, 17, "Perica:", false, sellDrugsWin)
        pericaQty = guiCreateEdit(90, 118, 72, 17, "0", false, sellDrugsWin)
        pericaPrice = guiCreateEdit(196, 118, 72, 17, "0", false, sellDrugsWin)
        GUIEditor.label[5] = guiCreateLabel(27, 149, 63, 17, "LSD:", false, sellDrugsWin)
        lsdQty = guiCreateEdit(90, 149, 72, 17, "0", false, sellDrugsWin)
        lsdPrice = guiCreateEdit(196, 149, 72, 17, "0", false, sellDrugsWin)
        GUIEditor.label[6] = guiCreateLabel(27, 181, 63, 17, "Bazuko:", false, sellDrugsWin)
        GUIEditor.label[7] = guiCreateLabel(27, 213, 63, 17, "Heroina:", false, sellDrugsWin)
        bazukoQty = guiCreateEdit(90, 181, 72, 17, "0", false, sellDrugsWin)
        heroinaQty = guiCreateEdit(90, 213, 72, 17, "0", false, sellDrugsWin)
        heroinaPrice = guiCreateEdit(196, 213, 72, 17, "0", false, sellDrugsWin)
        bazukoPrice = guiCreateEdit(196, 181, 72, 17, "0", false, sellDrugsWin)
        sellBtn = guiCreateButton(39, 264, 123, 32, "Vender", false, sellDrugsWin)
        cancelBtn = guiCreateButton(196, 264, 123, 32, "Cerrar", false, sellDrugsWin)    
		guiSetVisible(sellDrugsWin, false)
		addEventHandler ( "onClientGUIClick", cancelBtn, closeWindow, false )
		addEventHandler ( "onClientGUIClick", sellBtn, startSell, false )
    end
)
function startSell()
	dbaretaPrice = tonumber(guiGetText(bPrice))
	dpopperPrice = tonumber(guiGetText(popperPrice))
	dpericaPrice = tonumber(guiGetText(pericaPrice))
	dlsdPrice = tonumber(guiGetText(lsdPrice))
	dbazukoPrice = tonumber(guiGetText(bazukoPrice))
	dheroinaPrice = tonumber(guiGetText(heroinaPrice))
	
	dbaretaQty = tonumber(guiGetText(bQty))
	dpopperQty = tonumber(guiGetText(popperQty))
	dpericaQty = tonumber(guiGetText(pericaQty))
	dlsdQty = tonumber(guiGetText(lsdQty))
	dbazukoQty = tonumber(guiGetText(bazukoQty))
	dheroinaQty = tonumber(guiGetText(heroinaQty))
	
	if type(dbaretaPrice) =="number" and type(dpopperPrice) =="number" and type(dpericaPrice) =="number" and type(dlsdPrice) =="number" and type(dbazukoPrice) =="number" and 
		type(dheroinaPrice) =="number" and type(dbaretaQty) =="number" and type(dpopperQty) =="number" and type(dpericaQty) =="number" and type(dlsdQty) =="number" and 
		type(dbazukoQty) =="number" and type(dheroinaQty) =="number" then
		
		if dbaretaPrice < 0 or dpopperPrice < 0 or dpericaPrice < 0 or dlsdPrice < 0 or dbazukoPrice < 0 or dheroinaPrice < 0 or
		dbaretaQty < 0 or dpopperQty < 0 or dpericaQty < 0 or dlsdQty < 0 or dbazukoQty < 0 or dheroinaQty < 0 then
			return outputChatBox("Ingrese solo numeros positivos")
		else
			setElementData(getLocalPlayer(), "bPrice",dbaretaPrice)
			setElementData(getLocalPlayer(), "popperPrice",dpopperPrice)
			setElementData(getLocalPlayer(), "pericaPrice",dpericaPrice)
			setElementData(getLocalPlayer(), "lsdPrice",dlsdPrice)
			setElementData(getLocalPlayer(), "bazukoPrice",dbazukoPrice)
			setElementData(getLocalPlayer(), "heroinaPrice",dheroinaPrice)
			
			setElementData(getLocalPlayer(), "bQty",dbaretaQty)
			setElementData(getLocalPlayer(), "popperQty",dpopperQty)
			setElementData(getLocalPlayer(), "pericaQty",dpericaQty)
			setElementData(getLocalPlayer(), "lsdQty",dlsdQty)
			setElementData(getLocalPlayer(), "bazukoQty",dbazukoQty)
			setElementData(getLocalPlayer(), "heroinaQty",dheroinaQty)
			
			setElementData(getLocalPlayer(),"sellingDrugs", true)
			guiSetVisible(sellDrugsWin,false) 
			triggerServerEvent("startSellingDrugs",getLocalPlayer())
			
		end
	else
		return outputChatBox("Ingrese solo numeros")
	end

end

function stopSell()
	showCursor(false)
	setElementData(getLocalPlayer(),"sellingDrugs", false)
	triggerServerEvent("stopSellingDrugs",getLocalPlayer())
end
addCommandHandler("pararventa", stopSell ) 

function venderDroga( localPlayer ) 
	if guiGetVisible(sellDrugsWin) == false then
		guiSetVisible ( sellDrugsWin, true) 
		showCursor ( true ) 
	end
end 
addCommandHandler("venderdroga", venderDroga ) 

function closeWindow(localPlayer)
	guiSetVisible(sellDrugsWin, false)
	showCursor(false)
end

--buy_c.lua (client triggers when the buyer hits the marker handled and created in the serverside)

GUIEditor = {
    label = {},
    memo = {}
}
addEventHandler("onClientResourceStart", resourceRoot,
    function()
	buyWin = guiCreateWindow(567, 316, 226, 289, "Comprar Drogas", false)
	guiWindowSetSizable(buyWin, false)
	baretaLabel = guiCreateLabel(24, 36, 63, 15, "Bareta (0)$", false, buyWin)
	popperLabel = guiCreateLabel(24, 65, 77, 16, "Popper (0)$", false, buyWin)
	pericaLabel = guiCreateLabel(24, 95, 63, 15, "Perica (0)$", false, buyWin)
	lsdLabel = guiCreateLabel(24, 126, 63, 15, "Lsd (0)$", false, buyWin)
	bazukoLabel = guiCreateLabel(24, 159, 69, 15, "Bazuko (0)$", false, buyWin)
	heroinaLabel = guiCreateLabel(24, 191, 75, 15, "Heroina (0)$", false, buyWin)
	baretaEdit = guiCreateEdit(120, 36, 52, 19, "0", false, buyWin)
	popperEdit = guiCreateEdit(120, 62, 52, 19, "0", false, buyWin)
	pericaEdit = guiCreateEdit(120, 91, 52, 19, "0", false, buyWin)
	lsdEdit = guiCreateEdit(120, 122, 52, 19, "0", false, buyWin)
	bazukoEdit = guiCreateEdit(120, 155, 52, 19, "0", false, buyWin)
	heroinaEdit = guiCreateEdit(120, 187, 52, 19, "0", false, buyWin)
	buyBtn = guiCreateButton(21, 246, 82, 27, "Comprar", false, buyWin)
	closeBuyBtn = guiCreateButton(120, 246, 82, 27, "Cerrar", false, buyWin)
	totalLabel = guiCreateLabel(59, 216, 99, 15, "Total: 0 $", false, buyWin)  
	guiSetVisible(buyWin,false)
	addEventHandler ( "onClientGUIClick", closeBuyBtn, closeBuyWindow, false )
	addEventHandler ( "onClientGUIClick", buyBtn, buyDrugs, false )
    end
)

function buyDrugs()
baretaEdit = tonumber(guiGetText(baretaEdit)) 
popperEdit = tonumber(guiGetText(popperEdit))  
pericaEdit = tonumber(guiGetText(pericaEdit))
lsdEdit = tonumber(guiGetText(lsdEdit)) 
bazukoEdit = tonumber(guiGetText(bazukoEdit))
heroinaEdit = tonumber(guiGetText(heroinaEdit))

	if type(baretaEdit) =="number" and type(baretaEdit) =="number" and type(baretaEdit) =="number" and type(baretaEdit) =="number" and type(baretaEdit) =="number" and 
		type(baretaEdit) =="number" then
		if baretaEdit < 0 or popperEdit < 0 or pericaEdit < 0 or lsdEdit < 0 or bazukoEdit < 0 or heroinaEdit < 0 then
			return outputChatbox("Ingrese solo numeros positivos")
		else
			setElementData(getLocalPlayer(),"baretaBuyQty", baretaEdit)
			setElementData(getLocalPlayer(),"popperBuyQty", popperEdit)
			setElementData(getLocalPlayer(),"pericaBuyQty", pericaEdit)
			setElementData(getLocalPlayer(),"lsdBuyQty", lsdEdit)
			setElementData(getLocalPlayer(),"bazukoBuyQty", bazukoEdit)
			setElementData(getLocalPlayer(),"heroinaBuyQty", heroinaEdit)
			triggerServerEvent("sBuyDrugs",getLocalPlayer())
			
		end
	else
		return outputChatBox("Ingrese solo numeros")
	end

end

function closeBuyWindow()
	if guiGetVisible(buyWin) then
		guiSetVisible(buyWin,false)
		showCursor(false)
	end
end

function clientOpenBuyWin(seller)
	local sellerBPrice = tonumber(getElementData(seller,"bPrice"))
	local sellerPopperPrice = tonumber(getElementData(seller,"popperPrice"))
	local sellerPericaPrice = tonumber(getElementData(seller,"pericaPrice"))
	local sellerLsdPrice = tonumber(getElementData(seller,"lsdPrice"))
	local sellerBazukoPrice = tonumber(getElementData(seller,"bazukoPrice"))
	local sellerHeroinaPrice = tonumber(getElementData(seller,"heroinaPrice"))
	guiSetVisible(buyWin, true)
	showCursor(true)
	guiSetText(baretaLabel, "Bareta ("..tostring(sellerBPrice)..")$")
	guiSetText(popperLabel, "Popper ("..tostring(sellerPopperPrice)..")$")
	guiSetText(pericaLabel, "Perica ("..tostring(sellerPericaPrice)..")$")
	guiSetText(lsdLabel, "Lsd ("..tostring(sellerLsdPrice)..")$")
	guiSetText(bazukoLabel, "Bazuko ("..tostring(sellerBazukoPrice)..")$")
	guiSetText(heroinaLabel, "Heroina ("..tostring(sellerHeroinaPrice)..")$")
	setElementData(localPlayer,"seller",seller)
end
addEvent( "onServerMarkerHit", true )
addEventHandler( "onServerMarkerHit", localPlayer, clientOpenBuyWin )

--server.lua

function serverStartSellingDrugs() 
    local x, y, z = getElementPosition ( client) 
	local marker =  createMarker ( x, y, z-1, "cylinder", 1.5, 255, 255, 0, 170 ) 
	setElementData(marker, "owner", client)
	attachElementToElement( client, marker)

end  
addEvent( "startSellingDrugs", true ) 
addEventHandler("startSellingDrugs", root , serverStartSellingDrugs) 

function serverStopSellingDrugs()
	local attached = getElementAttachedTo ( client )
    if ( attached ) then
		destroyElement(attached)
    end
end
addEvent( "stopSellingDrugs", true ) 
addEventHandler("stopSellingDrugs", root , serverStopSellingDrugs) 

function buyerMarkerHit( hitElement, matchingDimension ) -- define MarkerHit function for the handler
    if getElementData(source, "owner") ~= nil and  getElementData(source,"owner") ~= false then
		if getPlayerName(hitElement) ~= getPlayerName( getElementData(source, "owner")) then
			triggerClientEvent ( hitElement, "onServerMarkerHit", hitElement, getElementData(source,"owner") )
		end
	end
    
end
addEventHandler( "onMarkerHit", root, buyerMarkerHit )

function serverBuyDrugs()
	local sellerPointer = getElementData(client, "seller")
	if tonumber(getElementData(sellerPointer, "bQty")) >= tonumber(getElementData(client,"baretaBuyQty")) then
		setElementData(sellerPointer,"bQty", tonumber(getElementData(sellerPointer,"bQty"))-tonumber(getElementData(client,"baretaBuyQty")))
		setElementData(client,"Weed",tonumber(getElementData(client,"Weed"))+tonumber(getElementData(client,"baretaBuyQty")))
		givePlayerMoney(sellerPointer, tonumber(getElementData(sellerPointer,"bPrice"))*tonumber(getElementData(client,"baretaBuyQty")))
		setPlayerMoney(client, getPlayerMoney(client) - tonumber(getElementData(sellerPointer,"bPrice"))*tonumber(getElementData(client,"baretaBuyQty")))
	else
		return outputChatBox("El usuario no posee tal cantidad de bareta",client)
	end
end
addEvent( "sBuyDrugs", true ) 
addEventHandler("sBuyDrugs", root , serverBuyDrugs) 

many thanks!

Link to comment
-- buy_c.lua:31-36 @@ function buyDrugs()
-- here baretaEdit refers to a gui-element
baretaEdit = tonumber(guiGetText(baretaEdit)) 
-- now baretaEdit refers to a number
popperEdit = tonumber(guiGetText(popperEdit))  
pericaEdit = tonumber(guiGetText(pericaEdit))
lsdEdit = tonumber(guiGetText(lsdEdit))
bazukoEdit = tonumber(guiGetText(bazukoEdit))
heroinaEdit = tonumber(guiGetText(heroinaEdit))

These lines override the original variables, thus each variable, e.g. baretaEdit, stops being a gui element and becomes the tonumber'd text of the input, and on all subsequent calls to guiGetText, you're passing a number rather than a gui-element.

You should prepend these variable assignments with the local keyword, so that these changes are only visible within the scope of the buyDrugs() function.

-- buy_c.lua:31-36 @@ function buyDrugs()
-- here baretaEdit refers to a gui-element
local baretaEdit = tonumber(guiGetText(baretaEdit)) 
-- here the original baretaEdit is inaccessible directly, and the new baretaEdit refers 
-- the number inputted in the gui-element (this new baretaEdit falls out of scope when 
-- the function exists and is not accessible elsewhere, and doesn't override the 
-- original's value which remains a gui-element and can be accessed using _G["baretaEdit"]
-- (_G is a table of global variables)
local popperEdit = tonumber(guiGetText(popperEdit))  
local pericaEdit = tonumber(guiGetText(pericaEdit))
local lsdEdit = tonumber(guiGetText(lsdEdit))
local bazukoEdit = tonumber(guiGetText(bazukoEdit))
local heroinaEdit = tonumber(guiGetText(heroinaEdit))

This technically doesn't override the value, but the reference to the variable itself. That is, the original variable still exists, it's only inaccessible because a newer one has been created and is in this scope.

As a followup, I'd like to point out that a better way to do this

-- buy_c.lua:43-49 @@ function buyDrugs()
setElementData(getLocalPlayer(),"baretaBuyQty", baretaEdit)
setElementData(getLocalPlayer(),"popperBuyQty", popperEdit)
setElementData(getLocalPlayer(),"pericaBuyQty", pericaEdit)
setElementData(getLocalPlayer(),"lsdBuyQty", lsdEdit)
setElementData(getLocalPlayer(),"bazukoBuyQty", bazukoEdit)
setElementData(getLocalPlayer(),"heroinaBuyQty", heroinaEdit)
triggerServerEvent("sBuyDrugs",getLocalPlayer())

-- server.lua:30-42 @@ function serverBuyDrugs()
function serverBuyDrugs()
  local sellerPointer = getElementData(client, "seller")
  if tonumber(getElementData(sellerPointer, "bQty")) >= tonumber(getElementData(client,"baretaBuyQty")) then
    setElementData(sellerPointer,"bQty", tonumber(getElementData(sellerPointer,"bQty"))-tonumber(getElementData(client,"baretaBuyQty")))
    setElementData(client,"Weed",tonumber(getElementData(client,"Weed"))+tonumber(getElementData(client,"baretaBuyQty")))
    givePlayerMoney(sellerPointer, tonumber(getElementData(sellerPointer,"bPrice"))*tonumber(getElementData(client,"baretaBuyQty")))
    setPlayerMoney(client, getPlayerMoney(client) - tonumber(getElementData(sellerPointer,"bPrice"))*tonumber(getElementData(client,"baretaBuyQty")))
  else
    return outputChatBox("El usuario no posee tal cantidad de bareta",client)
  end
end
addEvent( "sBuyDrugs", true ) 
addEventHandler("sBuyDrugs", root , serverBuyDrugs) 

is to use event parameters

-- buy_c.lua:43-49 @@ function buyDrugs()
triggerServerEvent("sBuyDrugs",getLocalPlayer(), baretaEdit, popperEdit, popperEdit, pericaEdit, lsdEdit, bazukoEdit, heroinaEdit)

-- server.lua:30-42 @@ function serverBuyDrugs()
function serverBuyDrugs(baretaQty, popperQty, pericaQty, lsdQty, bazukoQty, heroinaQty)
  if client then else return false end -- this line aborts the execution of the function if 'client' variable isn't set, that is, the event was faked, and not sent from an actual client
  local sellerPointer = getElementData(client, "seller")
  if tonumber(getElementData(sellerPointer, "bQty")) >= baretaQty then
    setElementData(sellerPointer,"bQty", tonumber(getElementData(sellerPointer,"bQty"))-baretaQty)
    setElementData(client,"Weed",tonumber(getElementData(client,"Weed"))+baretaQty)
    givePlayerMoney(sellerPointer, tonumber(getElementData(sellerPointer,"bPrice"))*baretaQty)
    setPlayerMoney(client, getPlayerMoney(client) - tonumber(getElementData(sellerPointer,"bPrice"))*baretaQty)
  else
    return outputChatBox("El usuario no posee tal cantidad de bareta",client)
  end
end
addEvent( "sBuyDrugs", true ) 
addEventHandler("sBuyDrugs", root , serverBuyDrugs) 

As an additional notice, you should never trust a client - add additional protections like ensuring that the seller is indeed selling drugs at the time a request to "take away his stuff and give it to me for the agreed price" is made.

Edited by Investor
Link to comment
19 hours ago, Investor said:

-- buy_c.lua:31-36 @@ function buyDrugs()
-- here baretaEdit refers to a gui-element
baretaEdit = tonumber(guiGetText(baretaEdit)) 
-- now baretaEdit refers to a number
popperEdit = tonumber(guiGetText(popperEdit))  
pericaEdit = tonumber(guiGetText(pericaEdit))
lsdEdit = tonumber(guiGetText(lsdEdit))
bazukoEdit = tonumber(guiGetText(bazukoEdit))
heroinaEdit = tonumber(guiGetText(heroinaEdit))

These lines override the original variables, thus each variable, e.g. baretaEdit, stops being a gui element and becomes the tonumber'd text of the input, and on all subsequent calls to guiGetText, you're passing a number rather than a gui-element.

You should prepend these variable assignments with the local keyword, so that these changes are only visible within the scope of the buyDrugs() function.


-- buy_c.lua:31-36 @@ function buyDrugs()
-- here baretaEdit refers to a gui-element
local baretaEdit = tonumber(guiGetText(baretaEdit)) 
-- here the original baretaEdit is inaccessible directly, and the new baretaEdit refers 
-- the number inputted in the gui-element (this new baretaEdit falls out of scope when 
-- the function exists and is not accessible elsewhere, and doesn't override the 
-- original's value which remains a gui-element and can be accessed using _G["baretaEdit"]
-- (_G is a table of global variables)
local popperEdit = tonumber(guiGetText(popperEdit))  
local pericaEdit = tonumber(guiGetText(pericaEdit))
local lsdEdit = tonumber(guiGetText(lsdEdit))
local bazukoEdit = tonumber(guiGetText(bazukoEdit))
local heroinaEdit = tonumber(guiGetText(heroinaEdit))

This technically doesn't override the value, but the reference to the variable itself. That is, the original variable still exists, it's only inaccessible because a newer one has been created and is in this scope.

As a followup, I'd like to point out that a better way to do this


-- buy_c.lua:43-49 @@ function buyDrugs()
setElementData(getLocalPlayer(),"baretaBuyQty", baretaEdit)
setElementData(getLocalPlayer(),"popperBuyQty", popperEdit)
setElementData(getLocalPlayer(),"pericaBuyQty", pericaEdit)
setElementData(getLocalPlayer(),"lsdBuyQty", lsdEdit)
setElementData(getLocalPlayer(),"bazukoBuyQty", bazukoEdit)
setElementData(getLocalPlayer(),"heroinaBuyQty", heroinaEdit)
triggerServerEvent("sBuyDrugs",getLocalPlayer())

-- server.lua:30-42 @@ function serverBuyDrugs()
function serverBuyDrugs()
  local sellerPointer = getElementData(client, "seller")
  if tonumber(getElementData(sellerPointer, "bQty")) >= tonumber(getElementData(client,"baretaBuyQty")) then
    setElementData(sellerPointer,"bQty", tonumber(getElementData(sellerPointer,"bQty"))-tonumber(getElementData(client,"baretaBuyQty")))
    setElementData(client,"Weed",tonumber(getElementData(client,"Weed"))+tonumber(getElementData(client,"baretaBuyQty")))
    givePlayerMoney(sellerPointer, tonumber(getElementData(sellerPointer,"bPrice"))*tonumber(getElementData(client,"baretaBuyQty")))
    setPlayerMoney(client, getPlayerMoney(client) - tonumber(getElementData(sellerPointer,"bPrice"))*tonumber(getElementData(client,"baretaBuyQty")))
  else
    return outputChatBox("El usuario no posee tal cantidad de bareta",client)
  end
end
addEvent( "sBuyDrugs", true ) 
addEventHandler("sBuyDrugs", root , serverBuyDrugs) 

is to use event parameters


-- buy_c.lua:43-49 @@ function buyDrugs()
triggerServerEvent("sBuyDrugs",getLocalPlayer(), baretaEdit, popperEdit, popperEdit, pericaEdit, lsdEdit, bazukoEdit, heroinaEdit)

-- server.lua:30-42 @@ function serverBuyDrugs()
function serverBuyDrugs(baretaQty, popperQty, pericaQty, lsdQty, bazukoQty, heroinaQty)
  if client then else return false end -- this line aborts the execution of the function if 'client' variable isn't set, that is, the event was faked, and not sent from an actual client
  local sellerPointer = getElementData(client, "seller")
  if tonumber(getElementData(sellerPointer, "bQty")) >= baretaQty then
    setElementData(sellerPointer,"bQty", tonumber(getElementData(sellerPointer,"bQty"))-baretaQty)
    setElementData(client,"Weed",tonumber(getElementData(client,"Weed"))+baretaQty)
    givePlayerMoney(sellerPointer, tonumber(getElementData(sellerPointer,"bPrice"))*baretaQty)
    setPlayerMoney(client, getPlayerMoney(client) - tonumber(getElementData(sellerPointer,"bPrice"))*baretaQty)
  else
    return outputChatBox("El usuario no posee tal cantidad de bareta",client)
  end
end
addEvent( "sBuyDrugs", true ) 
addEventHandler("sBuyDrugs", root , serverBuyDrugs) 

As an additional notice, you should never trust a client - add additional protections like ensuring that the seller is indeed selling drugs at the time a request to "take away his stuff and give it to me for the agreed price" is made.

Wow, i understand A LOT of things now!, Really thanks @Investor!!!!, and what do you think about my way to trigger and save the Seller user? i dont know if it is the best way to sync the players. i do it attaching the seller to a marker and later ask if isElementAttachedTo, i dont know how to sync 2 or more users. For example, in the server event "onPlayerDamage" i got 2 users, the source(the guy who gets the damage) and the attacker, i want to know if is a best way to make the way to sync seller and buyer or my way is a good idea :D!,
Thank you very much for the explanation, really really appreciate it!

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...