Jump to content

help script


HitmanLM

Recommended Posts

I'm having trouble getting this to work, I don't know how to activate this data I made

-- Client-side
table{
[1] = dxDrawImage(x*290, y*475, x*150, y*110, "img/gfx/grupo1.png", 0, 0, 0, tocolor(255, 255, 255, des1), false),
[2] = dxDrawImage(x*290, y*475, x*150, y*110, "img/gfx/grupo2.png", 0, 0, 0, tocolor(255, 255, 255, des1), false),
[3] = dxDrawImage(x*290, y*475, x*150, y*110, "img/gfx/grupo3.png", 0, 0, 0, tocolor(255, 255, 255, des1), false),
[4] = dxDrawImage(x*290, y*475, x*150, y*110, "img/gfx/semgrupo.png", 0, 0, 0, tocolor(255, 255, 255, des1), false),
}

local imagens = {
    [1] = true,
    [2] = false,
}
triggerServerEvent("chamarimagem", hitPlayer, imagens)




-- Server-side

addEvent("chamarimagem", true)
addEventHandler("chamarimagem", root, function (theImages)
function chamarimagem(thePlayer)
	if isObjectInACLGroup('user.'..ACL, aclGetGroup("grupo1")) then
		chamarimagem [1]
	elseif isObjectInACLGroup('user.'..ACL, aclGetGroup("grupo2")) then
		chamarimagem [2]
	elseif isObjectInACLGroup('user.'..ACL, aclGetGroup("grupo3")) then
		chamarimagem [3]
	else isObjectInACLGroup('user.'..ACL, aclGetGroup("semgrupo")) then
		chamarimagem [4]
	end
	end
	end
end
end

 

Link to comment

Hello HitmanLM,

does my adjustment give you any idea how to continue? Take a look:

-- Client-side
local img_names = {
[1] = "img/gfx/grupo1.png",
[2] = "img/gfx/grupo2.png",,
[3] = "img/gfx/grupo3.png",
[4] = "img/gfx/semgrupo.png"
}

local function draw_img(x, y, des1, n)
    dxDrawImage(x*290, y*475, x*150, y*110, img_names[n], 0, 0, 0, tocolor(255, 255, 255, des1), false)
end

local img_idx = false;

addEventHandler("onClientRender", root,
    function()
        if (img_idx) then
            -- TODO: use draw_img to draw the image, with n = img_idx
            
            dxDrawText("test: " .. img_idx, 100, 300);
        end
    end
);

local imagens = {
    [1] = true,
    [2] = false,
}
triggerServerEvent("chamarimagem", hitPlayer, imagens)

addEvent("onClientSelectPlayerGroup", true);
addEventHandler("onClientSelectPlayerGroup", root,
    function(idx)
        if not (source == localPlayer) then return; end;
        
        outputChatBox("selected group: " .. idx);
        
        img_idx = idx;
    end
);


-- Server-side

addEvent("chamarimagem", true)
addEventHandler("chamarimagem", root, function (theImages)
function chamarimagem()
        local theGroup
        if isObjectInACLGroup('user.'..ACL, aclGetGroup("grupo1")) then
            theGroup = 1
        elseif isObjectInACLGroup('user.'..ACL, aclGetGroup("grupo2")) then
            theGroup = 2
        elseif isObjectInACLGroup('user.'..ACL, aclGetGroup("grupo3")) then
            theGroup = 3
        else isObjectInACLGroup('user.'..ACL, aclGetGroup("semgrupo")) then
            theGroup = 4
        end
        triggerClientEvent(client, "onClientSelectPlayerGroup", client, theGroup);
    end
)
  • You are using a variable called "ACL" inside of the "chmarimagem" server-side event handler. Please adjust it to a proper value or explain what it is meant to do. Right now it looks like that the variable is not hooked up to any logic.
  • The client-side "onClientRender" event handler has been left for you to complete.
Edited by The_GTA
Link to comment

@The_GTA 

" You are using a variable called "ACL" inside of the "chmarimagem" server-side event handler. Please adjust it to a proper value or explain what it is meant to do. Right now it looks like that the variable is not hooked up to any logic.

The client-side "onClientRender" event handler has been left for you to complete. "
 

forgive me for not explaining i forgot, 
what I'm trying to do and what's next, when a player is set to group 1, 2 or 3 it activates the respective screen image of the group he was set to
Edited by HitmanLM
Link to comment

https://ibb.co/P1sRzq9

@The_GTA

 

I asked myself in the code, I don't know what to do, the problem is not the errors, but that I'm confused with the code :(

 

I don't know how to adjust my images to work, and I know it doesn't and the errors are preventing them from showing.

https://www.mediafire.com/file/r4kfn5w1nflu2v6/test.rar/file - I made a file to better understand what I'm trying to do
I set the group on the panel but the group doesn't activate at all, and I wanted that to happen when I set the group, the image automatically appears without the player needing to do anything

Edited by HitmanLM
Link to comment

There appears to be another error that I missed inside of your server-side code. Here is a fix:

addEvent("chamarimagem", true)
addEventHandler("chamarimagem", root,
    function (theImages)
        local theGroup
        if isObjectInACLGroup('user.'..ACL, aclGetGroup("grupo1")) then
            theGroup = 1
        elseif isObjectInACLGroup('user.'..ACL, aclGetGroup("grupo2")) then
            theGroup = 2
        elseif isObjectInACLGroup('user.'..ACL, aclGetGroup("grupo3")) then
            theGroup = 3
        else isObjectInACLGroup('user.'..ACL, aclGetGroup("semgrupo")) then
            theGroup = 4
        end
        triggerClientEvent(client, "onClientSelectPlayerGroup", client, theGroup);
    end
)

I wonder if you want to follow some basic Lua tutorials before starting full-fledged MTA development? You seem to hack things together, without logical connection. A big problem that is confusing me is the following part of your code:

triggerServerEvent("chamarimagem", hitPlayer, imagens)

Where did you copy it from and what were you thinking when you did?

Link to comment
"triggerServerEvent("chamarimagem", hitPlayer, imagens)"

"Where did you copy it from and what were you thinking when you did?"

this function is not used to join the server script with the client? at least I thought that this function would do that would call the client 
images that this function '' dxDrawImage " as I understand it doesn't work on the server as it is a correct client function?
Link to comment
8 hours ago, HitmanLM said:

this function is not used to join the server script with the client?

I think you meant to do it, yes. But you used a "hitPlayer" variable which is not defined anywhere. I think you should change the line to...

triggerServerEvent("chamarimagem", localPlayer, imagens)

You still have to fix the ACL variable as well as implement the drawing of the image. You need to insert code into the onClientRender event handler.

EDIT: the user has contacted me through private message because he is afraid of "making an essay".

Edited by The_GTA
Link to comment

 

sets the ACL all right, 

however I don't quite understand how the ''-- TODO part works: use draw_img to draw the image, with n = img_idx''

it also gave 2 errors that I didn't understand well.


-- client

local img_names = {
[1] = "img/gfx/BOPE.png",
[2] = "img/gfx/EB.png",
[3] = "img/gfx/PCRJ.png",
[4] = "img/gfx/semequipe.png",
}

local function draw_img(x, y, des1, n)
    dxDrawImage(x*290, y*475, x*150, y*110, img_names[n], 0, 0, 0, tocolor(255, 255, 255, des1), false)
end

local img_idx = false;

addEventHandler("onClientRender", root,
    function()
        if (img_idx) then
            -- TODO: use draw_img to draw the image, with n = img_idx
            dxDrawText("test: " .. img_idx, 100, 300);
        end
    end
);

local imagens = {
    [1] = true,
    [2] = false,
}
triggerServerEvent("chamarimagem", localPlayer, imagens)

addEvent("onClientSelectPlayerGroup", true);
addEventHandler("onClientSelectPlayerGroup", root,
    function(idx)
        if not (source == localPlayer) then return; end;
        
        outputChatBox("selected group: " .. idx);
        
        img_idx = idx;
    end
);

 

 

-- server

addEvent("chamarimagem", true)
addEventHandler("chamarimagem", root)
    function (theImages)
        local theGroup
		local ACL = getAccountName(getPlayerAccount(player))
        if isObjectInACLGroup('user.'..ACL, aclGetGroup("BOPE")) then
            theGroup = 1
        elseif isObjectInACLGroup('user.'..ACL, aclGetGroup("EB")) then
            theGroup = 2
        elseif isObjectInACLGroup('user.'..ACL, aclGetGroup("PCRJ")) then
            theGroup = 3
        elseif isObjectInACLGroup('user.'..ACL, aclGetGroup("semgrupo")) then
            theGroup = 4
        end
        triggerClientEvent(client, "onClientSelectPlayerGroup", client, theGroup);
    end


up1.png

Edited by HitmanLM
Link to comment
5 minutes ago, HitmanLM said:

 

addEvent("chamarimagem", true)
addEventHandler("chamarimagem", root)
    function (theImages)
        local theGroup
		local ACL = getAccountName(getPlayerAccount(player))
        if isObjectInACLGroup('user.'..ACL, aclGetGroup("BOPE")) then
            theGroup = 1
        elseif isObjectInACLGroup('user.'..ACL, aclGetGroup("EB")) then
            theGroup = 2
        elseif isObjectInACLGroup('user.'..ACL, aclGetGroup("PCRJ")) then
            theGroup = 3
        elseif isObjectInACLGroup('user.'..ACL, aclGetGroup("semgrupo")) then
            theGroup = 4
        end
        triggerClientEvent(client, "onClientSelectPlayerGroup", client, theGroup);
    end


up1.png

You made a mistake in applying the code that I gave you. If you read carefully then you should see that after root there is a comma (",") and not a curly-brackets (")"). Fix the script how I instructed you to and the error will disappear.

 

5 minutes ago, HitmanLM said:

however I don't quite understand how the ''-- TODO part works: use draw_img to draw the image, with n = img_idx''

draw_img is a function and you should call the function inside of the onClientRender event handler. Calling a function is done by using the function name and putting a curly-brackets after it with parameters inside into the code, for example...

func(p1, p2, p3)

 

Edited by The_GTA
  • Like 1
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...