Jump to content

How to add export?


Recommended Posts

Hello, I would like to export custom chat instead of outputchatbox

c.lua ( Chat )
https://www19.zippyshare.com/v/0uuzYmdN/file.html

replace chatoutput
 

addEvent("RozpocznijSAPD",true)
addEventHandler("RozpocznijSAPD",root,function(el)
    if isPlayerInPoliceFaction(el) then
         if not getElementData(el,'player:faction') then
			exports['psrpg-frakcja-ustawienia']:rozpocznijnaliczanie(el)
			setElementData(el,'player:faction','SAPD')
			local rank = exports['psrpg-frakcja-ustawienia']:getPlayerFactionRank(el,'SAPD')
			setElementData(el,"player:rank",rank)
			setPedStat(el,78,1000)
			setPedStat(el,70,1000)
			setElementData(el,"last:nick",getPlayerName(el))
			setElementData(el,"last:color",tostring(getPlayerNametagColor(el)))
			setPlayerName(el,"#0000FF"..getPlayerName(el):gsub("#%x%x%x%x%x%x",""))
			outputChatBox ("✔ #FFFFFFRozpocząłeś/aś służbe we frakcji: #00c005SAPD #FFFFFF(#00c005San Andreas Police Department#FFFFFF)",el, 0, 255, 0, true)
			local desc = "[Służba] Gracz: "..getPlayerName(el):gsub("#%x%x%x%x%x%x","").." rozpoczął służbe we frakcji: SAPD"
			triggerEvent("admin:addText", resourceRoot, RGBToHex(0,87,110)..desc..RGBToHex(255,255,255),math.random(0,99))
			triggerEvent("admin:logs", root, desc)
			outputServerLog(desc)
			exports["pystories-db"]:dbSet("UPDATE pystories_factions set actived=NOW() WHERE code=? AND sid=? LIMIT 1;", "SAPD", getElementData(el,"player:sid"))
			else
			exports["pystories-db"]:dbSet("insert into Logi_minuty_frakcja (uid,minuty,data) VALUES(?,?,NOW())", getElementData(el,"player:sid"), getElementData(el,"player:workinjob"))
			removeElementData(el,"player:workinjob69")
			takeAllWeapons(el)
			exports['psrpg-frakcja-ustawienia']:zatrzymajnaliczanie(el)
			setElementData(el, 'player:faction', false)
			setElementData(el,"player:rank",false)
			local skin=getElementData(el,"player:skin")
			setElementModel(el, skin)
			setPlayerName(el,getElementData(el,"last:nick"))
			outputChatBox ("✘ #FFFFFFZakończyłeś/aś służbe we frakcji: #00c005SAPD #FFFFFF(#00c005San Andreas Police Department#FFFFFF)",el, 255, 0, 0, true)
			local desc = "[Służba] Gracz: "..getPlayerName(el):gsub("#%x%x%x%x%x%x","").." zakończył służbe we frakcji: SAPD"
			triggerEvent("admin:addText", resourceRoot, RGBToHex(0,87,110)..desc..RGBToHex(255,255,255),math.random(0,99))
			triggerEvent("admin:logs", root, desc)
			outputServerLog(desc)
	end
else
			outputChatBox ("✘ #FFFFFFNie jesteś zatrudniony/a we frakcji: #bf0101SAPD #FFFFFF(#bf0101San Andreas Police Department#FFFFFF)",el, 255, 0, 0, true)
	end
end)



In short, my point is to swap all outputs PutChatBox To message about custom chat.

How to export cutom chat message?

@The_GTA

Link to comment
1 hour ago, NieZnanyUserOk said:

Did you know that zippyshare.com blocks connections from Germany? The website shows 403 Forbidden to me. I was able to download your script over a Tor node.

About your question, you can use the onPlayerChat event in combination with the cancelEvent function to block the regular chat messages inside of MTA. Then you can use outputChatBox to instead put your own messages, effectively replacing the regular ones. Give it a try!

Inside of your uploaded script I see that you are trying to implement a custom DX chatbox. Please note that trying this is not recommended because some MTA builtin MTA commands will be unavailable due to security issues. If you do not mind this fact then you should try hiding the regular MTA chat using the showChat function. Then you can use the onPlayerChat event to retrieve the messages that would be displayed in the regular MTA chat and instead pipe them to your own custom DX chatbox. Good luck!

Helpful leads:

Edited by The_GTA
Link to comment

I've already tried mta wiki but it failed. Would you help?

 

local screenW, screenH = guiGetScreenSize()
local resW, resH = 1360,768
local x, y = (screenW/resW), (screenH/resH)
showChat(false)

