Jump to content

مشكلة بمود حفظ المكان


mody134

Recommended Posts

لما احفظ المكان يتحفظ بس لما اطلع وادخل المكان الي حفظتة يختفي 

 

Client 


______________________________________________


local sw,sh=guiGetScreenSize()

----------------
-- Window
----------------
local x,y = (sw-419)/2,(sh-294)/2
Window = guiCreateWindow(x, y, 419, 294, "=[ Save Places System ]=", false)
guiSetAlpha(Window, 1.00)
guiSetProperty(Window, "CaptionColour", "FF18EB13")
guiSetVisible(Window,false)
Lbl1 = guiCreateLabel(10, 30, 270, 15, "=[ Save Places ]=", false, Window)
guiSetFont(Lbl1, "default-bold-small")
guiLabelSetColor(Lbl1, 253, 0, 0)
Close = guiCreateButton(356, 26, 47, 25, "✖", false, Window)
guiSetFont(Close, "default-bold-small")
guiSetProperty(Close, "NormalTextColour", "FF0D62EE")
List = guiCreateGridList(9, 63, 184, 221, false, Window)
guiGridListAddColumn(List, "      The Place       ", 0.7)
NamePlace = guiCreateEdit(202, 85, 201, 24, "", false, Window)
guiEditSetMaxLength(NamePlace, 15)
Lbl2 = guiCreateLabel(260, 68, 94, 17, "Place Name : ", false, Window)
guiSetFont(Lbl2, "default-bold-small")
guiLabelSetColor(Lbl2, 241, 206, 9)
Add = guiCreateButton(207, 123, 191, 20, "Add Place", false, Window)
guiSetFont(Add, "default-bold-small")
guiSetProperty(Add, "NormalTextColour", "FF1A77DF")
Warp = guiCreateButton(207, 160, 191, 20, "Warp To Place", false, Window)
guiSetFont(Warp, "default-bold-small")
guiSetProperty(Warp, "NormalTextColour", "FF1A77DF")
Delete = guiCreateButton(207, 198, 191, 20, "Delete Place", false, Window)
guiSetFont(Delete, "default-bold-small")
guiSetProperty(Delete, "NormalTextColour", "FF1A77DF")
Lbl2 = guiCreateLabel(207, 250, 210, 15, "", false, Window)
guiSetFont(Lbl2, "default-bold-small")
guiLabelSetColor(Lbl2, 255, 255, 0)

---------------
-- On Click
---------------

addEventHandler("onClientGUIClick",guiRoot,function()
    if ( source == Warp ) then
        local Select = guiGridListGetSelectedItem(List)
        local getNamePlaceFromList = guiGridListGetItemText(List,Select,1)
        if ( tostring(getNamePlaceFromList) ) then
            triggerServerEvent("WarpPlace",localPlayer,tostring(getNamePlaceFromList))
            guiSetVisible(Window,false)
            showCursor(false)
            guiSetInputEnabled(false)
        else
            outputChatBox("Please Select Place .",255,0,0,true)
        end
    elseif ( source == Delete ) then
        local Select = guiGridListGetSelectedItem(List)
        local getNamePlaceFromList = guiGridListGetItemText(List,Select,1)
        if ( tostring(getNamePlaceFromList) ) then
            triggerServerEvent("DeletePlace",localPlayer,tostring(getNamePlaceFromList))
        else
            outputChatBox("Please Select Place .",255,0,0,true)
        end
    elseif ( source == Add ) then
        local Name = guiGetText(NamePlace)
        if ( tostring(Name) and string.len(tostring(Name)) >= 1 ) then
            triggerServerEvent("AddNewPlace",localPlayer,tostring(Name))
        end
    elseif ( source == Close ) then
        guiSetVisible(Window,false)
        showCursor(false)
        guiSetInputEnabled(false)
    end
end)

-----------------------
-- Event From Server
-----------------------

addEvent("UpPleaceToList",true)
addEventHandler("UpPleaceToList",root,function(Table)
    guiGridListClear(List)
    for _,v in ipairs(Table) do
        local row = guiGridListAddRow(List)
        guiGridListSetItemText(List,row,1,tostring(v.NamePlaceT),false,false)
        guiGridListSetItemColor(List,row,1,0,255,255)
    end
end)


_________________________________

Server

_________________________________



addEventHandler("onResourceStart",resourceRoot,function()
    executeSQLQuery("CREATE TABLE IF NOT EXISTS PlaceSystem (NamePlace,SerialPlr,X,Y,Z) ")
end)

