Jump to content

Event się nie wykonuje.


Recommended Posts

Cześć. Ostatnio postanowiłem napisać sobie prosty skrypcik markerów(tych w grze) w MySQL.

Ładowanie i Tworzenie markerów działa lecz nie działa mi Event który chce wykonać mianowicie chodzi o:

  
--Kod ze strony klienta (client-side) 
function test( ) 
    outputChatBox("test") 
end 
addEventHandler("onClientMarkerHit", marker_create[1], test) 
  

A tutaj mam wczytywanie markerów i dodawanie ich do tablicy.

  
--Kod ze strony servera (server-side) 
marker_create = {} 
local total = 0 
function loadAllMarkers() 
    total = 0 
    local query = string.format("SELECT uid, x, y, z, type, size, r, g, b, a, other_arg FROM markers") 
    local wyniki = exports.SQL:sql_getTableResult( query ) 
    for _, v in ipairs( wyniki ) do 
        marker_create[v.uid] = createMarker (v.x, v.y, v.z , v.type, v.size, v.r, v.g, v.b, v.a) 
        total = total + 1 
    end 
    setTimer(reload_markers, 15*60*1000, 0) 
    outputServerLog("Total markers: " .. total) 
end 
addEventHandler("onResourceStart", resourceRoot, loadAllMarkers) 
  
--Użycie funkcji marker_link daje taki sam rezultat czyli nic 
function marker_link( uid ) 
    local uid = tonumber(uid) 
    if (marker_create[uid]) then 
        return marker_create[uid] 
    else 
        outputServerLog("Nie moge uzyskac linku do markera o id: " .. uid) 
    end 
end 

Dodatkowo dodam że w logach nie mam żadnych błędów nawet przy debugscript 3.

Proszę o pomoc. Pozdrawiam :)

Link to comment

Zrobiłem to inaczej teraz jest po stronie serwera lecz nie działa.

Zero warrningów i errorów.

  
function test_marker( markerHit ) 
     if markerHit == marker_create[1] then 
          outputConsole("Dziala") 
     else 
          outputConsole("Nie dziala") 
     end 
end 
addEventHandler("onPlayerMarkerHit", getRootElement(), test_marker) 
  

W konsoli wyświetla mi się Nie działa ale marker widać :)

--Jeszcze moge powiedzieć że gdy nie daje markerów w tablicy a z zmiennej to wszystko działa ale chciałbym aby dzialalo w tablicy.

Link to comment

Dobra zastosowałem Output Debug String.

Oto kod ServerSide:

marker_create = {} 
function loadAllMarkers() 
    total = 0 
    local query = string.format("SELECT uid, x, y, z, type, size, r, g, b, a, other_arg FROM gt_markers") 
    local wyniki = exports.SQL:sql_getTableResult( query ) 
    outputDebugString ( "Pobieram wszystkie markery" ) 
    for _, v in ipairs( wyniki ) do 
        marker_create[v.uid] = createMarker (v.x, v.y, v.z , v.type, v.size, v.r, v.g, v.b, v.a) 
        total = total + 1 
         
        if marker_create[v.uid] then 
            outputDebugString ( "Marker id: " .. v.uid .. " Wczytany!" ) 
        else 
            outputDebugString ( "Nie moge wczytac do tablicy: " .. v.uid ) 
        end 
    end 
    --setTimer(reload_markers, 15*60*1000, 0) 
    outputServerLog("Total markers: " .. total) 
end 
addEventHandler("onResourceStart", resourceRoot, loadAllMarkers) 
  
function test_marker( markerHit ) 
    outputDebugString ( "Event Wywolany" ) 
    if markerHit == marker_create[1] then 
        outputDebugString ( "marker_create[1] dziala." ) 
    else 
        outputDebugString ( "marker_create[1] niedziala" ) 
    end 
end 
addEventHandler("onPlayerMarkerHit", getRootElement(), test_marker) 
  

a to client-side

GUIWyladuj = { 
    tab = {}, 
    progressbar = {}, 
    tabpanel = {}, 
    label = {}, 
    button = {} 
} 
  
