Jump to content

Serverside y Clientside


aka Blue

Recommended Posts

Buenas nuevamente, he tenido un problemilla con una función para mi script de mecánico. Resulta que hace poco aprendí a usar los exports de colorBlender (fijandome en demás scripts y tal) y estuve creando mi apartado de "pinturas" de mi script de meca. Bueno, el error que tengo o mejor dicho, duda, es, ¿se puede poner una variable? actualmente utilizo ésto:

  
triggerServerEvent ( "onPintura", localPlayer, r,g,b, 1) 
  

El 2 de ese código es como una variable, es decir, en el serverside sería algo así

  
function pintarlo ( player, r, g, b, pintura ) 
local vehicle = getPedOccupiedVehicle( player ) 
    if vehicle and r and g and b then 
            r1, g1, b1, r2, g2, b2 = getVehicleColor(vehicle, true) 
            if pintura == 1 then 
                setVehicleColor (vehicle, r, g, b, r2, g2, b2) 
            elseif pintura == 2 then 
                setVehicleColor (vehicle, r1, g1, b1, r, g, b) 
        end 
    end 
end 
addEvent( "onPintura", true ) 
addEventHandler( "onPintura", getRootElement(), pintarlo) 
  

No sé si es posible hacer como una pequeña variable, cambiado ese "2" para poder así, usar la función del export de paradise para poder guardar el color en la base de datos.

Link to comment

Hola jaja.

Bueno, a ver. Quiero hacer que al hacer la función de pintar (setVehicleColor), se almacene en mi base de datos mediante un export que trae la GM de Paradise.

Éste

  
exports.sql:query_free( "UPDATE vehicles SET color1 = " .. AQUIIRIALAVARIABLE .. ", color2 = " .. AQUIIRIALAVARIABLEDOS .. " WHERE vehicleID = " .. data.vehicleID ) 
  

Daré un pequeño ejemplo. El triggerServerClient en el apartado cliente del script (el panel), trae una ¿variable se le podría llamar? llamada 1 y 2, dependiendo de la capa (capa 1 = numerito 1, capa 2 = numerito 2) y en el serverside se utilizan esos numeritos para definir que capa pintar. Lo que quiero hacer es cambiar esos numeritos por pequeñas variables para poder añadirlas al export.

Los numeritos en el clientside

  
function Pintarla1(id, hex, r, g, b) 
        triggerServerEvent ( "onPintura", localPlayer, localPlayer, r,g,b, 1) 
        removeEventHandler( "onColorPickerOK", localPlayer, Pintarla1) 
end 
  
function Pintarla2(id, hex, r, g, b) 
        triggerServerEvent ( "onPintura", localPlayer, localPlayer, r,g,b, 2) 
        removeEventHandler( "onColorPickerOK", localPlayer, Pintarla2) 
end 
  

Los numeritos en el serverside

  
function pintarlo ( player, r, g, b, pintura ) 
local vehicle = getPedOccupiedVehicle( player ) 
    if vehicle and r and g and b then 
            r1, g1, b1, r2, g2, b2 = getVehicleColor(vehicle, true) 
            if pintura == 1 then 
                setVehicleColor (vehicle, r, g, b, r2, g2, b2) 
            elseif pintura == 2 then 
                setVehicleColor (vehicle, r1, g1, b1, r, g, b) 
        end 
    end 
end 
addEvent( "onPintura", true ) 
addEventHandler( "onPintura", getRootElement(), pintarlo) 
  

PD: No me importa publicar el código ya que ese script lo pondré en la comunidad :P

Link to comment

No estoy muy seguro de que quieres realmente xD

es algo como esto ?

function Pintarla1(id, hex, r, g, b) 
        triggerServerEvent ( "onPintura", localPlayer, localPlayer, r,g,b, "rojo") 
        removeEventHandler( "onColorPickerOK", localPlayer, Pintarla1) 
end 
  
function Pintarla2(id, hex, r, g, b) 
        triggerServerEvent ( "onPintura", localPlayer, localPlayer, r,g,b, "verde") 
        removeEventHandler( "onColorPickerOK", localPlayer, Pintarla2) 
