Jump to content

[HELP] Saving/loading data to a mysql database


..:D&G:..

Recommended Posts

Posted

Hello guys, I am using mta paradise so I can learn more scripting, and I've come across something I never knew how to do.

addEvent( "items:drop", true ) 
addEventHandler( "items:drop", root, 
    function( slot ) 
        if source == client then 
            if exports.players:isLoggedIn( source ) then 
                local item = get( source )[ slot ] 
                if item then 
                    local id = item.item 
                    local value = item.value 
                    local name = item.name or getName( id ) 
                    local x,y,z = getElementPosition(source) 
                    local ang = getPedRotation(source) 
                    local dim = getElementDimension ( source ) 
                    local int = getElementInterior ( source ) 
                    local obj = 1271 
                    if(id == 1) then obj = 1581 
                    elseif(id == 3) then 
                    if(value == 10) then obj = 2663 
                    elseif(value == 30) then obj = 2663 
                    end 
                    elseif(id == 4) then 
                    if(value == 20) then obj = 2647 
                    else 
                    end 
                    elseif(id == 9) then  
                    if(value == 12) then obj = 1578 
                    elseif(value == 13) then obj = 1575 
                    else 
                    end 
                    else obj = 1271 
                    end 
                    local drop = createObject ( obj, x+math.sin(math.rad(-ang)), y+math.cos(math.rad(-ang)), z - 0.85, 90, 0, math.random (0, 360) ) 
                    if drop then 
                    setElementData ( drop, "id", id ) 
                    setElementData ( drop, "value", value ) 
                    setElementData ( drop, "name", name ) 
                    setElementInterior ( drop, int ) 
                    setElementDimension ( drop, dim ) 
                    take( source, slot ) 
                    local posx, posy, posz = getElementPosition ( drop ) 
                    exports.sql:query_insertid( "INSERT INTO dropitems (id, value, name, posx, posy, posz, int, dim) VALUES (" .. id .. ", " .. value .. ", " .. name .. ", " .. posx .. ", " .. posy .. ", " .. posz .. ", " .. int .. ", " .. dim .. ")")   
                    exports.chat:me( source, "drops a " .. name .. "." ) 
                    end 
                    outputChatBox( "This " ..name.. " has ID " .. slot .. ".", source, 0, 255, 0 ) 
                end 
            end 
        end 
    end 
) 

This was supposed to save the items droped (the items do drop and there are no errors). I cannot say it looks good to me, because I don't know anything about saving into a mysql database. Even tho I drop the item, and it is droped, it doesn't save in the database, any ideas why?

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