darbka2002 Posted February 27, 2016 Share Posted February 27, 2016 سلام عليكم انا عملت لوحة بسيطة بس المشكلة اللوحة تفتح معا الادمن كل حاجة وى مع الاونر الخاص با البنك لكن المشكلة ان لو واحد عادى ماهو اونر البانك او ادمن ما تفتح معة اللوحة عشان يشترى ممكن مساعدة addEvent("business.showBusinessWindow", true); addEventHandler("business.showBusinessWindow", root, function(b_marker, is_owner, is_admin) local b_data = b_marker:getData("b_data"); local id, name, owner, cost, payout, payout_time, payout_otime, payout_unit, bank, timer = unpack(b_data); local x, y, z = b_marker.position; if #tostring(id) == 1 then id = "0"..tostring(id) end gui.b.window.text = name; gui.b.label.id.text = "ID: #"..id; gui.b.label.name.text = "Name: "..name; gui.b.label.owner.text = "Owner: "..owner; gui.b.label.cost.text = "Cost: $"..cost; gui.b.label.payout.text = "Payout: $"..payout; gui.b.label.payout_time.text = "Payout Time: "..payout_otime.." "..payout_unit; gui.b.label.location.text = "Location: "..getZoneName(x, y, z, false).."("..getZoneName(x, y, z, true)..")"; gui.b.label.bank.text = "Bank: $"..bank; if is_admin and is_owner then gui.b.button.sell.enabled = true; gui.b.button.deposit.enabled = true; gui.b.button.withdraw.enabled = true; gui.b.button.buy.enabled = false; elseif is_admin and not is_owner and owner ~= "For Sale" then gui.b.button.sell.enabled = true; gui.b.button.buy.enabled = false; gui.b.button.deposit.enabled = false; gui.b.button.withdraw.enabled = false; elseif is_admin and not is_owner and owner == "For Sale" then gui.b.button.sell.enabled = false; gui.b.button.buy.enabled = true; gui.b.button.deposit.enabled = false; gui.b.button.withdraw.enabled = false; elseif not is_admin and is_owner then gui.b.button.sell.enabled = true; gui.b.button.deposit.enabled = true; gui.b.button.withdraw.enabled = true; gui.b.button.buy.enabled = false; elseif not is_admin and not is_owner and owner ~= "For Sale" then gui.b.window.enabled = true; elseif not is_admin and not is_owner and owner == "For Sale" then gui.b.window.enabled = true; gui.b.button.accept.enabled = false; gui.b.button.sell.enabled = false; gui.b.button.deposit.enabled = false; gui.b.button.withdraw.enabled = false; gui.b.button.buy.enabled = true; end gui.b.window.visible = true; showCursor(true); removeEventHandler("onClientRender", root, showInstructions) end ); Link to comment
Abdul KariM Posted February 27, 2016 Share Posted February 27, 2016 في الكود مافيه اي شي انه بقروب اونر او ادمن كيف تبي نساعدك اطرح الاكواد كاملة Link to comment
darbka2002 Posted February 27, 2016 Author Share Posted February 27, 2016 core.client local screen_width, screen_height = GuiElement.getScreenSize(); local is_cursor_over_gui = false; local action; local settings = {}; GuiElement.setInputMode("no_binds_when_editing"); addEvent("business.showCreateBusinessWindow", true); addEventHandler("business.showCreateBusinessWindow", root, function() gui.cb.window.visible = true; showCursor(true); end ); function outputMessage(message, r, g, b) triggerServerEvent("business.outputMessage", localPlayer, message, r, g, b); end addEventHandler("onClientRender", root, function() for index, b_marker in ipairs(Element.getAllByType("marker", resourceRoot)) do local b_data = b_marker:getData("b_data"); local id, name, owner, cost, payout, payout_time, payout_otime, payout_unit, bank, timer = unpack(b_data); local x, y, z = b_marker.position.x, b_marker.position.y, b_marker.position.z; local cam_x, cam_y, cam_z = getCameraMatrix(); if getDistanceBetweenPoints3D(cam_x, cam_y, cam_z, x, y, z) < 15 then local screen_x, screen_y = getScreenFromWorldPosition(x, y, z + 1.6); if screen_x then local scale = 1920 / screen_width; local width = 80 / scale; dxDrawImage(screen_x - width / 2, screen_y - screen_height / 10, width, 80, "files/business.png"); end if settings.show_business_info_on_marker then screen_x, screen_y = getScreenFromWorldPosition(x, y, z + 1.4); if screen_x then if #tostring(id) == 1 then id = "0"..tostring(id) end dxDrawFramedText("ID: #"..id, screen_x, screen_y, screen_x, screen_y, tocolor(255, 255, 255, 255), 1.0, "default-bold", "center", "center", false, false, false); end screen_x, screen_y = getScreenFromWorldPosition(x, y, z + 1.2); if screen_x then dxDrawFramedText("Name: "..name, screen_x, screen_y, screen_x, screen_y, tocolor(255, 255, 255, 255), 1.0, "default-bold", "center", "center", false, false, false); end screen_x, screen_y = getScreenFromWorldPosition(x, y, z + 1.0); if screen_x then dxDrawFramedText("Owner: "..owner, screen_x, screen_y, screen_x, screen_y, tocolor(255, 255, 255, 255), 1.0, "default-bold", "center", "center", false, false, false); end screen_x, screen_y = getScreenFromWorldPosition(x, y, z + 0.-- s8) -->; if screen_x then dxDrawFramedText("Cost: $"..cost, screen_x, screen_y, screen_x, screen_y, tocolor(255, 255, 255, 255), 1.0, "default-bold", "center", "center", false, false, false); end screen_x, screen_y = getScreenFromWorldPosition(x, y, z + 0.6); if screen_x then dxDrawFramedText("Payout: $"..payout, screen_x, screen_y, screen_x, screen_y, tocolor(255, 255, 255, 255), 1.0, "default-bold", "center", "center", false, false, false); end screen_x, screen_y = getScreenFromWorldPosition(x, y, z + 0.4); if screen_x then dxDrawFramedText("Payout Time: "..payout_otime.." "..payout_unit, screen_x, screen_y, screen_x, screen_y, tocolor(255, 255, 255, 255), 1.0, "default-bold", "center", "center", false, false, false); end screen_x, screen_y = getScreenFromWorldPosition(x, y, z + 0.2); if screen_x then dxDrawFramedText("Bank: $"..bank, screen_x, screen_y, screen_x, screen_y, tocolor(255, 255, 255, 255), 1.0, "default-bold", "center", "center", false, false, false); end end end end end ); addEvent("business.showInstructions", true); addEventHandler("business.showInstructions", root, function() addEventHandler("onClientRender", root, showInstructions); end ); function showInstructions() if settings.key then dxDrawText("Press",(screen_width / 1440) * 550,(screen_height / 900) * 450,(screen_width / 1440) * 100,(screen_height / 900) * 100, tocolor(255, 255, 255, 255),(screen_width / 1440) * 2.0); dxDrawText(settings.key:upper(),(screen_width / 1440) * 615,(screen_height / 900) * 450,(screen_width / 1440) * 100,(screen_height / 900) * 100, tocolor(255, 0, 0, 255),(screen_width / 1440) * 2.0); dxDrawText(" To Open The Business",(screen_width / 1440) * 630,(screen_height / 900) * 450,(screen_width / 1440) * 100,(screen_height / 900) * 100, tocolor(255, 255, 255, 255),(screen_width / 1440) * 2.0); end end addEvent("business.hideInstructions", true); addEventHandler("business.hideInstructions", root, function() removeEventHandler("onClientRender", root, showInstructions); end ); addEvent("business.showBusinessWindow", true); addEventHandler("business.showBusinessWindow", root, function(b_marker, is_owner, is_admin) local b_data = b_marker:getData("b_data"); local id, name, owner, cost, payout, payout_time, payout_otime, payout_unit, bank, timer = unpack(b_data); local x, y, z = b_marker.position; if #tostring(id) == 1 then id = "0"..tostring(id) end gui.b.window.text = name; gui.b.label.id.text = "ID: #"..id; gui.b.label.name.text = "Name: "..name; gui.b.label.owner.text = "Owner: "..owner; gui.b.label.cost.text = "Cost: $"..cost; gui.b.label.payout.text = "Payout: $"..payout; gui.b.label.payout_time.text = "Payout Time: "..payout_otime.." "..payout_unit; gui.b.label.location.text = "Location: "..getZoneName(x, y, z, false).."("..getZoneName(x, y, z, true)..")"; gui.b.label.bank.text = "Bank: $"..bank; if is_admin and is_owner then gui.b.button.sell.enabled = true; gui.b.button.deposit.enabled = true; gui.b.button.withdraw.enabled = true; gui.b.button.buy.enabled = false; elseif is_admin and not is_owner and owner ~= "For Sale" then gui.b.button.sell.enabled = true; gui.b.button.buy.enabled = false; gui.b.button.deposit.enabled = false; gui.b.button.withdraw.enabled = false; elseif is_admin and not is_owner and owner == "For Sale" then gui.b.button.sell.enabled = false; gui.b.button.buy.enabled = true; gui.b.button.deposit.enabled = false; gui.b.button.withdraw.enabled = false; elseif not is_admin and is_owner then gui.b.button.sell.enabled = true; gui.b.button.deposit.enabled = true; gui.b.button.withdraw.enabled = true; gui.b.button.buy.enabled = false; elseif not is_admin and not is_owner and owner ~= "For Sale" then gui.b.window.enabled = true; elseif not is_admin and not is_owner and owner == "For Sale" then gui.b.window.enabled = true; gui.b.button.accept.enabled = false; gui.b.button.sell.enabled = false; gui.b.button.deposit.enabled = false; gui.b.button.withdraw.enabled = false; gui.b.button.buy.enabled = true; end gui.b.window.visible = true; showCursor(true); removeEventHandler("onClientRender", root, showInstructions) end ); addEventHandler("onClientResourceStart", resourceRoot, function() triggerServerEvent("business.getSettings", localPlayer); end ); addEvent("business.getSettings", true); addEventHandler("business.getSettings", root, function(_settings) settings = _settings; end ); core.server local _settings = get(""); local settings = {}; for k, v in pairs(_settings) do k = split(k, ".")[2]; settings[k] = v; end if (settings.key:len() < 1 or settings.key:len() > 1) then settings.key = "N"; end if (not settings.blip or tonumber(settings.blip) == nil) then settings.blip = false; end addEventHandler("onResourceStart", resourceRoot, function() if (settings.database == "mysql") then local host, db, username, password, port, socket = unpack(settings.database_data); if not (host and db and username and password) then outputDebugString("Business: Failed to connect to the MySQL server - The data is invalid"); return; end if (tonumber(port)) then port = "port="..port..";"; else port = ""; end if (socket and socket ~= "") then socket = "socket="..socket..";"; else socket = ""; end database = Connection("mysql", "host="..host..";dbname="..db..";"..port..socket, username, password); if (not database) then outputDebugString("Business: Failed to connect to the MySQL server"); return; end else database = Connection("sqlite", "files/business.db"); if (not database) then outputDebugString("Business: Failed to connect to the SQLite file"); return; end end database:exec("CREATE TABLE IF NOT EXISTS business(id INT, name TEXT, owner TEXT, cost INT, pos TEXT, payout INT, payout_time INT, payout_otime INT, payout_unit TEXT, payout_cur_time INT, bank INT)"); database:query(dbCreateBusinessesCallback, "SELECT * FROM business"); end); function dbCreateBusinessesCallback(query_handle) local sql = query_handle:poll(0); if (sql and #sql > 0) then for index, row in ipairs(sql) do local pos = split(row["pos"], ","); local b_marker = Marker(pos[1], pos[2], pos[3], "cylinder", 1.5, settings.marker_color[1], settings.marker_color[2], settings.marker_color[3], settings.marker_color[4]); b_marker.interior = pos[4]; b_marker.dimension = pos[5]; if (settings.blip ~= false) then if (row["owner"] == "For Sale") then local b_blip = Blip.createAttachedTo(b_marker, settings.blip, 2, 255, 0, 0, 255, 0, 100.0); b_blip.interior = pos[4]; b_blip.dimension = pos[5]; else local b_blip = Blip.createAttachedTo(b_marker, settings.blip, 2, 255, 0, 0, 255, 0, 100.0); b_blip.interior = pos[4]; b_blip.dimension = pos[5]; end end addEventHandler("onMarkerHit", b_marker, onBusinessMarkerHit); addEventHandler("onMarkerLeave", b_marker, onBusinessMarkerLeave); local timer = Timer(businessPayout, row["payout_cur_time"] , 1, b_marker); b_marker:setData("b_data", {row["id"], row["name"], row["owner"], row["cost"], row["payout"], row["payout_time"], row["payout_otime"], row["payout_unit"], row["bank"], timer}); end end end addCommandHandler("business", function(player) if (ACL.hasObjectPermissionTo(player, "function.banPlayer")) then triggerClientEvent(player, "business.showCreateBusinessWindow", player); else player:outputMessage("Business: You don't have access to this command.", 255, 0, 0); end end); function Player:outputMessage(message, r, g, b) if (settings.info_messages_type == "dx") then dxOutputMessage(message, self, r, g, b); else self:outputChat(message, r, g, b, true); end end function outputMessage(message, player, r, g, b) if (settings.info_messages_type == "dx") then dxOutputMessage(message, player, r, g, b); else player:outputChat(message, r, g, b, true); end end function dxOutputMessage(message, player, r, g, b) triggerClientEvent(player, "business.dxOutputMessage", player, message, r, g, b); end addEvent("business.outputMessage", true); addEventHandler("business.outputMessage", root, function(message, r, g, b) source:outputMessage(message, r, g, b); end); addEvent("business.createBusiness", true); addEventHandler("business.createBusiness", root, function(x, y, z, interior, dimension, name, cost, payout, payout_time, payout_unit) database:query(dbCreateBusinessCallback, {client, x, y, z, interior, dimension, name, cost, payout, payout_time, payout_unit}, "SELECT * FROM business"); end); function dbCreateBusinessCallback(query_handle, client, x, y, z, interior, dimension, name, cost, payout, payout_time, payout_unit) local sql = query_handle:poll(0); if (sql) then local id; if (#sql > 0) then id = sql[#sql]["id"] + 1; else id = 1; end local unit; if (payout_unit == "Seconds") then unit = 1000; elseif (payout_unit == "Minutes") then unit = 60000; elseif (payout_unit == "Hours") then unit = 3600000; elseif (payout_unit == "Days") then unit = 86400000; end x = tonumber(x); y = tonumber(y); z = tonumber(z); interior = tonumber(interior); dimension = tonumber(dimension); cost = tonumber(cost); payout = tonumber(payout); payout_time = tonumber(payout_time); z = z - 1; database:exec("INSERT INTO business(id,name,owner,cost,pos,payout,payout_time,payout_otime,payout_unit,payout_cur_time,bank) VALUES(?,?,?,?,?,?,?,?,?,?,?)", id, name, "For Sale", cost, x..","..y..","..z..","..interior..","..dimension, payout, payout_time * unit, payout_time, payout_unit, payout_time * unit, 0); local b_marker = Marker(x, y, z, "cylinder", 1.5, settings.marker_color[1], settings.marker_color[2], settings.marker_color[3], settings.marker_color[4]); b_marker.interior = interior; b_marker.dimension = dimension; if (settings.blip ~= false) then local b_blip = Blip.createAttachedTo(b_marker, settings.blip, 2, 255, 0, 0, 255, 0, 100.0); b_blip.interior = interior; b_blip.dimension = dimension; end local timer = Timer(businessPayout, payout_time * unit , 1, b_marker); b_marker:setData("b_data", {id, name, "For Sale", cost, payout, payout_time * unit, payout_time, payout_unit, 0, timer}); addEventHandler("onMarkerHit", b_marker, onBusinessMarkerHit); addEventHandler("onMarkerLeave", b_marker, onBusinessMarkerLeave); if (#tostring(id) == 1) then id = "0".. tostring(id) end client:outputMessage("Business: Business(ID #"..id..") has been created successfully", 0, 255, 0); end end function onBusinessMarkerHit(hElement, mDim) if (hElement:getType() ~= "player") then return; end if (hElement:isInVehicle()) then return; end if (not mDim) then return; end triggerClientEvent(hElement, "business.showInstructions", hElement); end function onBusinessMarkerLeave(hElement, mDim) if (hElement:getType() ~= "player") then return; end if (hElement:isInVehicle()) then return; end if (not mDim) then return; end triggerClientEvent(hElement, "business.hideInstructions", hElement); end function businessPayout(b_marker) local b_data = b_marker:getData("b_data"); local id, name, owner, cost, payout, payout_time, payout_otime, payout_unit, bank, timer = unpack(b_data); if (owner ~= "For Sale") then bank = bank + payout; database:exec("UPDATE business SET bank = ? WHERE id = ?", bank, id); if (settings.inform_player_of_payout) then local account = Account(owner); if (account) then local player = account:getPlayer(); if (player and player.isElement) then player:outputMessage("Business: Business \" "..name.." \" has paid out($"..payout..")", 0, 255, 0); end end end end timer = Timer(businessPayout, payout_time, 1, b_marker); b_marker:setData("b_data", {id, name, owner, cost, payout, payout_time, payout_otime, payout_unit, bank, timer}); end addEventHandler("onResourceStop", resourceRoot, function() for index, b_marker in ipairs(Element.getAllByType("marker", resourceRoot)) do local b_data = b_marker:getData("b_data"); local id, name, owner, cost, payout, payout_time, payout_otime, payout_unit, bank, timer = unpack(b_data); if (timer and timer:isValid()) then local left = timer:getDetails(); if (left >= 50) then database:exec("UPDATE business SET payout_cur_time = ? WHERE id = ?", left, id); else database:exec("UPDATE business SET payout_cur_time = ? WHERE id = ?", payout_time, id); end end end end); function Ped:isInMarker(marker) local colshape = marker.colShape; return self:isWithinColShape(colshape); end addEventHandler("onResourceStart", resourceRoot, function() for index, player in ipairs(Element.getAllByType("player")) do bindKey(player, settings.key, "up", onPlayerAttemptToOpenBusiness); end end); addEventHandler("onPlayerJoin", root,function() bindKey(source, settings.key, "up", onPlayerAttemptToOpenBusiness); end); function onPlayerAttemptToOpenBusiness(player) for index, b_marker in ipairs(Element.getAllByType("marker", resourceRoot)) do if (player:isInMarker(b_marker)) then local b_data = b_marker:getData("b_data"); local id, name, owner, cost, payout, payout_time, payout_otime, payout_unit, bank, timer = unpack(b_data); triggerClientEvent(player, "business.showBusinessWindow", player, b_marker, getAccountName(getPlayerAccount(player)) == owner, ACL.hasObjectPermissionTo(player, "function.banPlayer")); break; end end end function Ped:getMarker() for index, b_marker in ipairs(Element.getAllByType("marker", resourceRoot)) do if (self:isInMarker(b_marker)) then return b_marker; end end end addEvent("business.buy", true); addEventHandler("business.buy", root, function() local account = client.account; if (not account or account:isGuest()) then client:outputMessage("Business: You are not logged in", 255, 0, 0) return; end local b_marker = client:getMarker(); if (not isElement(b_marker)) then return; end local b_data = b_marker:getData("b_data"); local id, name, owner, cost, payout, payout_time, payout_otime, payout_unit, bank, timer = unpack(b_data); if (owner ~= "For Sale") then client:outputMessage("Business: This business is owned", 255, 0, 0); return; end database:query(dbBuyBusinessCallback, {client, b_marker, id, name, owner, cost, payout, payout_time, payout_otime, payout_unit, bank, timer}, "SELECT * FROM business WHERE owner = ?", account.name); end); addEvent("business.sell", true); addEventHandler("business.sell", root, function() local account = client.account; if (not account or account:isGuest()) then return; end local b_marker = client:getMarker(); if (not isElement(b_marker)) then return; end local b_data = b_marker:getData("b_data"); local id, name, owner, cost, payout, payout_time, payout_otime, payout_unit, bank, timer = unpack(b_data); if (owner ~= account.name) then if (ACL.hasObjectPermissionTo(client, "function.banPlayer")) then database:exec("UPDATE business SET owner = ? WHERE id = ?", "For Sale", id); b_marker:setData Link to comment
darbka2002 Posted February 27, 2016 Author Share Posted February 27, 2016 انا بس بدى الاعب العادى تفتحلة اللوح كاملة و يكمنة الشراء Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now