end 

function pintarlo ( player, r, g, b, pintura ) 
local vehicle = getPedOccupiedVehicle( player ) 
    if vehicle and r and g and b then 
            r1, g1, b1, r2, g2, b2 = getVehicleColor(vehicle, true) 
            if pintura == "rojo" then 
                setVehicleColor (vehicle, r, g, b, r2, g2, b2) 
            elseif pintura == "verde" then 
                setVehicleColor (vehicle, r1, g1, b1, r, g, b) 
        end 
    end 
end 
addEvent( "onPintura", true ) 
addEventHandler( "onPintura", getRootElement(), pintarlo) 

Link to comment

Quería saber si se podía hacer, en vez de usar el == verde, simplemente usar, if color1, elseif color2. No sé si me doy a entender muy bien xD, dejo un código de ejemplo de lo que querría hacer.

  
function pintarlo ( player, r, g, b, color1, color2) 
local vehicle = getPedOccupiedVehicle( player ) 
local data = vehicles[ vehicle ] 
    if vehicle and r and g and b then 
            r1, g1, b1, r2, g2, b2 = getVehicleColor(vehicle, true) 
            if color1 then 
                exports.sql:query_free( "UPDATE vehicles SET color1 = "..color1.." WHERE vehicleID = " .. data.vehicleID) 
                setVehicleColor (vehicle, r, g, b, r2, g2, b2) 
            elseif color2 then 
                exports.sql:query_free( "UPDATE vehicles SET color2 = "..color2.." WHERE vehicleID = " .. data.vehicleID) 
                setVehicleColor (vehicle, r1, g1, b1, r, g, b) 
        end 
    end 
end 
addEvent( "onPintura", true ) 
addEventHandler( "onPintura", getRootElement(), pintarlo) 
  

ClientSide que quede algo así.

  
function Pintarla1(id, hex, r, g, b) 
        triggerServerEvent ( "onPintura", localPlayer, localPlayer, r,g,b, color1) 
        removeEventHandler( "onColorPickerOK", localPlayer, Pintarla1) 
end 
  
function Pintarla2(id, hex, r, g, b) 
        triggerServerEvent ( "onPintura", localPlayer, localPlayer, r,g,b, color2) 
        removeEventHandler( "onColorPickerOK", localPlayer, Pintarla2) 
end 
  

Link to comment

Puedes mostrar la parte donde ejecutas estas dos funciones

function Pintarla1(id, hex, r, g, b) 
        triggerServerEvent ( "onPintura", localPlayer, localPlayer, r,g,b, color1) 
        removeEventHandler( "onColorPickerOK", localPlayer, Pintarla1) 
end 
  
function Pintarla2(id, hex, r, g, b) 
        triggerServerEvent ( "onPintura", localPlayer, localPlayer, r,g,b, color2) 
        removeEventHandler( "onColorPickerOK", localPlayer, Pintarla2) 
end 

Link to comment

Aquí tienes todo el clientside. Como dije anteriormente, me da igual postear todo el código ya que será un script que publicaré para la comunidad de MTA :mrgreen:

  
function abrirelpanel() 
panelcolor = guiCreateWindow(452, 230, 291, 250, "Capas de pintura", false) 
guiWindowSetSizable(panelcolor, false) 
capa1 = guiCreateButton(92, 37, 107, 49, "Capa 1", false, panelcolor) 
capa2 = guiCreateButton(92, 111, 107, 49, "Capa 2", false, panelcolor) 
Cerrar = guiCreateButton(92, 190, 107, 49, "Cerrar", false, panelcolor)    
addEventHandler("onClientGUIClick", Cerrar, cerrarlo) 
addEventHandler("onClientGUIClick", capa1, capita1) 
addEventHandler("onClientGUIClick", capa2, capita2) 
showCursor (true) 
end 
addEvent( "onColorC", true ) 
addEventHandler( "onColorC", localPlayer, abrirelpanel ) 
  
function cerrarlo() 
destroyElement(panelcolor) 
showCursor (false) 
end 
  
function capita1() 
exports.colorblender:openPicker (1, 0, "Capa 1") addEventHandler( "onColorPickerOK", localPlayer, Pintarla1) 
end 
  