function vazernImage(posX, posY, width, height, image, rotation, rotationX, rotationY, color, postGUI)
    dxDrawImage(x*posX, y*posY, x*width, y*height, image, rotation, rotationX, rotationY, color, postGUI)
end

function vazernText(text, posX, posY, width, height, color, scale, font, alignX, alignY, clip, wordBreak, postGUI, colorCoded, subPixelPositioning)
    dxDrawText(text, x*posX, y*posY, x*width, y*height, color, x*scale, font, alignX, alignY, clip, wordBreak, postGUI, colorCoded, subPixelPositioning)
end

chatEdit = {}
chatEdit.dxEdit = false

local chatBox = createElement("dxEditBox")

AllKeys = { "mouse1", "mouse2", "mouse3", "mouse4", "mouse5", "mouse_wheel_up", "mouse_wheel_down", "arrow_l", "arrow_u",
 "arrow_r", "arrow_d", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
 "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "num_0", "num_1", "num_2", "num_3", "num_4", "num_5",
 "num_6", "num_7", "num_8", "num_9", "num_mul", "num_add", "num_sep", "num_sub", "num_div", "num_dec", "num_enter", "F1", "F2", "F3", "F4", "F5",
 "F6", "F7", "F8", "F9", "F10", "F11", "F12", "escape", "backspace", "tab", "lalt", "ralt", "space", "pgup", "pgdn", "end", "home",
 "insert", "delete", "lshift", "rshift", "lctrl", "rctrl", "[", "]", "pause", "capslock", "scroll", ";", ",", "-", ".", "/", "#", "\\", "=" }

addEventHandler("onClientKey", root, 
    function(button, press)
        for index, keys in pairs(AllKeys) do
            if getElementData(chatBox,"state") == true then
                if button == keys then
                    cancelEvent()
                end
            end
        end
    end
)

setTimer(function()
    if isChatVisible() then
        showChat(false)
    end
end, 500, 0)
local teclaText = ""
function renderEdit()
    dxDrawEditBox("Uzywasz teraz chatu "..teclaText, x*4, y*220, x*504, y*25, false, 49, chatBox)
end

function onStart()
    showCursor(false)
    showChat(false)
    chatEdit.dxEdit = false
    setElementData(chatBox, "state", false)    
end
addEventHandler("onClientResourceStart", resourceRoot, onStart)
local tecla = nil
function renderDx(key, state)
    if state ~= "down" then return end
    if chatEdit.dxEdit == false then
        if key == "u" then teclaText = "Globalnego" end
        if key == "n" then teclaText = "Jako nie znajomy" end
        if key == "t" then teclaText = "Lokalnego" end
        chatEdit.dxEdit = true
        addEventHandler("onClientRender", root, renderEdit)
        setElementData(chatBox, "text", false)
        setElementData(chatBox, "state", true)
        showCursor(true)
        tecla = key
    end
end
bindKey("u", "down", renderDx) -- Global
bindKey("n", "down", renderDx) -- Nieznany
bindKey("t", "down", renderDx) -- Local

function sendMessage()
    if chatEdit.dxEdit == true then
            chatEdit.dxEdit = false
            if getElementData(chatBox, "text") == "" then
            else
                if string.find(getElementData(chatBox, "text"), "@") then
                    addMessageInChatBox('#8A2BE2[ INFORMACJA ] #ffffffNie możesz aktualnie nikogo #8A2BE2Oznaczać', "16")
                else
                    if string.find(getElementData(chatBox, "text"), "z neta") or string.find(getElementData(chatBox, "text"), "staff") then
                        addMessageInChatBox("#8A2BE2[ INFORMACJA ] #ffffff"..getPlayerName(localPlayer).." #ffffffSłuchaj, jak Ci coś nie pasuje to #8A2BE2Wypierdalaj!", "16")
                    else
                        if string.find(getElementData(chatBox, "text"), "mtasa://") then
                            addMessageInChatBox("#8A2BE2[ INFORMACJA ] #ffffff"..getPlayerName(localPlayer).." #ffffffTutaj się nie zareklamujesz, idź grać w  #8A2BE2Fortnita", "16")
                        else
                            if string.find(getElementData(chatBox, "text"), "/") then
                                addMessageInChatBox("#8A2BE2[ INFORMACJA ] #ffffff"..getPlayerName(localPlayer).." #ffffffUżywanie komend jest dostępne tylko pod klawiszem #8A2BE2'F8'", "16")
                                addMessageInChatBox("#ffffffAnimacje dostepne sa pod klawiszem #8A2BE2'F7'", "16")
                        else
                            triggerServerEvent("onSendMessage", localPlayer, getElementData(chatBox, "text"), tecla)
		            end
                        end
                    end
                end
            end
            setElementData(chatBox, "text", false)
            setElementData(chatBox, "state", false)
            removeEventHandler("onClientRender", root, renderEdit)
            showCursor(false)
            tecla = nil
    end