function showGuiRozladuj() 
    GUIWyladuj.tabpanel[1] = guiCreateTabPanel(515, 235, 411, 430, false) 
  
    GUIWyladuj.tab[1] = guiCreateTab("Informacje.", GUIWyladuj.tabpanel[1]) 
  
    GUIWyladuj.button[1] = guiCreateButton(10, 35, 391, 54, "Rozładuj towar.", false, GUIWyladuj.tab[1]) 
    addEventHandler("onClientGUIClick", GUIWyladuj.button[1], 
    function() 
        triggerServerEvent("rozladujTowar", getRootElement()) 
    end) 
     
    GUIWyladuj.label[1] = guiCreateLabel(139, 7, 134, 24, "Menu", false, GUIWyladuj.tab[1]) 
    guiSetFont(GUIWyladuj.label[1], "clear-normal") 
    guiLabelSetHorizontalAlign(GUIWyladuj.label[1], "center", false) 
    guiLabelSetVerticalAlign(GUIWyladuj.label[1], "center") 
    GUIWyladuj.progressbar[1] = guiCreateProgressBar(11, 99, 390, 52, false, GUIWyladuj.tab[1]) 
    guiProgressBarSetProgress(GUIWyladuj.progressbar[1], 85) 
  
    GUIWyladuj.label[2] = guiCreateLabel(10, 10, 370, 27, "Poziom załadowania towaru.", false, GUIWyladuj.progressbar[1]) 
    guiSetFont(GUIWyladuj.label[2], "clear-normal") 
    guiLabelSetColor(GUIWyladuj.label[2], 0, 0, 0) 
    guiLabelSetHorizontalAlign(GUIWyladuj.label[2], "center", false) 
    guiLabelSetVerticalAlign(GUIWyladuj.label[2], "center") 
  
    GUIWyladuj.progressbar[2] = guiCreateProgressBar(11, 161, 390, 52, false, GUIWyladuj.tab[1]) 
    guiProgressBarSetProgress(GUIWyladuj.progressbar[3], 85) 
  
    GUIWyladuj.label[3] = guiCreateLabel(10, 10, 370, 26, "Waga towaru. (3000kg)", false, GUIWyladuj.progressbar[2]) 
    guiSetFont(GUIWyladuj.label[3], "clear-normal") 
    guiLabelSetColor(GUIWyladuj.label[3], 0, 0, 0) 
    guiLabelSetHorizontalAlign(GUIWyladuj.label[3], "center", false) 
    guiLabelSetVerticalAlign(GUIWyladuj.label[3], "center") 
  
    GUIWyladuj.label[4] = guiCreateLabel(12, 221, 389, 175, "Informacje o towarze:\nKategoria: Towary Nie legalne\nTowar: Nielegalny\nblalblba\nxdw\ndsadsa", false, GUIWyladuj.tab[1]) 
    guiLabelSetHorizontalAlign(GUIWyladuj.label[4], "center", false) 
    guiLabelSetVerticalAlign(GUIWyladuj.label[4], "center") 
     
    GUIWyladuj.button[2] = guiCreateButton(327, 161, 62, 14, "Zamknij", false, GUIWyladuj.label[4]) 
    guiSetVisible(GUIWyladuj.tabpanel[1], false) 
    addEventHandler("onClientGUIClick", GUIWyladuj.button[2], 
    function() 
        guiSetVisible(GUIWyladuj.tabpanel[1], false) 
        showCursor( false ) 
    end) 
end 
  
function GUIRozladuj( ) 
    showGuiRozladuj() 
    outputConsole("Gogogogo") 
    guiSetVisible(GUIWyladuj.tabpanel[1], true) 
    showCursor( true ) 
end 
addEvent("showGUIRozladuj", true) 
addEventHandler("showGUIRozladuj", getRootElement(), GUIRozladuj) 
  
addEvent("hideGUIZal_Wyl", true) 
addEventHandler("hideGUIZal_Wyl", getRootElement(), 
function() 
    guiSetVisible(GUIWyladuj.tabpanel[1], false) 
    showCursor( false ) 
end) 
  
  
function new3d_text( x, y, z, str ) 
    local px,py,pz = getElementPosition(getLocalPlayer()) 
    local distance = getDistanceBetweenPoints3D ( x,y,z,px,py,pz ) 
    if distance <= 150 then 
        local sx,sy = getScreenFromWorldPosition ( x, y, z+0.95, 0.06 ) 
    if not sx then return end 
    local scale = 1/(0.3 * (distance / 150)) 
    local str = tostring( str ) 
    dxDrawText ( str, sx, sy - 30, sx, sy - 30, tocolor(255,255,255,255), math.min ( 0.4*(150/distance)*1.4,4), "default", "center", "bottom", false, false, false ) 
    end 
end 
  
addEventHandler("onClientRender",getRootElement(), 
function() 
    new3d_text(2720.84375, -2405.4248046875, 10.4609375, "Strefa załadunku") 
    new3d_text(2720.3291015625, -2504.177734375, 10.485120773315, "Strefa załadunku") 
end) 

A oto logi:

[2014-02-08 16:44:27] INFO: Pobieram wszystkie markery 
[2014-02-08 16:44:27] INFO: Marker id: 1 Wczytany! 
[2014-02-08 16:44:27] INFO: Marker id: 2 Wczytany! 
[2014-02-08 16:46:44] INFO: Event Wywolany 
[2014-02-08 16:46:44] INFO: marker_create[1] niedziala 

Link to comment

Dobra wszystko działa.

Zrobiłem sobie jeszcze zmienną lokalną która formatuje liczbe do stringu i tak wygląda mój kawałek kodu.

  
for _, v in ipairs( wyniki ) do 
    local str = string.format("%d", v.uid) 
    marker_create[str] = createMarker (v.x, v.y, v.z , v.type, v.size, v.r, v.g, v.b, v.a) 
        total = total + 1 
         
    if marker_create[v.uid] then 
        outputDebugString ( "Marker id: " .. v.uid .. " Wczytany!" ) 
    else 
        outputDebugString ( "Nie moge wczytac do tablicy: " .. v.uid ) 
    end 
end 

Dziękuję ci bardzo za pomoc!

Bo próbowałem wielu metod ale tutaj już nie wiedziałem co mam zrobić :)

Jeszcze raz dzięki pozdrawiam.

Link to comment
  • 2 weeks later...

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