function capita2() 
exports.colorblender:openPicker (1, 0, "Capa2") addEventHandler( "onColorPickerOK", localPlayer, Pintarla2) 
end 
  
function Pintarla1(id, hex, r, g, b) 
        triggerServerEvent ( "onPintura", localPlayer, localPlayer, r,g,b, "color1") 
        removeEventHandler( "onColorPickerOK", localPlayer, Pintarla1) 
end 
  
function Pintarla2(id, hex, r, g, b) 
        triggerServerEvent ( "onPintura", localPlayer, localPlayer, r,g,b, "color2") 
        removeEventHandler( "onColorPickerOK", localPlayer, Pintarla2) 
end 
  

Link to comment

si pero en ese caso creo que ya no se podria usar elseif

si no te quedaria algo asi

function pintarlo ( player, r, g, b, color1, color2) 
local vehicle = getPedOccupiedVehicle( player ) 
local data = vehicles[ vehicle ] 
    if vehicle and r and g and b then 
            r1, g1, b1, r2, g2, b2 = getVehicleColor(vehicle, true) 
            if color1 then 
                exports.sql:query_free( "UPDATE vehicles SET color1 = "..color1.." WHERE vehicleID = " .. data.vehicleID) 
                setVehicleColor (vehicle, r, g, b, r2, g2, b2) 
            end 
            if color2 then 
                exports.sql:query_free( "UPDATE vehicles SET color2 = "..color2.." WHERE vehicleID = " .. data.vehicleID) 
                setVehicleColor (vehicle, r1, g1, b1, r, g, b) 
            end 
        end 
    end 
end 
addEvent( "onPintura", true ) 
addEventHandler( "onPintura", getRootElement(), pintarlo) 

y el client te quedaría algo asi

function abrirelpanel() 
panelcolor = guiCreateWindow(452, 230, 291, 250, "Capas de pintura", false) 
guiWindowSetSizable(panelcolor, false) 
capa1 = guiCreateButton(92, 37, 107, 49, "Capa 1", false, panelcolor) 
capa2 = guiCreateButton(92, 111, 107, 49, "Capa 2", false, panelcolor) 
Cerrar = guiCreateButton(92, 190, 107, 49, "Cerrar", false, panelcolor)   
addEventHandler("onClientGUIClick", getRootElement(), cerrarlo) 
showCursor (true) 
end 
addEvent( "onColorC", true ) 
addEventHandler( "onColorC", localPlayer, abrirelpanel ) 
  
function onGuiClick() 
  if source == Cerrar then 
     destroyElement(panelcolor) 
     showCursor (false) 
  elseif source = capa1 then 
     exports.colorblender:openPicker (1, 0, "Capa 1") addEventHandler( "onColorPickerOK", localPlayer, Pintarla1) 
  elseif source = capa2 
     exports.colorblender:openPicker (1, 0, "Capa2") addEventHandler( "onColorPickerOK", localPlayer, Pintarla2) 
  end 
end 
  
  
function Pintarla1(id, hex, r, g, b) 
        triggerServerEvent ( "onPintura", localPlayer, localPlayer, r,g,b, true, false) 
        removeEventHandler( "onColorPickerOK", localPlayer, Pintarla1) 
end 
  
function Pintarla2(id, hex, r, g, b) 
        triggerServerEvent ( "onPintura", localPlayer, localPlayer, r,g,b, false, true) 
        removeEventHandler( "onColorPickerOK", localPlayer, Pintarla2) 
end 

Link to comment

Ahora pues cuando le doy a pintar, no lo pinta.

  
function abrirelpanel() 
panelcolor = guiCreateWindow(452, 230, 291, 250, "Capas de pintura", false) 
guiWindowSetSizable(panelcolor, false) 
capa1 = guiCreateButton(92, 37, 107, 49, "Capa 1", false, panelcolor) 
capa2 = guiCreateButton(92, 111, 107, 49, "Capa 2", false, panelcolor) 
Cerrar = guiCreateButton(92, 190, 107, 49, "Cerrar", false, panelcolor)    
addEventHandler("onClientGUIClick", Cerrar, cerrarlo) 
addEventHandler("onClientGUIClick", capa1, capita1) 
addEventHandler("onClientGUIClick", capa2, capita2) 
showCursor (true) 
end 
addEvent( "onColorC", true ) 
addEventHandler( "onColorC", localPlayer, abrirelpanel ) 
  
