Jump to content

help me with a SQL Table


iFoReX

Recommended Posts

Posted

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 
) 

elMota/elFoReX De Vuelta En MTA *---------*

Cuenta De Youtube En La Que Subo Tutoriales Acerca De MTA :3

https://www.youtube.com/user/KillersGPs

430x73_FFFFFF_FF9900_000000_000000.png
Posted

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)

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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 
) 

Posted
  
  
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 ?

elMota/elFoReX De Vuelta En MTA *---------*

Cuenta De Youtube En La Que Subo Tutoriales Acerca De MTA :3

https://www.youtube.com/user/KillersGPs

430x73_FFFFFF_FF9900_000000_000000.png
Posted

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 
) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
  
  
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 ') '?

http://vk.com/the_kenix

Вопросы задавайте на форуме, не пишите мне в личку.

Please don't pm me.

Posted

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 ) 

elMota/elFoReX De Vuelta En MTA *---------*

Cuenta De Youtube En La Que Subo Tutoriales Acerca De MTA :3

https://www.youtube.com/user/KillersGPs

430x73_FFFFFF_FF9900_000000_000000.png
Posted (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 by Guest

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

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

Posted (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 by Guest

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

Posted

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) 

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

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