Jump to content

Problems with Client, and TriggerclientEvent


VenomOG

Recommended Posts

SERER SIDE!
conn = dbConnect( "mysql", "dbname="..tostring(exports["NGSQL"]:getMySQLData()[3])..";host=localhost", tostring(exports["NGSQL"]:getMySQLData()[1]), tostring(exports["NGSQL"]:getMySQLData()[2]), "share=1" )
---exports.NGSQL:db_exec ( "CREATE TABLE IF NOT EXISTS drugdealers (id INT AUTO_INCREMENT KEY, x TEXT, y TEXT, z TEXT, rot INT)" );

dd = {}
col = {}
qry = dbQuery(conn, "SELECT * FROM drugdealers")
pol, pl = dbPoll(qry, -1)
pl = tonumber(pl)
dn = {[14] = "LSD", [13] = "Heroine", [12] = "DMT", [15] = "Weed"}
dn2 = {["LSD"] = 20, ["Heroine"] = 18, ["DMT"] = 21, ["Weed"] = 19}

_createPed = createPed
function createPed(a, b, c, d,e,f)
	local p = _createPed(a, b, c, d,e,f)
	setElementData(p, "PEDNODMG", true)
	return p
end

function tocolor(red, green, blue, alpha)
	if((red < 0 or red > 255 or green < 0 or green > 255 or blue < 0 or blue > 255) or (alpha and (alpha < 0 or alpha > 255))) then
		return false
	end
	if(alpha ~= nil) then
		return "0x"..string.format("%.2X%.2X%.2X%.2X",alpha,red,green,blue)
	else
		return "0x"..string.format("%.2X%.2X%.2X", red,green,blue)
	end
end

function randomize()
	if pl < 4 then ready = false return end
	ready = true
	d1 = math.random(1, pl)
	d2 = math.random(1, pl)
	d3 = math.random(1, pl)
	d4 = math.random(1, pl)
	
end

randomize()
if ready then
while d1 == d2 or d1 == d3 or d1 == d4  or d2 == d3 or d2 == d4 or d3 == d4  do
	randomize()
end


for k, row in ipairs(pol) do
	if(k == d1 or k == d2 or k == d3 or k == d4) then
		dd[row["id"]] = createPed(29, row["x"], row["y"], row["z"], row["rot"], false)
		setElementData(dd[row["id"]], "MarketName", "Drug Dealer")
		col[k] = createColTube(row["x"], row["y"], row["z"]-1, 2, 2)
		createBlipAttachedTo(dd[row["id"]], 24, 2, 0, 0, 0, 0, 0, 200)
		setElementFrozen(dd[row["id"]], true)
		setElementData(dd[row["id"]], "DrugSelling", dn[math.random(12, 15)])
		
		addEventHandler("onPlayerLogin", getRootElement(), function ()
			exports["GTGText"]:create3DTextLabel("Drug Dealer", tocolor(255, 255, 0, 255), row["x"], row["y"], row["z"], 20, 0, "default-bold", 2, source)
		end)
		exports["GTGText"]:create3DTextLabel("Drug Dealer", tocolor(255, 255, 0, 255), row["x"], row["y"], row["z"], 20, 0, "default-bold", 2, root)
		addEventHandler("onElementClicked", dd[row["id"]], function (but, state, player)
		if(but == "left" and state == "down") then
			if(isElementWithinColShape(player, col[k]) and not isPedInVehicle(player)) then
				triggerClientEvent(player, "showDrugs", player, getElementData(source, "DrugSelling"))
			end
		end
		end)
	end
end
end

function hasPlayerDrugSeed(p)
	if (exports["GTGInventory"]:getPlayerItemCount(p, 18) and exports["GTGInventory"]:getPlayerItemCount(p, 18) > 0) or (exports["GTGInventory"]:getPlayerItemCount(p, 19) and exports["GTGInventory"]:getPlayerItemCount(p, 19) > 0) or (exports["GTGInventory"]:getPlayerItemCount(p, 20) and exports["GTGInventory"]:getPlayerItemCount(p, 20) > 0) or (exports["GTGInventory"]:getPlayerItemCount(p, 21) and exports["GTGInventory"]:getPlayerItemCount(p, 21) > 0) then
		return true
	end
	return false
end

addEvent("buyDrug", true)
addEventHandler("buyDrug", getRootElement(), function (drug)
	if getPlayerMoney(source) < 8000 then return end
	if hasPlayerDrugSeed(source) then return exports.GTGMessages:sendClientMessage("Drug Dealer: You already have a drug seed!",source, 255, 0, 0) 
end
	takePlayerMoney(source, 8000)
	exports["GTGInventory"]:addPlayerItem(source, tonumber(dn2[drug]), 1)
	exports.GTGMessages:sendClientMessage("Drug Dealer: You bough a drug seed for 8,000$",source, 0, 255, 0)
end)

addCommandHandler("adddrug", function (thePlayer, cnm, rot)
	if(isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Owner"))) then
		x, y, z = getElementPosition(thePlayer)
		dbExec(conn, "INSERT INTO drugdealers (x, y, z, rot) VALUES (?, ?, ?, ?)", x, y, z, tonumber(rot))
	end
end)


dtimer = setTimer(restartResource, 86400000, 1, getThisResource())

function getDealerTime()
if isTimer(dtimer) then 
	local tl = getTimerDetails(dtimer)
	if tl then
		return math.floor(tl/1000/60)
	end
	return "Already reseted!"
end
end

CLIENT SIDE!
local client = getLocalPlayer()
local drugdesc = {
["LSD"] = "LSD protects you from Bombs",
["Heroine"] = "Heals you each 10 Seconds",
["DMT"] = "DMT makes you semi-invisible",
["Weed"] = "Weed makes you jump high"
}

if isElement(window) then return 
end
window = guiCreateWindow(463,188,330,221,"GTG Drug Dealer", false)
guiWindowSetSizable(window,false)
desc_memo = guiCreateMemo(9, 24, 312, 138, "", false, window)
windowbuy = guiCreateButton(19, 172, 104, 40, "Buy Seed plant", false, window)
windowclose = guiCreateButton(207, 172, 104, 40, "Close", false, window)
guiMemoSetReadOnly(desc_memo,true)
guiSetVisible(window,true)
guiSetText(desc_memo, drugdesc[drug])
addEventHandler("onClientGUIClick",windowclose,function()
if (source == windowclose) then
destroyElement(window)
addEvent("showDrugs", true)
end
end)
end)

okay so, the problem is it wont trigger clientEvent

2- it keeps giving code '(' expected near ')'

3-Line 11 for 2 problem

@DNL291

i tagged you cuz you helped me once

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