Jump to content

Problem server side output


goofie88

Recommended Posts

Hello, i have problem with script, it should output message above screen but it does not when script is server side only when client side it outputs

resX, resY = guiGetScreenSize() 
local x,y,w,h = resX/4+(resX/16),0,resX/2-(resX/16),0 
container = {x,y,w,h} 
  
local messages = {} 
local locmessages = {} 
  
  
local fontIndex = 4 
local fonts = { 
    {15,"default",1}, 
    {15,dxCreateFont ( "helvetica.ttf",9 ,true ),1}, 
    {16,"bankgothic",0.5}, 
    {15,"default-bold",1} 
} 
  
function drawContainer() 
    dxDrawRectangle(container[1],container[2],container[3],container[4],tocolor(0,0,0,210)) 
    if messages[1] then 
        local y = messages[1][5] 
        local removeMessage  
        if messages[1][3] then 
            y = y - 1 
            messages[1][5] = y 
            container[4] = container[4] - 1 
            if messages[1][5] == (-1 * messages[1][7]) then 
                removeMessage = true  
                if #messages == 1 then 
                    killTimer(MESSAGETIMER) 
                    MESSAGETIMER = false 
                end 
            end 
        end 
  
        local x = container[1] 
        local w = container[1] + container[3] 
        for k, message in ipairs(messages) do 
  
            local h = message[7] 
            local msg = message[1] 
            if message[8] then 
                local messageTable = message[8] 
  
                msg = msg:format(message[8][1](message[8][2])) 
            end 
             
            dxDrawText(msg:gsub("#%x%x%x%x%x%x", ""),container[1] + 12,y,w - (12*2),y + h,message[2],fonts[fontIndex][3],fonts[fontIndex][2],"center","top",true,true,false, false, true) 
            y = y + h 
        end 
        if removeMessage then 
            table.remove(messages,1) 
            removeMessage = false 
        end 
    end 
end 
function moveMessage (i) 
    messages[i][3] = true 
end 
function addMessage(text,r,g,b,formattable) 
    if not MESSAGETIMER then 
        MESSAGETIMER = setTimer(messageTimer,1000,0) 
    end 
    if #messages > 5 then 
        local i = 1 
        while messages[i + 1][3] do 
            i = i + 1 
        end 
        if messages[i] then 
            messages[i][3] = true 
        end 
    end 
    local h = fonts[fontIndex][1]--15 
    local msg = text 
    if formattable then 
        local messageTable = {} 
        for k, func in ipairs(formattable) do 
            table.insert(messageTable,func()) 
        end 
        msg = text:format(unpack(messageTable)) 
    end 
    local textWidth = dxGetTextWidth(msg,fonts[fontIndex][3],fonts[fontIndex][2]) 
    if textWidth > container[3] then 
        h = 2 * h --15 
    end 
    container[4] = container[4] + h 
    local color = tocolor(r, g, b, 255) 
    table.insert(messages,{text,color,false,0,0,10,h,formattable}) 
    return messages[#messages] 
end 
function onClientResourceStart() 
    resX,resY = guiGetScreenSize()  
    if resX > 1280 then 
        fontIndex = 2 
    end 
    local x,y,w,h = resX/4+(resX/16),0,resX/2-(resX/16),0 
    container = {x,y,w,h} 
    addEventHandler("onClientPreRender",getRootElement(),drawContainer) 
end  
function messageTimer() 
    for k,message in ipairs(messages) do 
        message[6] = message[6] - 1 
        if message[6] <= 0 then  
            moveMessage(1)  
        end 
    end  
end 
addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),onClientResourceStart) 
  
addEvent("DxMsgS",true) 
function DxMsgS(message,r,g,b) 
    addMessage(message, r,g,b) 
end 
addEventHandler("DxMsgS",getLocalPlayer(),DxMsgS) 
  
function DxMsgClient(msg,r,g,b,static,silent) 
    DxMsgS(msg,r,g,b) 
end 
  

Here is error code

ERROR: call: failed to call 'topchatbox:DxMsgClient [string "?"] 

Ill be happy for help

Link to comment
It has completely nothing to do with being DirectX functions.

What You Mean ? Didn,t get it -_-" :| ?

It's not for being DirectX functions that you can't call a client side function in server. Client side functions are created in the MTA client, server functions are in the server. They're not in the same Lua state so you can't call each others that way.

@goofie88, if I understood you right, yes, create a function in the server side that triggers the client side event which then calls the function "DxMsgClient" or whatever the function name is. Then export the server side function.

Edited by Guest
Link to comment
It has completely nothing to do with being DirectX functions.

What You Mean ? Didn,t get it -_-" :| ?

It's not for being DirectX functions that you can't call a client side function in server. Client side functions are created in the MTA client, server functions are in the server. They're not in the same Lua state so you can't call each others that way.

Do you mean that you can not use it on the server side?

Link to comment
Of course you can't use them in server side.

Yes that's what I thought, thank you anyway Anderl Sorry to bother you but i mean this topic he can use export function on server side? if he is trigger it if am right ? .

Yes, as he and I said.

@goofie88, if I understood you right, yes, create a function in the server side that triggers the client side event which then calls the function "DxMsgClient" or whatever the function name is. Then export the server side function.
Link to comment
Of course you can't use them in server side.

Yes that's what I thought, thank you anyway Anderl Sorry to bother you but i mean this topic he can use export function on server side? if he is trigger it if am right ? .

Yes, as he and I said.

@goofie88, if I understood you right, yes, create a function in the server side that triggers the client side event which then calls the function "DxMsgClient" or whatever the function name is. Then export the server side function.

Oh,Didn,t See That Just Now I Saw it , Thanks .

Link to comment

hey guys its me again this might look weird from me asking such beginner questions but for me its look more than beginner lol

here's how I exported to make it trigger on server side

function DxMsgSr(msg,r,g,b,static,silent) 
    triggerClientEvent ( "DxMsgClient", getRootElement(), msg,r,g,b) 
end 
addEvent("DxMsgSr",true) 
addEventHandler("DxMsgSr",getRootElement(),DxMsgSr) 
  

Here's the export, the problem is that everyone is seeing it, how's that possible I mean the first argument Ive putted on script is player, so only the player who did that should see it. Im confused with all those inversing stuff :S

exports["'topchatbox"]:DxMsgSr("You're not allowed to do that",player,255,255,255)

Link to comment

I'll show you an example of how the server and client code should be:

Server:

function DxMsgSr ( message, player, ... ) 
    if ( triggerClientEvent ( player, "DxMsgClient", player, message, arg ) ) then 
        return true 
    end 
    return false 
end 

Client:

addEvent ( "DxMsgClient", true ); 
  
addEventHandler ( "DxMsgClient", root, 
    function ( message, color ) 
        --color[1] = R; 
        --color[2] = G; 
        --color[3] = B; 
         
        --the above written is to help you to know how to find the RGB color given by the scripter, that means index '1' in 'color' array is the R color and so on 
        --here draw your text with the help above ^ 
         
        --the text will ONLY be drawn to the player you passed to "DxMsgSr" in server 
    end 
) 

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