Jump to content

MySql Questions


Axel

Recommended Posts

Posted

So i'm new to MySql, i know just some basics. I'l post here some questions. First of all:

  
addEventHandler( "onResourceStart", getResourceRootElement( ), 
    function( ) 
        local result = mysql:query("SELECT gangs, teren, color1, color2, color3, alpha, x, y, sizex, sizey FROM turfs") 
        if (result) then 
            local continue = true 
            while continue do 
                row = mysql:fetch_assoc(result) 
                if not (row) then 
                    break 
                end 
                local gangs = tonumber(row["gangs"])     
                local teren = tostring(row["teren"]) 
                local color1 = tonumber(row["color1"]) 
                local color2 = tonumber(row["color2"]) 
                local color3 = tonumber(row["color3"])   
                local alpha = tonumber(row["alpha"]) 
                local x = tonumber(row["x"])     
                local y = tonumber(row["y"]) 
                local sizex = tonumber(row["sizex"]) 
                local sizey = tonumber(row["sizey"]) 
                local shape = createColRectangle(x, y, sizex, sizey) 
                local turf = createRadarArea(x,y,sizex,sizey,color1,color2,color3,alpha) 
            end 
            mysql:free_result(result) 
        end 
    end 
) 
  

This loads from MySql data about turfs, and creates them. All fine, but my question:

How do i use it in another script? Like i want onColShapeHit on the shape but nothing works..

Posted
  
proColshape = createColSphere(0,0,0, 5) -- your colshape (coords 0,0,0, radius 5) 
  
addEventHandler( "onColShapeHit", proColshape, 
    function( ) 
        local result = mysql:query("SELECT gangs, teren, color1, color2, color3, alpha, x, y, sizex, sizey FROM turfs") 
        if (result) then 
            local continue = true 
            while continue do 
                row = mysql:fetch_assoc(result) 
                if not (row) then 
                    break 
                end 
                local gangs = tonumber(row["gangs"])     
                local teren = tostring(row["teren"]) 
                local color1 = tonumber(row["color1"]) 
                local color2 = tonumber(row["color2"]) 
                local color3 = tonumber(row["color3"])   
                local alpha = tonumber(row["alpha"]) 
                local x = tonumber(row["x"])     
                local y = tonumber(row["y"]) 
                local sizex = tonumber(row["sizex"]) 
                local sizey = tonumber(row["sizey"]) 
                local shape = createColRectangle(x, y, sizex, sizey) 
                local turf = createRadarArea(x,y,sizex,sizey,color1,color2,color3,alpha) 
            end 
            mysql:free_result(result) 
        end 
    end 
) 
  

I guess this would do the trick?

Posted

No.. you understood me wrong, the script i posted takes data from sql and creates the turfs and colshapes, i want to use onColShapeHit on the colshape... but that does'nt work..

Posted

Oh I see... Well in that case, add an event handler for onColShapeHit right after you create it

  
 local shape = createColRectangle(x, y, sizex, sizey) 
addEventHandler("onColShapeHit", shape, functionToCall) 
  

Posted

What's wrong in this insert...

  
local r1,g1,b1,a1 = 0,0,0,100 
local query = mysql:query_free("INSERT INTO turfs SET color1=" .. mysql:escape_string(r1) .. ", color2="  .. mysql:escape_string(g1) .. ", color3=" .. mysql:escape_string(b1) .. ", alpha=" .. mysql:escape_string(a1) .. " ") 
if (query) then 
setRadarAreaColor(turf,0,0,0,100) 
setRadarAreaFlashing(turf,false) 
outputChatBox("Ai castigat teritoriul Dragonilor rosii!",thePlayer,255,100,0) 
else 
outputChatBox("Eroare 20000, raporteaza pe forum!",thePlayer,255,100,0) 
end 
end,20000,1) 
  

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