addEvent("AddNewPlace",true)
addEventHandler("AddNewPlace",root,function(Name)
    local serial = getPlayerSerial(source)
    local Row = executeSQLQuery("SELECT * FROM PlaceSystem WHERE SerialPlr=?",tostring(serial))
    if ( Row and Row ~= 0 ) then
        for _,v in ipairs(Row) do
            if ( tostring(v.NamePlace) == tostring(Name) ) then
                outputChatBox("Please Choose Another Name .",source,255,0,0,true)
                return
            end
        end
    end
    local x,y,z = getElementPosition(source)
    executeSQLQuery("INSERT INTO PlaceSystem (NamePlace,SerialPlr,X,Y,Z) VALUES (?,?,?,?,?)",tostring(Name),tostring(serial),tostring(x),tostring(y),tostring(z))
    outputChatBox("Successfully Add Place [ "..tostring(Name).." ]",source,0,0,255,true)
    sendPlaceForClient(source,serial)
end)

addEvent("WarpPlace",true)
addEventHandler("WarpPlace",root,function(Name)
    local skin = getElementModel(source)
    if ( Name and string.len(Name) >= 1 ) then
        local Row = executeSQLQuery("SELECT * FROM PlaceSystem WHERE SerialPlr=? AND NamePlace=?",getPlayerSerial(source),Name)
        if ( type(Row) == "table" and Row == 0 or not Row ) then
            outputChatBox("Please Select Place .",source,255,0,0,true)
            return
        end
        spawnPlayer(source,Row[1]["X"],Row[1]["Y"],Row[1]["Z"],math.random(0,270),skin)
    else
        outputChatBox("Please Select Place .",source,255,0,0,true)
    end
end)

addEvent("UpPleacesOnOpenWindow",true)
addEventHandler("UpPleacesOnOpenWindow",root,function()
    sendPlaceForClient(source,getPlayerSerial(source))
end)

addEvent("DeletePlace",true)
addEventHandler("DeletePlace",root,function(Name)
    if ( Name and string.len(Name) >= 1 ) then
        local Row = executeSQLQuery("SELECT * FROM PlaceSystem WHERE SerialPlr=? AND NamePlace=?",getPlayerSerial(source),Name)
        executeSQLQuery("DELETE FROM PlaceSystem WHERE NamePlace =? AND X=? AND Y=? AND Z=? AND SerialPlr=?",Name,Row[1]["X"],Row[1]["Y"],Row[1]["Z"],getPlayerSerial(source))
        sendPlaceForClient(source,getPlayerSerial(source))
    end
end)

function sendPlaceForClient(plr,serial)
    local Table = {}
    for _,v in ipairs (getPleaces(serial)) do
        table.insert(Table,{NamePlaceT = v.NamePlace,})
    end
    triggerClientEvent(plr,"UpPleaceToList",plr,Table)
end

function getPleaces(Serial)
    if ( Serial and type(Serial) == "string" ) then
        local Row = executeSQLQuery("SELECT * FROM PlaceSystem WHERE SerialPlr=?",tostring(Serial))
        if ( type(Row) == "table" and #Row == 0 or not Row ) then
            return {}
        else
            return Row
        end
    end
end

 

Edited by mody134
Link to comment
1 minute ago, The&Smile said:

المشكلة في قواعد البيانات :-D

ياريتك ما رديت هههههههه

الحين اذا الواحد رد يقوله 

المشكلة في قواعد البيانات :)

هو يبي يعرف المشكله + الحل حقها علي ما اعتقد .

واذا ع اساس انه يتعلم فـ 

:lol::oops:

Link to comment

يمكن يفيدك هل المود
 

https://forum.multitheftauto.com/topic/85731-%D8%A7%D9%84%D8%A7%D8%B5%D8%AF%D8%A7%D8%B1-%D8%A7%D9%84%D8%AB%D8%A7%D9%86%D9%8A-%D9%85%D9%86-%D8%B3%D9%83%D8%B1%D8%A8%D8%AA-%D8%AD%D9%81%D8%B8-%D8%A7%D9%84%D9%85%D9%83%D8%A7%D9%86-20-place-system/

حمل المود و اتعلم منو 

Link to comment
  • 1 month later...
1 hour ago, mody134 said:

:) عايز حل

onResourceStart 
-- Use The Useful Function  
function sendPlaceForClient(plr,serial)
    local Table = {}
    for _,v in ipairs (getPleaces(serial)) do
        table.insert(Table,{NamePlaceT = v.NamePlace,})
    end
    triggerClientEvent(plr,"UpPleaceToList",plr,Table)
end

or 

-- On Open Your Panel

triggerServerEvent

-- Use The Useful Function 

function sendPlaceForClient(plr,serial)
    local Table = {}
    for _,v in ipairs (getPleaces(serial)) do
        table.insert(Table,{NamePlaceT = v.NamePlace,})
    end
    triggerClientEvent(plr,"UpPleaceToList",plr,Table)
end

 

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