Jump to content

[Help] Someone can help me with this?


trux_yt

Recommended Posts

 I don't have any changes to the database and i don't have errores in the debug, can anyone help me?

 

Quote

addEventHandler("textoComprado", root,
 function(player)
 local model = getElementModel(player) 
 exports.sql:query_free("UPDATE personaje SET skin = '" .. model .."' WHERE characterID = "..exports.players:getCharacterID(player)) --error
 exports.players:takeMoney(player, 200)
end
)

 

Link to comment

Hey,

The problem might be coming from the exported function (i.e. can't find the player or problem with the code there).
Also it would be good if you store the result of the exported function in a variable before the query.

local model = getElementModel(player)
local charID = exports.players:getCharacterID(player)

if model and charID then
	exports.sql:query_free("UPDATE personaje SET skin = '" .. model .."' WHERE characterID = '"..charID.."'")
else
	outputDebugString("Problem with either model or charID")
end

 

Edited by SpecT
Link to comment

I have a error with this too, i have this in the debug: 

Problem with either model or charID

This is my client-side function to ejecute this 

 

function keyShop(button)
    if (shop == true) then
        if (button == "arrow_l") then
            if (current > 1) then
                current = current - 1
                setElementModel(base, skins[current].id)
                playSoundFrontEnd(1)
            end
        elseif (button == "arrow_r") then
            if (current < #skins) then
                current = current + 1
                setElementModel(base, skins[current].id)
                playSoundFrontEnd(1)
            end
        elseif (button == "enter") then
            if (getElementModel(localPlayer) ~= skins[current].id) then
                if (getPlayerMoney() >= skins[current].valor) then 
                    setElementModel(localPlayer, skins[current].id)
                    playSoundFrontEnd(12)
                    closeShop()
					triggerServerEvent("textoComprado", localPlayer)
                else
                	outputChatBox("No tienes $200 para comprar la skin",255,0,0)
                end
            else
            	outputChatBox("Ya tienes esa skin",255,0,0)
            end
        elseif (button == "backspace") then
            closeShop()
        end
    end
end
bindKey("arrow_l", "down", keyShop)
bindKey("arrow_r", "down", keyShop)
bindKey("enter", "down", keyShop)
bindKey("backspace", "down", keyShop)

 

Link to comment

I wrote it like this so we will know if there is something wrong with the exported function called "getCharacterID" from the resource called "players".
Obviously there is a problem with it.
In this case we will need the code from this exported function I just mentioned.

Link to comment

Even if the function works in other resources correctly, you do not have to pass it. It has to be from the resource that I am programming. Can I pass the entire resource to show?

Edited by trux_yt
spanish to english
Link to comment

Oh wait my bad.

Yeah the problem is in the client-side where you trigger the server event.
The arguments for the function triggerServerEvent are eventName, source element and arguments. You only put the event name and the source element.
So you have 2 options: use source instead of player in the server function OR just put one more localPlayer argument in the triggerServerEvent.

Edited by SpecT
Link to comment

I have this error in client side bad argument triggerServerEvent [expected acl-group at argument 2, got boolean]

triggerServerEvent(localPlayer, "textoComprado", localplayer) --error

and this is my server side

addEventHandler("textoComprado", root,
 function()
 local model = getElementModel(source)
 local charID = exports.players:getCharacterID(source)

if model and charID then
	exports.sql:query_free("UPDATE characters SET skin = '" .. model .."' WHERE characterID = '"..charID.."'")
else
	outputDebugString("Problem with either model or charID")
end
end
)

 

Edited by trux_yt
code
Link to comment

Nothing men, nothing in the debug, i don't have changes in de db

 

--clientside
addEvent("N3xT.onShopSkin", true)


local screen = {guiGetScreenSize()} local x, y = (screen[1]/1366), (screen[2]/768)

local dxSkin = function()
    local moveY = interpolateBetween(0, 0, 0, 10, 0, 0, ((getTickCount() - tick) / 3000), "Linear")
    setCameraMatrix(213.5888671875, -101.4853515625-10+moveY, 1005.2578125,     216.7080078125, -101.546875, 1005.2578125 )
    dxDrawRectangleBorde(x*599, y*669, x*120, y*31, tocolor(0, 0, 0, 150), false)
    dxDrawText(skins[current].id.." | Valor - #006400$#ffffff"..skins[current].valor, x*610, y*676, x*710, y*686, tocolor(255, 255, 255, 255), x*1, "default-bold", "left", "top", false, false, false, true, false)
    dxDrawText("Usa las flechas para cambiar la skin", x*500, y*646, x*815, y*662, tocolor(255, 255, 255, 255), x*1, "default", "center", "top", false, false, false, false, false)
end

local shop
addEventHandler("N3xT.onShopSkin", root,
    function()
        if (shop ~= true) then
            shop = true
            current = 1
            tick = getTickCount()
            base = createPed(skins[current].id, 216.7080078125, -101.546875, 1005.2578125)
            setElementInterior(base, 15)
            setElementDimension(base, 14)
            setElementFrozen(base, true)
            setPedAnimation(base, "CLOTHES", "CLO_Pose_Torso")
            addEventHandler("onClientRender", root, dxSkin)
            showCursor(true)
            showChat(true)
            playSoundFrontEnd(8)
        end
    end
)

function keyShop(button)
    if (shop == true) then
        if (button == "arrow_l") then
            if (current > 1) then
                current = current - 1
                setElementModel(base, skins[current].id)
                playSoundFrontEnd(1)
            end
        elseif (button == "arrow_r") then
            if (current < #skins) then
                current = current + 1
                setElementModel(base, skins[current].id)
                playSoundFrontEnd(1)
            end
        elseif (button == "enter") then
            if (getElementModel(localPlayer) ~= skins[current].id) then
                if (getPlayerMoney() >= skins[current].valor) then 
                    setElementModel(localPlayer, skins[current].id)
                    playSoundFrontEnd(12)
                    closeShop()
					triggerServerEvent("textoComprado", localPlayer)
                else
                	outputChatBox("No tienes $200 para comprar la skin",255,0,0)
                end
            else
            	outputChatBox("Ya tienes esa skin",255,0,0)
            end
        elseif (button == "backspace") then
            closeShop()
        end
    end
end
bindKey("arrow_l", "down", keyShop)
bindKey("arrow_r", "down", keyShop)
bindKey("enter", "down", keyShop)
bindKey("backspace", "down", keyShop)

function closeShop()
    fadeCamera(false, 0.1, 0, 0, 0)
    removeEventHandler("onClientRender", root, dxSkin)
    showCursor(false)
    showChat(true)
    playSoundFrontEnd(20)
    destroyElement(base)
    setTimer(fadeCamera, 100, 1, true, 0.5)
    setTimer(setCameraTarget, 100, 1, localPlayer)
    shop = nil
    current = nil
end

function dxDrawRectangleBorde(left, top, width, height, color, postgui)
    if not postgui then
        postgui = false;
    end

    left, top = left + 2, top + 2;
    width, height = width - 4, height - 4;

    dxDrawRectangle(left - 2, top, 2, height, color, postgui);
    dxDrawRectangle(left + width, top, 2, height, color, postgui);
    dxDrawRectangle(left, top - 2, width, 2, color, postgui);
    dxDrawRectangle(left, top + height, width, 2, color, postgui);

    dxDrawRectangle(left - 1, top - 1, 1, 1, color, postgui);
    dxDrawRectangle(left + width, top - 1, 1, 1, color, postgui);
    dxDrawRectangle(left - 1, top + height, 1, 1, color, postgui);
    dxDrawRectangle(left + width, top + height, 1, 1, color, postgui);

    dxDrawRectangle(left, top, width, height, color, postgui);
end

-- serverside
addCommandHandler("skinshombre",
 function(player)
 local sq2l = exports.sql:query_assoc_single("SELECT genero FROM characters WHERE characterID = "..exports.players:getCharacterID(player))
 if sq2l.genero == 1 then
 triggerClientEvent("N3xT.onShopSkin", player)
 else
  outputChatBox("No eres un hombre",player,255,0,0)
 end
end
)

this is my all resource..

Link to comment

Well, now you edited the server-side function to be called by a command instead by an event.

From what I see in the server side the triggerClientEvent will be triggered for all the players online.
See documentation of triggerClientEvent. The first optional argument is the sendTo element, in this case "player".

triggerClientEvent(player, "N3xT.onShopSkin", player)

And what do you mean by "nothing" ? Nothing happens/opens or ?

Link to comment

Try This

addEvent("textoComprado", true)
addEventHandler("textoComprado", root,
 function()
 local model = getElementModel(source)
 local charID = exports.players:getCharacterID(source)

if (exports.sql:query_free("UPDATE characters SET skin= '" .. model .."' WHERE characterID = '"..charID.."'")) then
-- .....
end
	
end
)

 

Edited by Major . Mr3b
Link to comment

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