Jump to content

[ HELP ] Ajuda Em Limite de Comprar !


Recommended Posts

On 09/09/2018 at 22:57, DNL291 said:

Grave na conta do jogador quando ele comprar 1 propriedade (setAccountData).

Como Ficaria no script ?
 

local props = {
    {2023.57532, 1007.71838, 10.82031, "Luxus", 550000,30000 }, 
    {2088.52930, 2074.63062, 10.82031, "Jericó", 550000,25000 },
    {2306.42407, -1642.46130, 14.43137, "GoodLook", 550000,25000 },
    {2184.85864, 1676.79028, 11.08834, "MuitoSwag!", 550000,25000 },
    {1458.74536, -1140.35547, 24.06615, "Lojas Zip", 550000,25000 },
    {2245.22681, -1662.87427, 15.46900, "Lojas Binco", 550000,25000 },
    {2094.79712, 2119.42456, 10.82031, "Tatoo Shop",550000,25000 },
    {2071.95703, -1779.58240, 13.55746, "Tatoo Shop",550000,25000 },
    {418.5547,-80.1667,1001.8047, "Botique",550000,25000 },
    {2421.17212, -1226.42212, 25.04780, "Strip Club", 550000,25000 },
    {414.3864, 2532.9265, 19.1484, "Verdant Meadows Air Strip", 550000,25000 },
    {2127.5940,2370.4255,10.8203, "Emerald Isle", 550000,25000 },
    {2022.5179,1916.6848,12.3397, "The Visage", 550000,25000 },
    {1361.92383, 250.55600, 19.56693, "The Well Stacked Pizza", 550000,25000 },
    {457.33954, -1500.64001, 31.04420, "Lojas Victim", 550000,25000 },
    {2210.5991,1285.8645,10.8203, "Camel's Toe",550000,25000 },
    {2181.0334,1116.3749,12.6484, "Come-a-Lot",550000,25000 },
    {2201.1609,1391.2201,10.8203, "Autobahn Imports",550000,25000 },
    {2088.1499,1449.0906,10.8203, "The Royal Casino", 550000,25000 },
    {2087.0022,2175.8208,10.8203, "The Motel",550000,25000 },
    {1971.7400,1623.1630,12.8624, "Pirates in Mans Pants Hotel",550000,25000 },
    {1477.9447,2248.8301,11.0234, "Las Venturas Bandits Stadion",550000,25000 },
    {270.5629,1369.5687,10.5859, "Xoomer Corporation", 550000,25000 },
    {-360.7929,1593.6844,76.8165, "Big Ear Radioteleskop",550000,25000 },
    {-143.9193,1224.5100,19.8992, "The King Ring", 550000,25000 },
    {-1941.3511,2379.8010,49.6943, "Jays Diner", 550000,25000 },
    {-844.7192,2746.0947,46.1409, "Tee Pee Motel",550000,25000 },
    {-36.0793,2349.6643,24.3026, "The Snakefarm", 550000,25000 },
    {504.15668, -1361.35962, 16.12516, "Lojas Pro Laps", 550000,25000 },
    {451.32590, -1479.09119, 30.81235, "Lojas Dider Sachs",550000,25000 },
    {1022.7669,-1124.1028,23.8708, "Teatro Cathay", 550000,25000 },
    {1129.0569,-1489.0812,22.7690, "Shopping Verona",550000,25000 },
    {-2244.12109, 128.63309, 35.32031, "Zero RC Shop", 550000,25000 },
    {-2624.65015, 1410.24951, 7.09375, "Jizzy's Club", 550000,25000 },
    {-2724.3921,-314.7957,7.1861, "Country Club", 550000,25000 },
    {-1957.3124,302.8924,35.4688, "Wang Cars", 550000,25000 },
    {-1754.2139,960.2347,24.8828, "Hotel", 550000,25000 },
    {-1660.4781,1218.4636,7.2500, "Otto's Autos", 550000,25000 },
    {2010.5006,1167.5737,10.8203, "Pink Flamingo Hotel",550000,25000 },
    {1933.0240,1345.5447,9.9688, "The High Roller Casino", 550000,25000 },
    {2367.9846,1983.1243,10.8203, "Casa de Carnes Las Venturas", 550000,25000 },
    {2318.6628,2117.7773,10.8281, "Las Venturas Casino", 550000,25000 },
    {2205.2927,1900.5876,10.8203, "Starfish Casino", 550000,25000 },
    {2221.1721,1839.1243,10.8203, "Clowns Pocket Casino", 550000,25000 },
    {2483.1555,1527.3000,11.2504, "Tikki Motel", 550000,25000 },
    {2310.4160,1389.8794,10.8203, "Estacionamento Central", 550000,25000 },
    {-2442.8101,753.7776,35.1719, "Supa Save Supermercado", 550000,25000 },
    {-2766.1062,788.7639,52.7813, "Tuff Nut Donuts", 550000,25000 },
    {1217.2138671875,-1692.6422119141,19.734375, "Loja Das Putinhas",550000,25000 },
    {2861.4619140625,-1440.1755371094,10.9375, "Mercadinho Municipal", 550000,25000},
    {2820.6293945313,-1603.1125488281,11.04239654541, "Auto Peças", 550000,25000},
    {2812.576171875,-1631.0520019531,11.013246536255, "Informaticas Ls", 550000,25000},
    {2440.9387207031,-1472.4278564453,24, "Lava Rapido", 550000,25000},
    {2651.4919433594,-1369.1989746094,31.367134094238, "Lojao Do 1,99", 550000,25000},
    {2561.3835449219,-1329.7752685547,39.714729309082, "Oficina Sao Pedro", 550000,25000},
    {2559.7907714844,-1426.1782226563,24.815044403076, "Casa Dos Salgados", 550000,25000},
    {2389.9499511719,-1548.6805419922,24.1640625, "Mercadão", 550000,25000},
}