end
bindKey("enter", "down", sendMessage)


local sx,sy = guiGetScreenSize()
local px,py = 1360,768
local x2,y2 = (sx/px), (sy/py)
local dxfont2_font = dxCreateFont("font/fonte.ttf", x2*10, false, "cleartype_natural")

messages = {}

function renderMensages()       
    tickJ = getTickCount()
    
    if #messages > 7 then
        table.remove(messages, 1)
    end 
    
    for i, v in ipairs(messages) do
        
        local xx = dxGetTextWidth(v[1], 1, dxfont2_font, true)
        _dxDrawRectangle( x2*35, y2*2 + (i*y2*27), xx + 13, y2*25, 20, tocolor(0, 0, 0, 90), false )  
        dxDrawText(v[1], x2*42, y2*6 + (i*y2*27), (x2*42)+(xx + 13), (y2*6 + (i*y2*27))+(y2*17), tocolor(255, 255, 255, 255), 1, dxfont2_font, "left", "center", false, false, false, true, false)      
        if tickJ >= v[2] then
            messages[i][3] = v[3]-2
            if v[3] <= 25 then
                table.remove(messages,i)
            end
        end
    end
end
addEventHandler("onClientRender", root, renderMensages) 

function _dxDrawRectangle( posX, posY, width, height, radius, color, postGUI )  
    local posX, posY, width, height = round( posX ), round( posY ), round( width ), round( height )
    local radius = radius and math.min( radius, math.min( width, height ) / 2 )  or 12
    
    dxDrawRectangle( posX, posY + radius, width, height - radius * 2, color, postGUI )
    dxDrawRectangle( posX + radius, posY, width - 2 * radius, radius, color, postGUI )
    dxDrawRectangle( posX + radius, posY + height - radius, width - 2 * radius, radius, color, postGUI )
    
    dxDrawCorner( posX + radius, posY + radius, radius, color, 1, postGUI )
    dxDrawCorner( posX + radius, posY + height - radius, radius, color, 2, postGUI )
    dxDrawCorner( posX + width - radius, posY + radius, radius, color, 3, postGUI )
    dxDrawCorner( posX + width - radius, posY + height - radius, radius, color, 4, postGUI )
end

function round(num) 
    if ( num >= 0 ) then return math.floor( num + .5 ) 
    else return math.ceil( num - .5 ) end
end

function dxDrawCorner( x, y, r, color, corner, postGUI )
    local corner = corner or 1
    local start = corner % 2 == 0 and 0 or -r
    local stop = corner % 2 == 0 and r or 0
    local m = corner > 2 and -1 or 1
    local h = ( corner == 1 or corner == 3 ) and -1 or 1
    for yoff = start, stop do
        local xoff = math.sqrt( r * r - yoff * yoff ) * m
        dxDrawRectangle( x - xoff, y + yoff, xoff, h, color, postGUI )
    end 
end

function addMessageInChatBox(message, avatar)
    tickJ = getTickCount()
    table.insert(messages, {message, tickJ+99999999, 90, avatar})
end
addEvent("addMessageInChatBox", true)
addEventHandler("addMessageInChatBox", resourceRoot, addMessageInChatBox)

function removeAllMessage()
    messages = {}
    tickJ = getTickCount()
    table.insert(messages, {"#fca903* #ffffffChat został wyczyszczony przez #ff0000Administratora #fca903*", tickJ+99999999, 90, "i"})
end
addEvent("removeAllMessage", true)
addEventHandler("removeAllMessage", resourceRoot, removeAllMessage)

function isCursorOnElement( posX, posY, width, height )
  if isCursorShowing( ) then
    local mouseX, mouseY = getCursorPosition( )
    local clientW, clientH = guiGetScreenSize( )
    local mouseX, mouseY = mouseX * clientW, mouseY * clientH
    if ( mouseX > posX and mouseX < ( posX + width ) and mouseY > posY and mouseY < ( posY + height ) ) then
      return true
    end
  end
  return false
end







































C.lua ( CHat )

Link to comment
1 minute ago, NieZnanyUserOk said:

I've already tried mta wiki but it failed. Would you help?

 

What do you mean "it failed"? It has never failed for me. Please elaborate what you have tried, based on my recommendations, and we can proceed into something else if necessary.

Link to comment
13 minutes ago, NieZnanyUserOk said:

Can you just write me one line of frog export to custom chat, a message appeared? Please

meta.xml

<export function="frog" type="client" />
<script src="client.lua" type="client" />

client.lua (frogmaker resource)

