Jump to content

[Help]dxDrawImage


Gripex

Recommended Posts

function Remove()
if assignShow == false then return false end
	    for i = 1,5 do
	        if isMouseInRectPosition(assignSlots[i][1], assignSlots[i][2], assignSlots[i][3], assignSlots[i][4]) then
				if assigns[i] then
				    triggerServerEvent("remove", resourceRoot, assigns[i]["key"], assigns[i]["item"])
					iprint(assigns[i]["key"], assigns[i]["item"])
			end
		end
	end
end


addEvent("showItems", true)
addEventHandler("showItems", root,
function (assignItems)
    if assignShow then
	    if #assignItems == 0 then
			iprint(assignShow)
		    return
		end
	    assigns = assignItems
		local maxKeys = 5
		iprint(assignShow)
	for i, v in ipairs(assigns) do
		if assigns[i]["item"] == "Buster" then assigns[i]["item"] = "pizza" end
	    img1 = assignItems[1] and {["img"] = ":images/"..assignItems[1]["item"]..".png", ["key"] = assignItems[1]["key"]}
		img2 = assignItems[2] and {["img"] = ":images/"..assignItems[2]["item"]..".png", ["key"] = assignItems[2]["key"]}
		img3 = assignItems[3] and {["img"] = ":images/"..assignItems[3]["item"]..".png", ["key"] = assignItems[3]["key"]}
		img4 = assignItems[4] and {["img"] = ":images/"..assignItems[4]["item"]..".png", ["key"] = assignItems[4]["key"]}
		img5 = assignItems[5] and {["img"] = ":images/"..assignItems[5]["item"]..".png", ["key"] = assignItems[5]["key"]}
   if i >= maxKeys then break end
end
	else
	    if #assignItems == 0 then
		    removeEventHandler("onClientClick", root, assignKeysRemove)
            assignShow = false
		iprint(assignShow)
		    return
		end
	    assigns = assignItems
		local maxKeys = 5
		iprint(assignShow)
	for i, v in ipairs(assigns) do
		if assigns[i]["item"] == "Buster" then assigns[i]["item"] = "pizza" end
	    img1 = assignItems[1] and {["img"] = ":images/"..assignItems[1]["item"]..".png", ["key"] = assignItems[1]["key"]}
		img2 = assignItems[2] and {["img"] = ":images/"..assignItems[2]["item"]..".png", ["key"] = assignItems[2]["key"]}
		img3 = assignItems[3] and {["img"] = ":images/"..assignItems[3]["item"]..".png", ["key"] = assignItems[3]["key"]}
		img4 = assignItems[4] and {["img"] = ":images/"..assignItems[4]["item"]..".png", ["key"] = assignItems[4]["key"]}
		img5 = assignItems[5] and {["img"] = ":images/"..assignItems[5]["item"]..".png", ["key"] = assignItems[5]["key"]}
   if i >= maxKeys then break end
end
		addEventHandler("onClientClick", root, Remove)
        assignShow = true
	end
end)

it had Problem

when i click on isMouseInRectPosition(assignSlots[1], assignSlots[2], assignSlots[3], assignSlots[4]) iprint work but item doesn't remove but if i removed this loop for i, v in ipairs(assigns) do it will work fine, any Help?

Link to comment
  • Moderators
57 minutes ago, Gripex said:

do it will work fine, any Help?

Clean up your code and add comments, then I do not mind take a look at it.

Currently I am looking at alien code...

  • Haha 1
Link to comment
54 minutes ago, IIYAMA said:

Clean up your code and add comments, then I do not mind take a look at it.

Currently I am looking at alien code...