local db = dbConnect("sqlite", "database.db")
pickup = {}
marker = {}
mPlayer = {}
inMarker = {}

function execute(...)
    return dbFree(dbQuery(db,...))
end

function getProperties()
    local qh = dbQuery(db,"SELECT * FROM PropriedadesTable")
    return dbPoll(qh,-1)
end

function checkPropertie(id)
    local qh = dbQuery(db,"SELECT * FROM PropriedadesTable WHERE ID=?",id)
    local result = dbPoll(qh,-1)
    if (#result > 0) then
        return true
    end
    return false
end

function getPlayerFromPartialName(name)
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil
    if name then
        for _, player in ipairs(getElementsByType("player")) do
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower()
            if name_:find(name, 1, true) then
                return player
            end
        end
    end
end

function addPickUps()
    execute([[CREATE TABLE IF NOT EXISTS PropriedadesTable (    
                            ID VARCHAR(50),
                            Name VARCHAR(100),
                            Price VARCHAR(50),
                            Salary VARCHAR(50),
                            Position VARCHAR(200),
                            Owner VARCHAR(100))]])
    for k, v in pairs(props) do
        if not (checkPropertie(k)) then
            outputDebugString("Propertie: Insert a new propertie in database")
            execute("INSERT INTO PropriedadesTable (Name,ID,Price,Salary,Position) VALUES (?,?,?,?,?)", v[4],k,v[5],v[6],toJSON({v[1], v[2], v[3]}))
        end
    end
    for k, p in pairs(getProperties()) do
        local x,y,z = unpack(fromJSON(p["Position"]))
        local ID = p["ID"]
        pickup[ID] = createPickup(x,y,z,3, 1273, 0)
        marker[ID] = createMarker(x,y,z-1, "cylinder", 2, 0, 0, 0, 0)
        blips = createBlipAttachedTo ( pickup[ID], 31 )
        setElementData(blips,"textInfo","Propriedade | Nome: "..p["Name"])
        setElementData(blips,"blipIcon","dollar")
        setElementData(pickup[ID],"isProperty", true)
        setElementData(pickup[ID], "name", p["Name"])
        setElementData(pickup[ID], "ID", p["ID"])
        setElementData(pickup[ID], "price", tonumber(p["Price"]))
        setElementData(pickup[ID], "salary", tonumber(p["Salary"]))
        if p["Owner"] and p["Owner"] ~= "Ninguem" and p["Owner"] ~= "False" then
            setElementData(pickup[ID],"owner",true)
            setElementData(pickup[ID], "playerName", p["Owner"])
            if getPlayerFromName(p["Owner"]) then
                setElementData(pickup[ID], "player", getPlayerFromName(p["Owner"]))
            end
            setElementData(pickup[ID], "accountName", getAccountName(getPlayerAccount(getPlayerFromName(p["Owner"]))))
            setTimer(function()
                triggerClientEvent(getPlayerFromName(p["Owner"]), "propriedade:InsertTable" , getPlayerFromName(p["Owner"]), {x, y, z, p["Name"], p["Price"],  p["Salary"], p["ID"]}, "ID: "..p["ID"].." | "..p["Name"])
            end, 1500, 1)
        else
            setElementData(pickup[ID],"owner",nil)
            setElementData(pickup[ID],"playerName",nil)
            setElementData(pickup[ID],"accountName",nil)
        end
        addEventHandler("onMarkerHit", marker[ID], MarkerHit )
        addEventHandler("onMarkerLeave", marker[ID], MarkerLeave )
    end
end
addEventHandler("onResourceStart", resourceRoot, addPickUps)

function onResourceStop()
    for k, v in pairs(pickup) do
            execute("UPDATE PropriedadesTable SET Owner=? WHERE ID=?",getElementData(v,"playerName") or "Ninguem",k)
    end
end
addEventHandler("onResourceStop", resourceRoot, onResourceStop)

function MarkerHit(hitElement, matchingDimension)
    if getElementType( hitElement ) == "player" then
        mPlayer[hitElement] = true
        inMarker[hitElement] = true
        for k, v in pairs(pickup) do
            if getElementData(v, "owner") then 
                if getElementData(v, "accountName") == getAccountName(getPlayerAccount(hitElement)) then
                    if isElementWithinMarker(hitElement, marker[k]) then
                    getMessage(hitElement,1)
                    return
                    end
                end
            end
        end
        getMessage(hitElement,2)
    end
end

function MarkerLeave(hitElement, matchingDimension)
    if getElementType( hitElement ) == "player" then
        inMarker[hitElement] = false
    end
end

function buyP(player)
    if player then
        for k, v in pairs(marker) do
            if not inMarker[player] and mPlayer[player] then
                getMessage(player,3)
                mPlayer[player] = false
                return
            end
            if isElementWithinMarker(player, v) then
                if getElementData(pickup[k], "accountName") == getAccountName(getPlayerAccount(player)) then
                    return getMessage(player,4)
                end
                if getPlayerMoney(player) < getElementData(pickup[k],"price") then
                    return getMessage(player,5)
                end
                if getElementData(pickup[k], "owner") then
                    return getMessage(player,6)
                end
                setElementData(pickup[k], "owner", true)
                setElementData(pickup[k], "playerName", getPlayerName(player))
                setElementData(pickup[k], "player", player)
                setElementData(pickup[k], "accountName", getAccountName(getPlayerAccount(player)))
                local pos = {getElementPosition(pickup[k])}
                triggerClientEvent(player, "propriedade:InsertTable" , player, {pos[1], pos[2], pos[3], getElementData(pickup[k],"name"), getElementData(pickup[k],"price"), getElementData(pickup[k],"salary"), getElementData(pickup[k],"ID")}, "ID: "..getElementData(pickup[k],"ID").." | "..getElementData(pickup[k],"name"))
                takePlayerMoney(player, getElementData(pickup[k], "price"))
                getMessage(player,7)
            end
        end
    end
end
addCommandHandler("comprar", buyP)

addEvent("sell:Propriedade",true)
function sellP(player, id)
    if player then
        if id then
            if getElementData(pickup[id], "accountName") ~= getAccountName(getPlayerAccount(player)) then
                return getMessage(player,8)
            end
            setElementData(pickup[id], "owner", nil)
            setElementData(pickup[id], "playerName", nil)
            setElementData(pickup[id], "player", nil)
            setElementData(pickup[id], "accountName", nil)
            givePlayerMoney(player, getElementData(pickup[id],"price"))
            if getElementData(player,"lang") == "portuguese" then
                outputChatBox("#8DCDCD[PROPRIEDADES] #FFFFFFVocê vendeu sua propriedade #8DCD8D"..getElementData(pickup[id],"name").."#FFFFFF e ganhou #8DCD8D$"..formatNumber(getElementData(pickup[id],"price")).." !", player,255,255,0, true)
            elseif getElementData(player,"lang") == "english" then
                outputChatBox("#8DCDCD[PROPERTIES] #FFFFFFYou sell your property #8DCD8D"..getElementData(pickup[id],"name").."#FFFFFF and win #8DCD8D$"..formatNumber(getElementData(pickup[id],"price")).." !", player,255,255,0, true)
            end
        end
    end
end
addEventHandler("sell:Propriedade", getRootElement(), sellP)

function lucro()
    local count = 0
    for k, player in pairs(getElementsByType("player")) do
        local startMoney = getPlayerMoney(player)
        for k, v in pairs(marker) do
            if getElementData(pickup[k], "owner") then
                if getElementData(pickup[k], "accountName") == getAccountName(getPlayerAccount(player)) then
                    givePlayerMoney(player,getElementData(pickup[k],"salary"))
                    count = count+1
                end
            end
        end
        if getPlayerMoney(player)-startMoney ~= 0 then
            if getElementData(player,"lang") == "portuguese" then
                outputChatBox("#8DCDCD[PAGAMENTO] #FFFFFFVocê recebeu #8DCD8D$"..formatNumber(getPlayerMoney(player)-startMoney).."#FFFFFF of your profit(s) #8DCD8D"..formatNumber(count).."#FFFFFF property(s).", player, 255,255,0,true)
            elseif getElementData(player,"lang") == "english" then
                outputChatBox("#8DCDCD[PROPERTIES] #FFFFFFYou received #8DCD8D$"..formatNumber(getPlayerMoney(player)-startMoney).."#FFFFFF of your profit(s) #8DCD8D"..formatNumber(count).."#FFFFFF property(s).", player, 255,255,0,true)
            end
        end
        count = 0
    end
end
time = setTimer(lucro, 4*125000, 0)

addEventHandler("onPlayerLogin", root,
function()
    for k, v in pairs(marker) do
        if getElementData(pickup[k], "accountName") == getAccountName(getPlayerAccount(source)) then
            setElementData(pickup[k], "playerName", getPlayerName(source))
            setElementData(pickup[k], "player", source)
            local pos = {getElementPosition(pickup[k])}
            triggerClientEvent(source, "propriedade:InsertTable" , source, {pos[1], pos[2], pos[3], getElementData(pickup[k],"name"), getElementData(pickup[k],"price"), getElementData(pickup[k],"salary"), getElementData(pickup[k],"ID")}, "ID: "..getElementData(pickup[k],"ID").." | "..getElementData(pickup[k],"name"))
        end
    end
end)

addEventHandler("onPlayerLogout", getRootElement(),
function()
    triggerClientEvent(source, "propriedade:RemoveTable" , source)
end)

addEvent("warp:Propriedade",true)
addEventHandler("warp:Propriedade", getRootElement(),
    function(player, x, y, z)
        if isElement(player) then
            fadeCamera(player,false,1.0,0,0,0)
            setTimer(function()
                setElementPosition(player, x, y, z)
                local pos = {getElementPosition(player)}
                if getElementData(player,"lang") == "portuguese" then
                    outputChatBox("#8DCDCD[PROPRIEDADES]#FFFFFF Você foi para a propriedade em #8DCD8D"..getZoneName(getElementPosition(player)).." ("..getElementCity(pos[1], pos[2], pos[3])..") .", player, 255, 255, 255, true)
                elseif getElementData(player,"lang") == "english" then
                    outputChatBox("#8DCDCD[PROPERTIES]#FFFFFF You went to the property on #8DCD8D"..getZoneName(getElementPosition(player)).." ("..getElementCity(pos[1], pos[2], pos[3])..") .", player, 255, 255, 255, true)
                end
            end, 1000, 1)
            setTimer(function()
                fadeCamera(player,true,0.5)
            end,2000,1)
        end
    end
)

function getElementCity(x, y, z)
    local citynames = {
        ["Los Santos"] = "LS", ["San Fierro"] = "SF", ["Las Venturas"] = "LV",
        ["Tierra Robada"] = "TR", ["Bone County"] = "BC", ["Red County"] = "RC",
        ["Flint County"] = "FC", ["Whetstone"] = "WT"
   Como Ficaria ? 

 }
    return citynames[getZoneName( x, y, z , true)] or "N/A"
end

function formatNumber(number)  
    local formatted = number  
    while true do      
        formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1.%2')    
        if (k == 0) then      
            break   
        end  
    end  
    return formatted
end

function getMessage(target,id)
    triggerClientEvent(target,"getMessage",target,id)
end

 

Edited by DNL291
Link to comment

local props = {
	{2023.57532, 1007.71838, 10.82031, "Luxus", 550000,30000 }, 
	{2088.52930, 2074.63062, 10.82031, "Jericó", 550000,25000 },
	{2306.42407, -1642.46130, 14.43137, "GoodLook", 550000,25000 },
	{2184.85864, 1676.79028, 11.08834, "MuitoSwag!", 550000,25000 },
	{1458.74536, -1140.35547, 24.06615, "Lojas Zip", 550000,25000 },
	{2245.22681, -1662.87427, 15.46900, "Lojas Binco", 550000,25000 },
	{2094.79712, 2119.42456, 10.82031, "Tatoo Shop",550000,25000 },
	{2071.95703, -1779.58240, 13.55746, "Tatoo Shop",550000,25000 },
	{418.5547,-80.1667,1001.8047, "Botique",550000,25000 },
	{2421.17212, -1226.42212, 25.04780, "Strip Club", 550000,25000 },
	{414.3864, 2532.9265, 19.1484, "Verdant Meadows Air Strip", 550000,25000 },
	{2127.5940,2370.4255,10.8203, "Emerald Isle", 550000,25000 },
	{2022.5179,1916.6848,12.3397, "The Visage", 550000,25000 },
	{1361.92383, 250.55600, 19.56693, "The Well Stacked Pizza", 550000,25000 },
	{457.33954, -1500.64001, 31.04420, "Lojas Victim", 550000,25000 },
	{2210.5991,1285.8645,10.8203, "Camel's Toe",550000,25000 },
	{2181.0334,1116.3749,12.6484, "Come-a-Lot",550000,25000 },
	{2201.1609,1391.2201,10.8203, "Autobahn Imports",550000,25000 },
	{2088.1499,1449.0906,10.8203, "The Royal Casino", 550000,25000 },
	{2087.0022,2175.8208,10.8203, "The Motel",550000,25000 },
	{1971.7400,1623.1630,12.8624, "Pirates in Mans Pants Hotel",550000,25000 },
	{1477.9447,2248.8301,11.0234, "Las Venturas Bandits Stadion",550000,25000 },
	{270.5629,1369.5687,10.5859, "Xoomer Corporation", 550000,25000 },
	{-360.7929,1593.6844,76.8165, "Big Ear Radioteleskop",550000,25000 },
	{-143.9193,1224.5100,19.8992, "The King Ring", 550000,25000 },
	{-1941.3511,2379.8010,49.6943, "Jays Diner", 550000,25000 },
	{-844.7192,2746.0947,46.1409, "Tee Pee Motel",550000,25000 },
	{-36.0793,2349.6643,24.3026, "The Snakefarm", 550000,25000 },
	{504.15668, -1361.35962, 16.12516, "Lojas Pro Laps", 550000,25000 },
	{451.32590, -1479.09119, 30.81235, "Lojas Dider Sachs",550000,25000 },
	{1022.7669,-1124.1028,23.8708, "Teatro Cathay", 550000,25000 },
	{1129.0569,-1489.0812,22.7690, "Shopping Verona",550000,25000 },
	{-2244.12109, 128.63309, 35.32031, "Zero RC Shop", 550000,25000 },
	{-2624.65015, 1410.24951, 7.09375, "Jizzy's Club", 550000,25000 },
	{-2724.3921,-314.7957,7.1861, "Country Club", 550000,25000 },
	{-1957.3124,302.8924,35.4688, "Wang Cars", 550000,25000 },
	{-1754.2139,960.2347,24.8828, "Hotel", 550000,25000 },
	{-1660.4781,1218.4636,7.2500, "Otto's Autos", 550000,25000 },
	{2010.5006,1167.5737,10.8203, "Pink Flamingo Hotel",550000,25000 },
	{1933.0240,1345.5447,9.9688, "The High Roller Casino", 550000,25000 },
	{2367.9846,1983.1243,10.8203, "Casa de Carnes Las Venturas", 550000,25000 },
	{2318.6628,2117.7773,10.8281, "Las Venturas Casino", 550000,25000 },
	{2205.2927,1900.5876,10.8203, "Starfish Casino", 550000,25000 },
	{2221.1721,1839.1243,10.8203, "Clowns Pocket Casino", 550000,25000 },
	{2483.1555,1527.3000,11.2504, "Tikki Motel", 550000,25000 },
	{2310.4160,1389.8794,10.8203, "Estacionamento Central", 550000,25000 },
	{-2442.8101,753.7776,35.1719, "Supa Save Supermercado", 550000,25000 },
	{-2766.1062,788.7639,52.7813, "Tuff Nut Donuts", 550000,25000 },
	{1217.2138671875,-1692.6422119141,19.734375, "Loja Das Putinhas",550000,25000 },
	{2861.4619140625,-1440.1755371094,10.9375, "Mercadinho Municipal", 550000,25000},
	{2820.6293945313,-1603.1125488281,11.04239654541, "Auto Peças", 550000,25000},
	{2812.576171875,-1631.0520019531,11.013246536255, "Informaticas Ls", 550000,25000},
	{2440.9387207031,-1472.4278564453,24, "Lava Rapido", 550000,25000},
	{2651.4919433594,-1369.1989746094,31.367134094238, "Lojao Do 1,99", 550000,25000},
	{2561.3835449219,-1329.7752685547,39.714729309082, "Oficina Sao Pedro", 550000,25000},
	{2559.7907714844,-1426.1782226563,24.815044403076, "Casa Dos Salgados", 550000,25000},
	{2389.9499511719,-1548.6805419922,24.1640625, "Mercadão", 550000,25000},
}

local db = dbConnect("sqlite", "database.db")
pickup = {}
marker = {}
mPlayer = {}
inMarker = {}

function execute(...)
	return dbFree(dbQuery(db,...))
end

function getProperties()
	local qh = dbQuery(db,"SELECT * FROM PropriedadesTable")
	return dbPoll(qh,-1)
end
	
function checkPropertie(id)
	local qh = dbQuery(db,"SELECT * FROM PropriedadesTable WHERE ID=?",id)
	local result = dbPoll(qh,-1)
	if (#result > 0) then
		return true
	end
	return false
end

function getPlayerFromPartialName(name)
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil
    if name then
        for _, player in ipairs(getElementsByType("player")) do
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower()
            if name_:find(name, 1, true) then
                return player
            end
        end
    end
end


function addPickUps()
	execute([[CREATE TABLE IF NOT EXISTS PropriedadesTable (	
							ID VARCHAR(50),
							Name VARCHAR(100),
							Price VARCHAR(50),
							Salary VARCHAR(50),
							Position VARCHAR(200),
							Owner VARCHAR(100))]])
	for k, v in pairs(props) do
		if not (checkPropertie(k)) then
			outputDebugString("Propertie: Insert a new propertie in database")
			execute("INSERT INTO PropriedadesTable (Name,ID,Price,Salary,Position) VALUES (?,?,?,?,?)", v[4],k,v[5],v[6],toJSON({v[1], v[2], v[3]}))
		end
	end
	for k, p in pairs(getProperties()) do
		local x,y,z = unpack(fromJSON(p["Position"]))
		local ID = p["ID"]
		pickup[ID] = createPickup(x,y,z,3, 1273, 0)
		marker[ID] = createMarker(x,y,z-1, "cylinder", 2, 0, 0, 0, 0)
		blips = createBlipAttachedTo ( pickup[ID], 31 )
		setElementData(blips,"textInfo","Propriedade | Nome: "..p["Name"])
		setElementData(blips,"blipIcon","dollar")
		setElementData(pickup[ID],"isProperty", true)
		setElementData(pickup[ID], "name", p["Name"])
		setElementData(pickup[ID], "ID", p["ID"])
		setElementData(pickup[ID], "price", tonumber(p["Price"]))
		setElementData(pickup[ID], "salary", tonumber(p["Salary"]))
		if p["Owner"] and p["Owner"] ~= "Ninguem" and p["Owner"] ~= "False" then
			setElementData(pickup[ID],"owner",true)
			setElementData(pickup[ID], "playerName", p["Owner"])
			if getPlayerFromName(p["Owner"]) then
				setElementData(pickup[ID], "player", getPlayerFromName(p["Owner"]))
			end
			setElementData(pickup[ID], "accountName", getAccountName(getPlayerAccount(getPlayerFromName(p["Owner"]))))
			setTimer(function()
				triggerClientEvent(getPlayerFromName(p["Owner"]), "propriedade:InsertTable" , getPlayerFromName(p["Owner"]), {x, y, z, p["Name"], p["Price"],  p["Salary"], p["ID"]}, "ID: "..p["ID"].." | "..p["Name"])
			end, 1500, 1)
		else
			setElementData(pickup[ID],"owner",nil)
			setElementData(pickup[ID],"playerName",nil)
			setElementData(pickup[ID],"accountName",nil)
		end
		addEventHandler("onMarkerHit", marker[ID], MarkerHit )
		addEventHandler("onMarkerLeave", marker[ID], MarkerLeave )
	end
end
addEventHandler("onResourceStart", resourceRoot, addPickUps)

function onResourceStop()
	for k, v in pairs(pickup) do
			execute("UPDATE PropriedadesTable SET Owner=? WHERE ID=?",getElementData(v,"playerName") or "Ninguem",k)
	end
end
addEventHandler("onResourceStop", resourceRoot, onResourceStop)




function MarkerHit(hitElement, matchingDimension)
    if getElementType( hitElement ) == "player" then
		mPlayer[hitElement] = true
		inMarker[hitElement] = true
		for k, v in pairs(pickup) do
			if getElementData(v, "owner") then 
				if getElementData(v, "accountName") == getAccountName(getPlayerAccount(hitElement)) then
					if isElementWithinMarker(hitElement, marker[k]) then
					getMessage(hitElement,1)
					return
					end
				end
			end
		end
		getMessage(hitElement,2)
	end
end

function MarkerLeave(hitElement, matchingDimension)
	if getElementType( hitElement ) == "player" then
		inMarker[hitElement] = false
	end
end

function buyP(player)
	if player then
		for k, v in pairs(marker) do
			if not inMarker[player] and mPlayer[player] then
				getMessage(player,3)
				mPlayer[player] = false
				return
			end
			if isElementWithinMarker(player, v) then
				if getElementData(pickup[k], "accountName") == getAccountName(getPlayerAccount(player)) then
					return getMessage(player,4)
				end
				if getPlayerMoney(player) < getElementData(pickup[k],"price") then
					return getMessage(player,5)
				end
				if getElementData(pickup[k], "owner") then
					return getMessage(player,6)
				end
				setElementData(pickup[k], "owner", true)
				setElementData(pickup[k], "playerName", getPlayerName(player))
				setElementData(pickup[k], "player", player)
				setElementData(pickup[k], "accountName", getAccountName(getPlayerAccount(player)))
				local pos = {getElementPosition(pickup[k])}
				triggerClientEvent(player, "propriedade:InsertTable" , player, {pos[1], pos[2], pos[3], getElementData(pickup[k],"name"), getElementData(pickup[k],"price"), getElementData(pickup[k],"salary"), getElementData(pickup[k],"ID")}, "ID: "..getElementData(pickup[k],"ID").." | "..getElementData(pickup[k],"name"))
				takePlayerMoney(player, getElementData(pickup[k], "price"))
				getMessage(player,7)
			end
		end
	end
end
addCommandHandler("comprar", buyP)

addEvent("sell:Propriedade",true)
function sellP(player, id)
	if player then
		if id then
			if getElementData(pickup[id], "accountName") ~= getAccountName(getPlayerAccount(player)) then
				return getMessage(player,8)
			end
			setElementData(pickup[id], "owner", nil)
			setElementData(pickup[id], "playerName", nil)
			setElementData(pickup[id], "player", nil)
			setElementData(pickup[id], "accountName", nil)
			givePlayerMoney(player, getElementData(pickup[id],"price"))
			if getElementData(player,"lang") == "portuguese" then
				outputChatBox("#8DCDCD[PROPRIEDADES] #FFFFFFVocê vendeu sua propriedade #8DCD8D"..getElementData(pickup[id],"name").."#FFFFFF e ganhou #8DCD8D$"..formatNumber(getElementData(pickup[id],"price")).." !", player,255,255,0, true)
			elseif getElementData(player,"lang") == "english" then
				outputChatBox("#8DCDCD[PROPERTIES] #FFFFFFYou sell your property #8DCD8D"..getElementData(pickup[id],"name").."#FFFFFF and win #8DCD8D$"..formatNumber(getElementData(pickup[id],"price")).." !", player,255,255,0, true)
			end
		end
	end
end
addEventHandler("sell:Propriedade", getRootElement(), sellP)

function lucro()
	local count = 0
	for k, player in pairs(getElementsByType("player")) do
		local startMoney = getPlayerMoney(player)
		for k, v in pairs(marker) do
			if getElementData(pickup[k], "owner") then
				if getElementData(pickup[k], "accountName") == getAccountName(getPlayerAccount(player)) then
					givePlayerMoney(player,getElementData(pickup[k],"salary"))
					count = count+1
				end
			end
		end
		if getPlayerMoney(player)-startMoney ~= 0 then
			if getElementData(player,"lang") == "portuguese" then
				outputChatBox("#8DCDCD[PAGAMENTO] #FFFFFFVocê recebeu #8DCD8D$"..formatNumber(getPlayerMoney(player)-startMoney).."#FFFFFF of your profit(s) #8DCD8D"..formatNumber(count).."#FFFFFF property(s).", player, 255,255,0,true)
			elseif getElementData(player,"lang") == "english" then
				outputChatBox("#8DCDCD[PROPERTIES] #FFFFFFYou received #8DCD8D$"..formatNumber(getPlayerMoney(player)-startMoney).."#FFFFFF of your profit(s) #8DCD8D"..formatNumber(count).."#FFFFFF property(s).", player, 255,255,0,true)
			end
		end
		count = 0
	end
end
time = setTimer(lucro, 4*125000, 0)

setAccountData (PlayerAccount,"database.db",
         outputChatBox ("LiMITE")

		 
		end 
    end
	
addEventHandler("onPlayerLogin", root,
function()
    for k, v in pairs(marker) do
		if getElementData(pickup[k], "accountName") == getAccountName(getPlayerAccount(source)) then
			setElementData(pickup[k], "playerName", getPlayerName(source))
			setElementData(pickup[k], "player", source)
			local pos = {getElementPosition(pickup[k])}
			triggerClientEvent(source, "propriedade:InsertTable" , source, {pos[1], pos[2], pos[3], getElementData(pickup[k],"name"), getElementData(pickup[k],"price"), getElementData(pickup[k],"salary"), getElementData(pickup[k],"ID")}, "ID: "..getElementData(pickup[k],"ID").." | "..getElementData(pickup[k],"name"))
		end
	end
end)

addEventHandler("onPlayerLogout", getRootElement(),
function()
	triggerClientEvent(source, "propriedade:RemoveTable" , source)
end)

addEvent("warp:Propriedade",true)
addEventHandler("warp:Propriedade", getRootElement(),
	function(player, x, y, z)
		if isElement(player) then
			fadeCamera(player,false,1.0,0,0,0)
			setTimer(function()
				setElementPosition(player, x, y, z)
				local pos = {getElementPosition(player)}
				if getElementData(player,"lang") == "portuguese" then
					outputChatBox("#8DCDCD[PROPRIEDADES]#FFFFFF Você foi para a propriedade em #8DCD8D"..getZoneName(getElementPosition(player)).." ("..getElementCity(pos[1], pos[2], pos[3])..") .", player, 255, 255, 255, true)
				elseif getElementData(player,"lang") == "english" then
					outputChatBox("#8DCDCD[PROPERTIES]#FFFFFF You went to the property on #8DCD8D"..getZoneName(getElementPosition(player)).." ("..getElementCity(pos[1], pos[2], pos[3])..") .", player, 255, 255, 255, true)
				end
			end, 1000, 1)
			setTimer(function()
				fadeCamera(player,true,0.5)
			end,2000,1)
		end
	end
)

function getElementCity(x, y, z)
	local citynames = {
		["Los Santos"] = "LS", ["San Fierro"] = "SF", ["Las Venturas"] = "LV",
		["Tierra Robada"] = "TR", ["Bone County"] = "BC", ["Red County"] = "RC",
		["Flint County"] = "FC", ["Whetstone"] = "WT"
	}
	return citynames[getZoneName( x, y, z , true)] or "N/A"
end

function formatNumber(number)  
	local formatted = number  
	while true do      
		formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1.%2')    
		if (k == 0) then      
			break   
		end  
	end  
	return formatted
end

function getMessage(target,id)
	triggerClientEvent(target,"getMessage",target,id)
end

 

5 minutes ago, OverKILL said:

Por gentileza, use o código de formatação do fórum para postar códigos .lua:

 

xn9sfEX.png

 

Separe o lado CLIENT E SERVER para ficar mais fácil de você receber ajuda, seja organizado.

Obrigado Pelo Aviso

Edited by StarK001
Link to comment
  • Other Languages Moderators

Você poderia fazer um FOR que verifica todas as casas do server quando o player tenta comprar uma casa. Se já existir outra casa com esse jogador como proprietário, manda uma mensagem dizendo que ele já tem uma casa no servidor e cancela a compra dessa nova.

  • Thanks 1
Link to comment
2 minutes ago, Lord Henry said:

Você poderia fazer um FOR que verifica todas as casas do server quando o player tenta comprar uma casa. Se já existir outra casa com esse jogador como proprietário, manda uma mensagem dizendo que ele já tem uma casa no servidor e cancela a compra dessa nova.

O Problema que não sei Fazer Um FOR Nunca Ouvi falar. Pd me ajudar? @Lord Henry

Edited by StarK001
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...