function cerrarlo() 
destroyElement(panelcolor) 
showCursor (false) 
end 
  
function capita1() 
exports.colorblender:openPicker (1, 0, "Capa 1") addEventHandler( "onColorPickerOK", localPlayer, Pintarla1) 
end 
  
function capita2() 
exports.colorblender:openPicker (1, 0, "Capa2") addEventHandler( "onColorPickerOK", localPlayer, Pintarla2) 
end 
  
function Pintarla1(id, hex, r, g, b, color1) 
        triggerServerEvent ( "onPintura", localPlayer, localPlayer, r,g,b, color1) 
        removeEventHandler( "onColorPickerOK", localPlayer, Pintarla1) 
end 
  
function Pintarla2(id, hex, r, g, b, color2) 
        triggerServerEvent ( "onPintura", localPlayer, localPlayer, r,g,b, color2) 
        removeEventHandler( "onColorPickerOK", localPlayer, Pintarla2) 
end 
  

Puse el color1 o color2 en cada función de "Pintarla" (1,2) pero igual probé sin eso y no va. No me marca ningun error en la consola, tampoco en debugscript.

Link to comment

perdón xD cometí un error pruebalo nuevamente

function abrirelpanel() 
panelcolor = guiCreateWindow(452, 230, 291, 250, "Capas de pintura", false) 
guiWindowSetSizable(panelcolor, false) 
capa1 = guiCreateButton(92, 37, 107, 49, "Capa 1", false, panelcolor) 
capa2 = guiCreateButton(92, 111, 107, 49, "Capa 2", false, panelcolor) 
Cerrar = guiCreateButton(92, 190, 107, 49, "Cerrar", false, panelcolor)   
addEventHandler("onClientGUIClick", getRootElement(), onGuiClick) 
showCursor (true) 
end 
addEvent( "onColorC", true ) 
addEventHandler( "onColorC", localPlayer, abrirelpanel ) 
  
function onGuiClick() 
  if source == Cerrar then 
     destroyElement(panelcolor) 
     showCursor (false) 
  elseif source == capa1 then 
     exports.colorblender:openPicker (1, 0, "Capa 1") addEventHandler( "onColorPickerOK", localPlayer, Pintarla1) 
  elseif source == capa2 then 
     exports.colorblender:openPicker (1, 0, "Capa2") addEventHandler( "onColorPickerOK", localPlayer, Pintarla2) 
  end 
end 
  
  
function Pintarla1(id, hex, r, g, b) 
        triggerServerEvent ( "onPintura", localPlayer, localPlayer, r,g,b, true, false) 
        removeEventHandler( "onColorPickerOK", localPlayer, Pintarla1) 
end 
  
function Pintarla2(id, hex, r, g, b) 
        triggerServerEvent ( "onPintura", localPlayer, localPlayer, r,g,b, false, true) 
        removeEventHandler( "onColorPickerOK", localPlayer, Pintarla2) 
end 
  

Link to comment

aca te dejo los dos pruebalo si te anda

function abrirelpanel() 
panelcolor = guiCreateWindow(452, 230, 291, 250, "Capas de pintura", false) 
guiWindowSetSizable(panelcolor, false) 
capa1 = guiCreateButton(92, 37, 107, 49, "Capa 1", false, panelcolor) 
capa2 = guiCreateButton(92, 111, 107, 49, "Capa 2", false, panelcolor) 
Cerrar = guiCreateButton(92, 190, 107, 49, "Cerrar", false, panelcolor)   
addEventHandler("onClientGUIClick", getRootElement(), onGuiClick) 
showCursor (true) 
end 
addEvent( "onColorC", true ) 
addEventHandler( "onColorC", localPlayer, abrirelpanel ) 
  