addEvent("showItems", true)
addEventHandler("showItems", root,
function (assignItems)
    if assignShow then
	    if #assignItems == 0 then
			iprint(assignShow)
		    return
		end
	    assigns = assignItems
	    img1 = assignItems[1] and {["img"] = ":images/"..assignItems[1]["item"]..".png", ["key"] = assignItems[1]["key"]}
		img2 = assignItems[2] and {["img"] = ":images/"..assignItems[2]["item"]..".png", ["key"] = assignItems[2]["key"]}
		img3 = assignItems[3] and {["img"] = ":images/"..assignItems[3]["item"]..".png", ["key"] = assignItems[3]["key"]}
		img4 = assignItems[4] and {["img"] = ":images/"..assignItems[4]["item"]..".png", ["key"] = assignItems[4]["key"]}
		img5 = assignItems[5] and {["img"] = ":images/"..assignItems[5]["item"]..".png", ["key"] = assignItems[5]["key"]}
	else
	    if #assignItems == 0 then
		    removeEventHandler("onClientRender", root, assignKeysUI)
		    removeEventHandler("onClientClick", root, assignKeysRemove)
            assignShow = false

		    return
		end
	    assigns = assignItems
	    img1 = assignItems[1] and {["img"] = ":images/"..assignItems[1]["item"]..".png", ["key"] = assignItems[1]["key"]}
		img2 = assignItems[2] and {["img"] = ":images/"..assignItems[2]["item"]..".png", ["key"] = assignItems[2]["key"]}
		img3 = assignItems[3] and {["img"] = ":images/"..assignItems[3]["item"]..".png", ["key"] = assignItems[3]["key"]}
		img4 = assignItems[4] and {["img"] = ":images/"..assignItems[4]["item"]..".png", ["key"] = assignItems[4]["key"]}
		img5 = assignItems[5] and {["img"] = ":images/"..assignItems[5]["item"]..".png", ["key"] = assignItems[5]["key"]}
        addEventHandler("onClientRender", root, assignKeysUI)
		addEventHandler("onClientClick", root, assignKeysRemove)
        assignShow = true
	end
end)

Thats cleaned COde, i want if get assignItems[1]["item"] like assignItems[1]["item"] == "Test" then change Test to Any name i want it  like assignItems[1]["item"] == "Test1"

Link to comment
  • Moderators
2 hours ago, Gripex said:

Thats cleaned COde, i want if get assignItems[1]["item"] like assignItems[1]["item"] == "Test" then change Test to Any name i want it  like assignItems[1]["item"] == "Test1"

That is still an alien explanation.

But let me give you 2 concepts

addCommandHandler("changeItem", 
function (cmd, index, value)
	index = tonumber(index)
	if index and value then
		assignItems[index]["item"] = value
		outputChatBox("set!")
	end
end, false) -- not caseSensitive


addCommandHandler("changeItemIfValue", 
function (cmd, value, newValue)
	if value and newValue then
		--[[
			Loop through all items, until you find the right one, then replace it's value.
		]]
		for i=1, #assignItems do
			local item = assignItems[i]
			if item and item["item"] == value then
				item["item"] = newValue
				outputChatBox("set!")
				break
			end
		end
	end
end, false) -- not caseSensitive

 

 

 

 

Edited by IIYAMA
Link to comment
22 hours ago, IIYAMA said:

That is still an alien explanation.

But let me give you 2 concepts


addCommandHandler("changeItem", 
function (cmd, index, value)
	index = tonumber(index)
	if index and value then
		assignItems[index]["item"] = value
		outputChatBox("set!")
	end
end, false) -- not caseSensitive


addCommandHandler("changeItemIfValue", 
function (cmd, value, newValue)
	if value and newValue then
		--[[
			Loop through all items, until you find the right one, then replace it's value.
		]]
		for i=1, #assignItems do
			local item = assignItems[i]
			if item and item["item"] == value then
				item["item"] = newValue
				outputChatBox("set!")
				break
			end
		end
	end
end, false) -- not caseSensitive

 

 

 

 

There aren't way to make list for changing item? Without command And I need count from 1 to 5 inside it bcs if item in img2 or any one so it work fine

Edited by Gripex
Link to comment
  • Moderators
14 minutes ago, Gripex said:

There aren't way to make list for changing item? Without command