function frog(msg)
    outputChatBox(msg)
end

client.lua (froguser resource)

addEventHandler("onClientResourceStart", resourceRoot, function()
        exports.frogmaker:frog("test");
    end
);

frogmaker has to be running for froguser to work.

Replace outputChatBox with your own custom chat function (in your script you have the addMessageInChatBox function so use it instead).

Edited by The_GTA
Link to comment

If resource start console error

ERROR: Loading script failed: [ Main ]/[ Factions ]/[ LSPD ]/VCSMTA_LSPD-Frakcja/s_duty.lua:64: '=' expected near '-'

addEvent("RozpocznijSAPD",true)
addEventHandler("RozpocznijSAPD",root,function(el)
    if isPlayerInPoliceFaction(el) then
         if not getElementData(el,'player:faction') then
			exports['psrpg-frakcja-ustawienia']:rozpocznijnaliczanie(el)
			setElementData(el,'player:faction','SAPD')
			local rank = exports['psrpg-frakcja-ustawienia']:getPlayerFactionRank(el,'SAPD')
			setElementData(el,"player:rank",rank)
			setPedStat(el,78,1000)
			setPedStat(el,70,1000)
			setElementData(el,"last:nick",getPlayerName(el))
			setElementData(el,"last:color",tostring(getPlayerNametagColor(el)))
			setPlayerName(el,"#0000FF"..getPlayerName(el):gsub("#%x%x%x%x%x%x",""))
			outputChatBox ("✔ #FFFFFFRozpocząłeś/aś służbe we frakcji: #00c005SAPD #FFFFFF(#00c005San Andreas Police Department#FFFFFF)",el, 0, 255, 0, true)
			local desc = "[Służba] Gracz: "..getPlayerName(el):gsub("#%x%x%x%x%x%x","").." rozpoczął służbe we frakcji: SAPD"
			triggerEvent("admin:addText", resourceRoot, RGBToHex(0,87,110)..desc..RGBToHex(255,255,255),math.random(0,99))
			triggerEvent("admin:logs", root, desc)
			outputServerLog(desc)
			exports["pystories-db"]:dbSet("UPDATE pystories_factions set actived=NOW() WHERE code=? AND sid=? LIMIT 1;", "SAPD", getElementData(el,"player:sid"))
			else
			exports["pystories-db"]:dbSet("insert into Logi_minuty_frakcja (uid,minuty,data) VALUES(?,?,NOW())", getElementData(el,"player:sid"), getElementData(el,"player:workinjob"))
			removeElementData(el,"player:workinjob69")
			takeAllWeapons(el)
			exports['psrpg-frakcja-ustawienia']:zatrzymajnaliczanie(el)
			setElementData(el, 'player:faction', false)
			setElementData(el,"player:rank",false)
			local skin=getElementData(el,"player:skin")
			setElementModel(el, skin)
			setPlayerName(el,getElementData(el,"last:nick"))
			outputChatBox ("✘ #FFFFFFZakończyłeś/aś służbe we frakcji: #00c005SAPD #FFFFFF(#00c005San Andreas Police Department#FFFFFF)",el, 255, 0, 0, true)
			local desc = "[Służba] Gracz: "..getPlayerName(el):gsub("#%x%x%x%x%x%x","").." zakończył służbe we frakcji: SAPD"
			triggerEvent("admin:addText", resourceRoot, RGBToHex(0,87,110)..desc..RGBToHex(255,255,255),math.random(0,99))
			triggerEvent("admin:logs", root, desc)
			outputServerLog(desc)
	end
else
			outputChatBox ("✘ #FFFFFFNie jesteś zatrudniony/a we frakcji: #bf0101SAPD #FFFFFF(#bf0101San Andreas Police Department#FFFFFF)",el, 255, 0, 0, true)
			exports.VCSMTA-Chat.sendMessage("Work"); -- Export here
	end
end)

 

Link to comment
2 minutes ago, NieZnanyUserOk said:

ERROR: Loading script failed: [ Main ]/[ Factions ]/[ LSPD ]/VCSMTA_LSPD-Frakcja/s_duty.lua:64: '=' expected near '-'

  • you are mixing up clientside and serverside (it looks like it because of the "s_" tag of your Lua file)
  • I don't even know what content that file has
  • Are you sure you know what you are doing? I am trying to help you incrementally here. You should try performing smaller steps and ask before you do something.
Edited by The_GTA
Link to comment
20 minutes ago, NieZnanyUserOk said:

VCSMTA-Chat - Chat Script name

Read up on the MTA event system and related functions. You seem to lack crucial understanding of it. Contact the resource authors for details about the named script you mentioned.

I am not supporting this topic any further. I invite somebody else to address the inquiries from the user.

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