function onGuiClick() 
  if source == Cerrar then 
     destroyElement(panelcolor) 
     showCursor (false) 
  elseif source == capa1 then 
     exports.colorblender:openPicker (1, 0, "Capa 1") addEventHandler( "onColorPickerOK", localPlayer, Pintarla1) 
  elseif source == capa2 then 
     exports.colorblender:openPicker (1, 0, "Capa2") addEventHandler( "onColorPickerOK", localPlayer, Pintarla2) 
  end 
end 
  
  
function Pintarla1(id, hex, r, g, b) 
        triggerServerEvent ( "onPintura", localPlayer, localPlayer, r,g,b, true, false) 
        removeEventHandler( "onColorPickerOK", localPlayer, Pintarla1) 
end 
  
function Pintarla2(id, hex, r, g, b) 
        triggerServerEvent ( "onPintura", localPlayer, localPlayer, r,g,b, false, true) 
        removeEventHandler( "onColorPickerOK", localPlayer, Pintarla2) 
end 
  

function pintarlo ( player, r, g, b, color1, color2) 
local vehicle = getPedOccupiedVehicle( player ) 
local data = vehicles[ vehicle ] 
    if vehicle and r and g and b then 
            r1, g1, b1, r2, g2, b2 = getVehicleColor(vehicle, true) 
            if color1 then 
                exports.sql:query_free( "UPDATE vehicles SET color1 = "..color1.." WHERE vehicleID = " .. data.vehicleID) 
                setVehicleColor (vehicle, r, g, b, r2, g2, b2) 
            end 
            if color2 then 
                exports.sql:query_free( "UPDATE vehicles SET color2 = "..color2.." WHERE vehicleID = " .. data.vehicleID) 
                setVehicleColor (vehicle, r1, g1, b1, r, g, b) 
            end 
        end 
end 
addEvent( "onPintura", true ) 
addEventHandler( "onPintura", getRootElement(), pintarlo) 

Link to comment

Acabo de verlo así rápidamente y me pareció rara ésta parte.

  
function Pintarla1(id, hex, r, g, b) 
        triggerServerEvent ( "onPintura", localPlayer, localPlayer, r,g,b, true, false) 
        removeEventHandler( "onColorPickerOK", localPlayer, Pintarla1) 
end 
  
function Pintarla2(id, hex, r, g, b) 
        triggerServerEvent ( "onPintura", localPlayer, localPlayer, r,g,b, false, true) 
        removeEventHandler( "onColorPickerOK", localPlayer, Pintarla2) 
end 
  
  

¿No debería haber una variable ahí? Osea, color1 y color2 que sería la función del serverside ya que el error dice que color1 y color2 no son nada (hasta donde entiendo).

Link to comment

reemplaza esa parte por esto y ya debería funcionarte

function Pintarla1(id, hex, r, g, b) 
        triggerServerEvent ( "onPintura", localPlayer, localPlayer, r,g,b, "color1", false) 
        removeEventHandler( "onColorPickerOK", localPlayer, Pintarla1) 
end 
  
function Pintarla2(id, hex, r, g, b) 
        triggerServerEvent ( "onPintura", localPlayer, localPlayer, r,g,b, false, "color2") 
        removeEventHandler( "onColorPickerOK", localPlayer, Pintarla2) 
end 

Link to comment
Muestra algún ejemplo de cómo debe de quedar guardado en el mysql. ¿Hasta ahora te devuelve el color en RGB?

Son las dos tablas de Paradise, color1 y color2. Lo que pasa es que mi función utiliza el colorBlender que lo saca en formato RGB y eso no lo lee, por lo que veo.

Pasa lo siguiente. Pongo el comando y tal, el panel, selecciono el color, se pinta todo pero al reiniciar el resource, vuelve el mismo color, osea, que no lo guarda. Si necesitas ss o código mismo de las tablas del script o cualquier cosa, dime.

Link to comment

Se debería guardar en formato RGB.

No, no jaja, uso un export de colorBlender, puedes ver más arriba el código completo (el que funciona es el que me arregló alex), ahí están todas las funciones. Creo que te refieres a formato como RGB, en ese caso sí, guardarlas en formato RGB, supongo (?.

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...