You will need to decide what the input must be. If it is scrolling, clicking (on a specific something), typing, commands, that doesn't matter as long as that input can be translated to the instructions you want to give to your code.

 

I picked commands, because you only created an input (clicking) for removing items:

function Remove()
	if assignShow == false then return false end
	for i = 1,5 do
		if isMouseInRectPosition(assignSlots[i][1], assignSlots[i][2], assignSlots[i][3], assignSlots[i][4]) then
			if assigns[i] then
				triggerServerEvent("remove", resourceRoot, assigns[i]["key"], assigns[i]["item"])
				iprint(assigns[i]["key"], assigns[i]["item"])
--[[
  ...      
]]

 

But not to replace them with another one, as you instructed here:

On 08/07/2020 at 19:57, Gripex said:

Thats cleaned COde, i want if get assignItems[1]["item"] like assignItems[1]["item"] == "Test" then change Test to Any name i want it  like assignItems[1]["item"] == "Test1"

 

Link to comment
19 hours ago, IIYAMA said:

You will need to decide what the input must be. If it is scrolling, clicking (on a specific something), typing, commands, that doesn't matter as long as that input can be translated to the instructions you want to give to your code.

 

I picked commands, because you only created an input (clicking) for removing items:


function Remove()
	if assignShow == false then return false end
	for i = 1,5 do
		if isMouseInRectPosition(assignSlots[i][1], assignSlots[i][2], assignSlots[i][3], assignSlots[i][4]) then
			if assigns[i] then
				triggerServerEvent("remove", resourceRoot, assigns[i]["key"], assigns[i]["item"])
				iprint(assigns[i]["key"], assigns[i]["item"])
--[[
  ...      
]]

 

But not to replace them with another one, as you instructed here:

 

i mean there are Much Items to make it export img with other name and if i restarted scripts then names what i typed it it will remove! u got me ?

it's exports item names from ServerSide but i want it export other name of image

if assigns[i]["item"] == "Buster" then assigns[i]["item"] = "pizza" end

if assigns[i]["item"] == "Other" then assigns[i]["item"] = "pizza" end

if assigns[i]["item"] == "Test2" then assigns[i]["item"] = "burger" end

u got me ?

Link to comment
  • Moderators
2 hours ago, Gripex said:

i mean there are Much Items to make it export img with other name and if i restarted scripts then names what i typed it it will remove! u got me ?

yes I understand that if you do not save your data inside of a database, it will be gone after restarting the resource.

 

2 hours ago, Gripex said:

it's exports item names from ServerSide but i want it export other name of image

I lost you here.

You want to replace names? Which you already have saved in the database? And then return that result back to clientside and update the list there as well?

 

Link to comment
7 hours ago, IIYAMA said:

yes I understand that if you do not save your data inside of a database, it will be gone after restarting the resource.

 

I lost you here.

You want to replace names? Which you already have saved in the database? And then return that result back to clientside and update the list there as well?

 

Yes, Server Side had items name and saved on DB  its return to client side but i want when it return of get item name of server side just make photo of it as i want, u understand me? I mean if return Test so if get item called Test it return to image called "Name"

But i want data to save it

Link to comment
  • Moderators
8 hours ago, Gripex said:

But i want data to save it

Did you already add a database identifier to all your items?

Because without there is a change that will be desync.

 

 

About making a photo.

Serverside:

You can take the screenshot with:

https://wiki.multitheftauto.com/wiki/TakePlayerScreenShot

and receive it on:

https://wiki.multitheftauto.com/wiki/OnPlayerScreenShot

 

Or clientside:

You can capture the screen with:

https://wiki.multitheftauto.com/wiki/DxCreateScreenSource

 

Get the pixels of it:

https://wiki.multitheftauto.com/wiki/DxGetTexturePixels

 

Convert the pixels to a (compressed) format:

https://wiki.multitheftauto.com/wiki/DxConvertPixels

 

 

 

 

 

 

 

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