iFoReX Posted May 24, 2012 Share Posted May 24, 2012 who can help me with my script ?, I need create a SQL table for save the Positions and Skins , anyone can help me ? please Here the script theGUI GUIEditor_Window = {} GUIEditor_Button = {} GUIEditor_Label = {} GUIEditor_Edit = {} GUIEditor_Window[1] = guiCreateWindow(0.2783,0.2448,0.4063,0.4818,"GUI Make Peds",true) guiWindowSetMovable(GUIEditor_Window[1],false) guiWindowSetSizable(GUIEditor_Window[1],false) GUIEditor_Label[1] = guiCreateLabel(8,26,401,16,"-------------------------------------------------------------------------------",false,GUIEditor_Window[1]) guiSetFont(GUIEditor_Label[1],"clear-normal") GUIEditor_Label[2] = guiCreateLabel(9,49,49,17,"Skin ID : ",false,GUIEditor_Window[1]) GUIEditor_Edit[1] = guiCreateEdit(61,44,60,26,"",false,GUIEditor_Window[1]) guiEditSetMaxLength(GUIEditor_Edit[1],3) GUIEditor_Label[3] = guiCreateLabel(8,81,401,16,"-------------------------------------------------------------------------------",false,GUIEditor_Window[1]) guiSetFont(GUIEditor_Label[3],"clear-normal") GUIEditor_Edit[2] = guiCreateEdit(12,118,103,28,"",false,GUIEditor_Window[1]) GUIEditor_Edit[3] = guiCreateEdit(12,150,103,28,"",false,GUIEditor_Window[1]) GUIEditor_Edit[4] = guiCreateEdit(12,182,103,28,"",false,GUIEditor_Window[1]) GUIEditor_Button[1] = guiCreateButton(12,214,103,38,"Get Positions",false,GUIEditor_Window[1]) GUIEditor_Label[4] = guiCreateLabel(30,101,61,14,"POSITIONS",false,GUIEditor_Window[1]) guiSetFont(GUIEditor_Label[4],"default-bold-small") GUIEditor_Label[5] = guiCreateLabel(294,101,61,14,"ROTATION",false,GUIEditor_Window[1]) guiSetFont(GUIEditor_Label[5],"default-bold-small") GUIEditor_Edit[5] = guiCreateEdit(273,118,103,28,"",false,GUIEditor_Window[1]) GUIEditor_Edit[6] = guiCreateEdit(273,150,103,28,"",false,GUIEditor_Window[1]) GUIEditor_Edit[7] = guiCreateEdit(273,182,103,28,"",false,GUIEditor_Window[1]) GUIEditor_Button[2] = guiCreateButton(273,214,103,38,"Get Rotation",false,GUIEditor_Window[1]) GUIEditor_Label[6] = guiCreateLabel(11,262,182,15,"* Note : the Rotation is optional.",false,GUIEditor_Window[1]) guiLabelSetColor(GUIEditor_Label[6],255,0,0) guiSetFont(GUIEditor_Label[6],"default-bold-small") GUIEditor_Label[7] = guiCreateLabel(8,288,401,16,"-------------------------------------------------------------------------------",false,GUIEditor_Window[1]) guiSetFont(GUIEditor_Label[7],"clear-normal") GUIEditor_Button[3] = guiCreateButton(126,44,77,31,"Get my Skin",false,GUIEditor_Window[1]) GUIEditor_Button[4] = guiCreateButton(290,319,116,42,"Create the Ped and Save",false,GUIEditor_Window[1]) GUIEditor_Button[5] = guiCreateButton(218,319,69,42,"Reset",false,GUIEditor_Window[1]) GUIEditor_Button[6] = guiCreateButton(146,319,69,42,"Cancel",false,GUIEditor_Window[1]) guiSetVisible(GUIEditor_Window[1],false) showCursor(false) addEventHandler("onClientGUIClick", root, function() if source == GUIEditor_Button[1] then local x, y, z = getElementPosition( getLocalPlayer() ) guiSetText(GUIEditor_Edit[2], x) guiSetText(GUIEditor_Edit[3], y) guiSetText(GUIEditor_Edit[4], z) elseif source == GUIEditor_Button[2] then local rx, ry, rz = getElementRotation( getLocalPlayer() ) guiSetText(GUIEditor_Edit[5], rx) guiSetText(GUIEditor_Edit[6], ry) guiSetText(GUIEditor_Edit[7], rz) elseif source == GUIEditor_Button[3] then local skinID = getElementModel( getLocalPlayer() ) guiSetText(GUIEditor_Edit[1], skinID) elseif source == GUIEditor_Button[5] then guiSetText(GUIEditor_Edit[1], "") guiSetText(GUIEditor_Edit[2], "") guiSetText(GUIEditor_Edit[3], "") guiSetText(GUIEditor_Edit[4], "") guiSetText(GUIEditor_Edit[5], "") guiSetText(GUIEditor_Edit[6], "") guiSetText(GUIEditor_Edit[7], "") elseif source == GUIEditor_Button[6] then guiSetText(GUIEditor_Edit[1], "") guiSetText(GUIEditor_Edit[2], "") guiSetText(GUIEditor_Edit[3], "") guiSetText(GUIEditor_Edit[4], "") guiSetText(GUIEditor_Edit[5], "") guiSetText(GUIEditor_Edit[6], "") guiSetText(GUIEditor_Edit[7], "") guiSetVisible(GUIEditor_Window[1],false) showCursor(false) elseif source == GUIEditor_Button[4] then createPed((guiGetText(GUIEditor_Edit[1])), (guiGetText(GUIEditor_Edit[2])), (guiGetText(GUIEditor_Edit[3])), (guiGetText(GUIEditor_Edit[4])), (guiGetText(GUIEditor_Edit[5])), (guiGetText(GUIEditor_Edit[6])), (guiGetText(GUIEditor_Edit[7]))) end end ) addEvent("setVisiblePedGUI", true) addEventHandler("setVisiblePedGUI", getLocalPlayer(), function() guiSetVisible(GUIEditor_Window[1], not guiGetVisible(GUIEditor_Window[1])) showCursor(guiGetVisible(GUIEditor_Window[1])) end ) server-sd function opGUI ( thePlayer ) local accName = getAccountName ( getPlayerAccount ( thePlayer ) ) if isObjectInACLGroup ( "user.".. accName, aclGetGroup ( "Admin" ) ) then triggerClientEvent ( thePlayer, "setVisiblePedGUI", thePlayer ) end end addEventHandler ( "onPlayerJoin", root, function ( ) bindKey ( source, "F3", "down", opGUI ) end ) addEventHandler ( "onResourceStart", resourceRoot, function ( ) for index, player in ipairs ( getElementsByType ( "player" ) ) do bindKey ( player, "F3", "down", opGUI ) end end ) Link to comment
Kenix Posted May 24, 2012 Share Posted May 24, 2012 http://dev.mysql.com/doc/refman/5.6/en/tutorial.html https://wiki.multitheftauto.com/wiki/Ser ... _functions Link to comment
iFoReX Posted May 25, 2012 Author Share Posted May 25, 2012 yeh kenix, but how ? this is good for start ? executeSQLCreateTable ( "Peds", "PosX", "PosY", "PosZ" ) Link to comment
Castillo Posted May 25, 2012 Share Posted May 25, 2012 No, you set the columns in wrong syntax. Each column definition is separated by a comma (,) (e.g. field1,field2,field3 or field1 INTEGER,field2 TEXT as definition) Link to comment
Jaysds1 Posted May 25, 2012 Share Posted May 25, 2012 actually, it's: executeSQLCreateTable ( "Peds", "PosX, PosY, PosZ" ) Link to comment
FWCentral Posted May 25, 2012 Share Posted May 25, 2012 executeSQLCreateTable(“peds“, “posx REAL, posy REAL, posz REAL“) Thats what you need to put im on mobile it might be wrong. Link to comment
Flaker Posted May 25, 2012 Share Posted May 25, 2012 use "dbExec", it is much easier! addCommandHandler ( "create_table", function () example_connection = dbConnect( "mysql", "dbname=frank;host=1.2.3.4", "username", "password", "share=1" ) --Just as example if ( example_connection )then dbExec ( example_connection, "CREATE TABLE IF NOT EXISTS data (Account TEXT, Skin INT, PosX INT, PosY INT, PosZ INT)" ) outputDebugString ( "Successfully connected to data base" ) else outputDebugString ( "Failed to connect to data base", 3 ) end end ) Link to comment
Alpha Posted May 25, 2012 Share Posted May 25, 2012 You have 'mysql' in your dbConnect, should be 'sqlite' since he's using executeSQL* functions. Link to comment
Flaker Posted May 25, 2012 Share Posted May 25, 2012 What about: example_connection = dbConnect( "sqlite", "file.db" ) ? Link to comment
Alpha Posted May 25, 2012 Share Posted May 25, 2012 Yes, this will connect with the SQLite database called 'file.db'. Link to comment
Flaker Posted May 25, 2012 Share Posted May 25, 2012 Yes, and we can use dbExec with it) Link to comment
iFoReX Posted May 25, 2012 Author Share Posted May 25, 2012 Flaker if I use DbConnect I need a localHost and I dont have it Link to comment
Alpha Posted May 25, 2012 Share Posted May 25, 2012 Mota, dbConnect can be used to connect to a SQLite database. Check the wiki documentation: dbConnect Link to comment
iFoReX Posted May 25, 2012 Author Share Posted May 25, 2012 addEventHandler( 'onResourceStart', resourceRoot, function() executeSQLQuery( "CREATE TABLE IF NOT EXISTS peds (\ ID Peds, SkinPeds REAL, X REAL, Y REAL, Z REAL,\ rX REAL, rY REAL, rZ REAL )" ) this is good ? Link to comment
Castillo Posted May 25, 2012 Share Posted May 25, 2012 No. addEventHandler ( "onResourceStart", resourceRoot, function ( ) executeSQLQuery ( "CREATE TABLE IF NOT EXISTS peds ( ID Peds, X REAL, Y REAL, Z REAL, rX REAL, rY REAL, rZ REAL )" ) end ) Link to comment
Kenix Posted May 25, 2012 Share Posted May 25, 2012 addEventHandler( 'onResourceStart', resourceRoot, function() executeSQLQuery( "CREATE TABLE IF NOT EXISTS peds (\ ID Peds, SkinPeds REAL, X REAL, Y REAL, Z REAL,\ rX REAL, rY REAL, rZ REAL )" ) this is good ? All is good but where 'end' and ') '? Link to comment
iFoReX Posted May 25, 2012 Author Share Posted May 25, 2012 Ok... now... what is bad ? addEventHandler("onResourceStop", resourceRoot, function() triggerClientEvent("exportarPeds", ped) local x, y, z = getElementPosition( ped ) local modelo = getElementModel( ped ) local rotX, rotY, rotZ = getElementRotation( ped ) executeSQLQuery ( "INSERT INTO peds ( ID Peds, X, Y, Z, rX, rY, rZ ) VALUES ( IDPed+1, modelo, xP, yP, zP, rotX, rotY, rotZ ) " ) end ) function botoones() if source == GUIEditor_Button[1] then local x, y, z = getElementPosition( getLocalPlayer() ) guiSetText(GUIEditor_Edit[2], x) guiSetText(GUIEditor_Edit[3], y) guiSetText(GUIEditor_Edit[4], z) elseif source == GUIEditor_Button[2] then local rx, ry, rz = getElementRotation( getLocalPlayer() ) guiSetText(GUIEditor_Edit[5], rx) guiSetText(GUIEditor_Edit[6], ry) guiSetText(GUIEditor_Edit[7], rz) elseif source == GUIEditor_Button[3] then local skinID = getElementModel( getLocalPlayer() ) guiSetText(GUIEditor_Edit[1], skinID) elseif source == GUIEditor_Button[5] then guiSetText(GUIEditor_Edit[1], "") guiSetText(GUIEditor_Edit[2], "") guiSetText(GUIEditor_Edit[3], "") guiSetText(GUIEditor_Edit[4], "") guiSetText(GUIEditor_Edit[5], "") guiSetText(GUIEditor_Edit[6], "") guiSetText(GUIEditor_Edit[7], "") elseif source == GUIEditor_Button[6] then guiSetText(GUIEditor_Edit[1], "") guiSetText(GUIEditor_Edit[2], "") guiSetText(GUIEditor_Edit[3], "") guiSetText(GUIEditor_Edit[4], "") guiSetText(GUIEditor_Edit[5], "") guiSetText(GUIEditor_Edit[6], "") guiSetText(GUIEditor_Edit[7], "") guiSetVisible(GUIEditor_Window[1],false) showCursor(false) elseif source == GUIEditor_Button[4] then ped = createPed((guiGetText(GUIEditor_Edit[1])), (guiGetText(GUIEditor_Edit[2])), (guiGetText(GUIEditor_Edit[3])), (guiGetText(GUIEditor_Edit[4])), (guiGetText(GUIEditor_Edit[5])), (guiGetText(GUIEditor_Edit[6])), (guiGetText(GUIEditor_Edit[7]))) end end addEvent("exportarPeds", true) addEventHandler("exportarPeds", getLocalPlayer(), botoones) addEventHandler("onClientGUIClick", root, botoones ) Link to comment
Jaysds1 Posted May 25, 2012 Share Posted May 25, 2012 (edited) ped isn't defined in the server-side script. function botoones() local x, y, z = getElementPosition( getLocalPlayer() ) local skinID = getElementModel( getLocalPlayer() ) if source == GUIEditor_Button[1] then guiSetText(GUIEditor_Edit[2], x) guiSetText(GUIEditor_Edit[3], y) guiSetText(GUIEditor_Edit[4], z) elseif source == GUIEditor_Button[2] then guiSetText(GUIEditor_Edit[5], rx) guiSetText(GUIEditor_Edit[6], ry) guiSetText(GUIEditor_Edit[7], rz) elseif source == GUIEditor_Button[3] then guiSetText(GUIEditor_Edit[1], skinID) elseif source == GUIEditor_Button[5] then guiSetText(GUIEditor_Edit[1], "") guiSetText(GUIEditor_Edit[2], "") guiSetText(GUIEditor_Edit[3], "") guiSetText(GUIEditor_Edit[4], "") guiSetText(GUIEditor_Edit[5], "") guiSetText(GUIEditor_Edit[6], "") guiSetText(GUIEditor_Edit[7], "") elseif source == GUIEditor_Button[6] then guiSetText(GUIEditor_Edit[1], "") guiSetText(GUIEditor_Edit[2], "") guiSetText(GUIEditor_Edit[3], "") guiSetText(GUIEditor_Edit[4], "") guiSetText(GUIEditor_Edit[5], "") guiSetText(GUIEditor_Edit[6], "") guiSetText(GUIEditor_Edit[7], "") guiSetVisible(GUIEditor_Window[1],false) showCursor(false) elseif source == GUIEditor_Button[4] then ped = createPed((guiGetText(GUIEditor_Edit[1])), (guiGetText(GUIEditor_Edit[2])), (guiGetText(GUIEditor_Edit[3])), (guiGetText(GUIEditor_Edit[4])), (guiGetText(GUIEditor_Edit[5])), (guiGetText(GUIEditor_Edit[6])), (guiGetText(GUIEditor_Edit[7]))) end end addEvent("exportarPeds", true) addEventHandler("exportarPeds", getLocalPlayer(), botoones) --why did you add this to the function? addEventHandler("onClientGUIClick", guiRoot, botoones,true )--always include a bool at the end for button/gui click events Edited May 25, 2012 by Guest Link to comment
Alpha Posted May 25, 2012 Share Posted May 25, 2012 executeSQLQuery ( "INSERT INTO peds ( ID Peds, X, Y, Z, rX, rY, rZ ) VALUES ( IDPed+1, modelo, xP, yP, zP, rotX, rotY, rotZ ) " ) IDPed+1?? That's not correct at all, you must retrieve the IDPed from the database first. Link to comment
Jaysds1 Posted May 25, 2012 Share Posted May 25, 2012 (edited) I think I know what he's trying to do... Server: local peds addEventHandler("onResourceStart",resourceRoot,function() peds = get("@peds") if(not peds)then peds = 0 set("@peds",0) end end) addEvent("savePed",true) addEventHandler("savePed",root,function(ped) if(ped)then local x, y, z = getElementPosition( ped ) local modelo = getElementModel( ped ) local rotX, rotY, rotZ = getElementRotation( ped ) local peds = peds+1 set("peds",peds) executeSQLInsert ( " peds","'"..peds.."', '"..modelo.."', '"..xP.."', '"..yP.."', '"..zP.."', '"..rotX.."', '"..rotY.."', '"..rotZ.."'") end end) Client: function botoones() local x, y, z = getElementPosition( getLocalPlayer() ) local skinID = getElementModel( getLocalPlayer() ) if source == GUIEditor_Button[1] then guiSetText(GUIEditor_Edit[2], x) guiSetText(GUIEditor_Edit[3], y) guiSetText(GUIEditor_Edit[4], z) elseif source == GUIEditor_Button[2] then guiSetText(GUIEditor_Edit[5], rx) guiSetText(GUIEditor_Edit[6], ry) guiSetText(GUIEditor_Edit[7], rz) elseif source == GUIEditor_Button[3] then guiSetText(GUIEditor_Edit[1], skinID) elseif source == GUIEditor_Button[5] then guiSetText(GUIEditor_Edit[1], "") guiSetText(GUIEditor_Edit[2], "") guiSetText(GUIEditor_Edit[3], "") guiSetText(GUIEditor_Edit[4], "") guiSetText(GUIEditor_Edit[5], "") guiSetText(GUIEditor_Edit[6], "") guiSetText(GUIEditor_Edit[7], "") elseif source == GUIEditor_Button[6] then guiSetText(GUIEditor_Edit[1], "") guiSetText(GUIEditor_Edit[2], "") guiSetText(GUIEditor_Edit[3], "") guiSetText(GUIEditor_Edit[4], "") guiSetText(GUIEditor_Edit[5], "") guiSetText(GUIEditor_Edit[6], "") guiSetText(GUIEditor_Edit[7], "") guiSetVisible(GUIEditor_Window[1],false) showCursor(false) elseif source == GUIEditor_Button[4] then ped = createPed((guiGetText(GUIEditor_Edit[1])), (guiGetText(GUIEditor_Edit[2])), (guiGetText(GUIEditor_Edit[3])), (guiGetText(GUIEditor_Edit[4])), (guiGetText(GUIEditor_Edit[5])), (guiGetText(GUIEditor_Edit[6])), (guiGetText(GUIEditor_Edit[7]))) triggerServerEvent("savePed",localPlayer,ped) end end addEventHandler("onClientGUIClick", guiRoot, botoones,true )--always include a bool at the end for button/gui click events Edited May 26, 2012 by Guest Link to comment
iFoReX Posted May 26, 2012 Author Share Posted May 26, 2012 doesnt save the peds Jaysd , when I restart the resource the Ped disappear Link to comment
Jaysds1 Posted May 26, 2012 Share Posted May 26, 2012 oh, sorry, I forgot to add a query for getting the peds x,y,z,rx,ry,rz etc... Link to comment
iFoReX Posted May 26, 2012 Author Share Posted May 26, 2012 when I restart the resource the ped disappear :c Link to comment
Jaysds1 Posted May 26, 2012 Share Posted May 26, 2012 sorry, try this, Server: local peds addEventHandler("onResourceStart",resourceRoot,function() pedsTable = executeSQLQuery("SELECT * FROM peds") for i,v in ipairs(pedsTable)do local ped = createPed(modelo.v,xP.v,yP.v,zP.v) setElementRotation(ped,rotX.v,rotY.v,rotZ.v) peds = (peds.v) end end) addEvent("savePed",true) addEventHandler("savePed",root,function(ped) if(ped)then local x, y, z = getElementPosition( ped ) local modelo = getElementModel( ped ) local rotX, rotY, rotZ = getElementRotation( ped ) local peds = peds+1 set("peds",peds) executeSQLInsert ("peds","'"..peds.."','"..modelo.."', '"..xP.."', '"..yP.."', '"..zP.."', '"..rotX.."', '"..rotY.."', '"..rotZ.."'") end end) Link to comment
iFoReX Posted May 26, 2012 Author Share Posted May 26, 2012 when I restart the resource doesnt save Jaysd 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