Jump to content

outputMessage (Output Custom Function)


Zuher Laith

Recommended Posts

Greetings Everyone ..

I Was looking for a Brand new outputMessage to Show The Error Message

So The Content is When i Call "outputMessage", It Popup an Message With What i typed.

To make the Idea Clear, Here is an Code-Ex:

outputMessage("# Test Message", 255, 0, 255); 

I Found this in Business Mod At Community (https://community.multitheftauto.com/index.php?p=resources&s=details&id=2847)

So this Mod has The OutputMessage Functions ..

Here is a Code Look on his Functions:

dxoutput.client File:

local screen_width, screen_height = GuiElement.getScreenSize(); 
local relative_width, relative_height = screen_width / 1440, screen_height / 900 
  
local static_left = relative_width * 983; 
local cur_left = static_left; 
local move_offet = relative_width * 20; 
local cur_message = ""; 
local cur_color = {255, 255, 255}; 
local message_moving = false; 
local message_moving_back = false; 
local message_moving_back_timer; 
  
addEventHandler("onClientRender", root, function() 
    dxDrawFramedText(cur_message, cur_left, relative_height * 618.0, cur_left + (relative_width * 456), relative_height * 645.0, tocolor(cur_color[1], cur_color[2], cur_color[3], 255), 1.0, "default-bold", "center", "center", false, true, true); 
end); 
  
function dxOutputMessage(message, r, g, b) 
    if (message_moving) then removeEventHandler("onClientRender", root, moveMessage); end 
    if (message_moving_back) then removeEventHandler("onClientRender", root, moveMessageBack); end 
    if (message_moving_back_timer and message_moving_back_timer:isValid()) then message_moving_back_timer:destroy(); end 
    cur_left, cur_message, cur_color = relative_width * 1440, message or "", {r or 255, g or 255, b or 255}; 
    message_moving_back_timer = Timer(hideMessage, 5000, 1); 
    addEventHandler("onClientRender", root, moveMessage); 
    message_moving = true; 
end 
  
function moveMessage() 
    cur_left = cur_left - move_offet; 
    if (cur_left <= static_left) then 
        removeEventHandler("onClientRender", root, moveMessage); 
        cur_left = relative_width * 983; 
        message_moving = false; 
    end 
end 
  
function hideMessage() 
    message_moving_back = true; 
    addEventHandler("onClientRender", root, moveMessageBack); 
end 
  
function moveMessageBack() 
    cur_left = cur_left + move_offet; 
    if (cur_left >= relative_width * 1440) then 
        removeEventHandler("onClientRender", root, moveMessageBack); 
        cur_left = relative_width * 1440; 
        message_moving_back = false; 
    end 
end 
     
function dxDrawFramedText(message, left, top, width, height, color, scale, font, alignX, alignY, clip, wordBreak, postGUI) 
    dxDrawText(message, left + 1, top + 1, width + 1, height + 1, tocolor(0, 0, 0, 255), scale, font, alignX, alignY, clip, wordBreak, postGUI); 
    dxDrawText(message, left + 1, top - 1, width + 1, height - 1, tocolor(0, 0, 0, 255), scale, font, alignX, alignY, clip, wordBreak, postGUI); 
    dxDrawText(message, left - 1, top + 1, width - 1, height + 1, tocolor(0, 0, 0, 255), scale, font, alignX, alignY, clip, wordBreak, postGUI); 
    dxDrawText(message, left - 1, top - 1, width - 1, height - 1, tocolor(0, 0, 0, 255), scale, font, alignX, alignY, clip, wordBreak, postGUI); 
    dxDrawText(message, left, top, width, height, color, scale, font, alignX, alignY, clip, wordBreak, postGUI); 
end 
  
addEvent("business.dxOutputMessage", true) 
addEventHandler("business.dxOutputMessage", root, function(message, r, g, b) 
    dxOutputMessage(message, r, g, b); 
end); 

Client File Function:

function outputMessage(message, r, g, b) 
    triggerServerEvent("business.outputMessage", localPlayer, message, r, g, b); 
end 

Server File Function:

function Player:outputMessage(message, r, g, b) 
    if (settings.info_messages_type == "dx") then 
        dxOutputMessage(message, self, r, g, b); 
    else 
        self:outputChat(message, r, g, b, true); 
    end 
end 
  
function outputMessage(message, player, r, g, b) 
    if (settings.info_messages_type == "dx") then 
        dxOutputMessage(message, player, r, g, b); 
    else 
        player:outputChat(message, r, g, b, true); 
    end 
end 
  
function dxOutputMessage(message, player, r, g, b) 
    triggerClientEvent(player, "business.dxOutputMessage", player, message, r, g, b); 
end 
  
addEvent("business.outputMessage", true); 
addEventHandler("business.outputMessage", root, function(message, r, g, b) 
    source:outputMessage(message, r, g, b); 
end); 

META File:

    

So this is "His" Functions that he used to Ouput Message

WHAT I WANT IS

Install This Output Functions to Other Mods ..

Can i Do that?

OR

Can i Make a Custom mod for this Func?, So I Can Just Call "outputMessage" On every Mod i have ?

Waiting for Reply.

Link to comment

You can always write your own function. All you need is a table for the text that has been sent already ( the messages ), you might even add some time in there if you like. Colors, what so ever.

After the table has been filled, loop over the entries and show them. Make them fade, make them fancy. Whatever floats your boat. To do so, you should be able to write it with the following functions/events (might miss some );

triggerServerEvent 
triggerClientEvent 
dxDrawText -- for the text, obviously 
dxDrawImage -- can be used if you want images in there 
dxDrawRectangle -- if you want a background behind the text 
getLocalPlayer -- always check if the requested player is the localPlayer to avoid others from getting his messages 
table.insert -- to save the table 
onClientRender -- to show your messages 
setTimer -- to hide them later on, if you want to do this 
exports -- to call the function from another resource 

Link to comment

@tosfera

Thanks for The Idea's ..

but i guess this Will Request from me some Experience .. and Time and support for the problems i have with it.

So I will just use the Function he made, it shorts every thing for me.

but till now i didn't get the Answer for my first Question ..

Install This Output Functions to Other Mods
Link to comment

If you want to do that, you just install the resource and execute the function. You can do this by using triggerServerEvent, triggerEvent or directly with triggerClientEvent. All this needs is the event which is "business.outputMessage", the player, the message and the rgb. That's basically it.

Make dxOutputMessage an export function and you can call it from other resources.
call 

Why would you export it if you can also just call the added event, quite double dutch there. :lol:

Link to comment

@tosfera

So I Will Export the Functions to The Original Mod Meta ..

        function="outputMessage" type="client"/> 
        function="outputMessage" type="server"/> 
        function="dxOutputMessage" type="server"/> 
        function="Player:outputMessage" type="server"/> 

Right ? ..

Now i Will go to the Mod that i want to call the function on ..

call(getResourceFromName("business"), "outputMessage", "Message", "r", "g", "b") 

I think what i'am talking about make's sense right ? ..

Sorry for Bad Exp, I'am new around here.

Link to comment
  • Moderators

fill in >"r", 'g', 'b'< in with a value between 0 and 255.

255, 0, 0 = red color

0, 255, 0 = green color

0, 0, 255 = blue color

Or mix the color channels until you have the color you want.

And you are ready to go.

Link to comment

Hold On ..

I've got an Error While Output in Server Side:

[17:30:24] ERROR: Shop\Server.lua:37: call: failed to call 'business:Player:outputMessage' 

I Used "Player.outputMessage" ..

call(getResourceFromName("business"), "Player:outputMessage", "Message", 255, 0, 255) 

Because in "Business Mod" In Server Side, He Used "player:outputMessage"

I Don't Understand the Problem ..

Link to comment

Alright, So i tried the Same One , on Client & Server "outputMessage"

This is what is Give's in the Console:

[18:25:53] WARNING: [gamemodes]\business\scripts\core.server.lua:83: Bad argumen 
t @ 'triggerClientEvent' [Expected element at argument 2, got string 'business.d 
xOutputMessage'] 

Here's the Code of Line 83:

function dxOutputMessage(message, player, r, g, b) 
    triggerClientEvent(player, "business.dxOutputMessage", player, message, r, g, b); 
end 

This is Strange ..

Because it Works On Client Side, but do not works on Server Side !

Help Please ..

Link to comment

You didn't specify the player element for the server side call, thus it skipped the sendTo argument (since it is optional, it is evaluated only if it is a userdata, otherwise it assumes the argument doesn't exist and considers argument 1 as argument 2, 2 as 3, 3 as 4 and so on), leaving the slightly confusing message that it got a string instead of a player element.

-- To illustrate, this is being called: 
triggerClientEvent(nil, "business.dxOutputMessage", nil, "message", 255, 255, 255) 
-- which is the same as 
triggerClientEvent("business.dxOutputMessage", nil, "message", 255, 255, 255) 
-- but the arguments are misplaced. If the first argument was a player element, instead of a nil, the former example would work, otherwise it must be structured like the latter. 
  

Link to comment

@MrTasty

Here is The DxOutput Function In the Original "business" Server Side:

function dxOutputMessage(message, player, r, g, b) 
    triggerClientEvent(player, "business.dxOutputMessage", player, message, r, g, b); 
end 

No Mistake's in here Right ? ..

I Tried to Change "player" to "nil" as you Suggested , didn't worked !

Remember The Function Works In Client Side, but doesn't work on Server Side ..

Waiting for Reply ..

Link to comment
The problem is with the export from resource you are exporting from.

The player element you use in your export isn't valid.

I recommend you to post your own code.

Well, I Will do that ..

First: Business Mod, I guess Everyone know's it right? but i will put it any way.

core.server.lua "Business Mod File"

local _settings = get(""); 
local settings = {};
for k, v in pairs(_settings) do
    k = split(k, ".")[2];
    settings[k] = v;
end
 
if (settings.key:len() < 1 or settings.key:len() > 1) then
    settings.key = "N";
end
if (not settings.blip or tonumber(settings.blip) == nil) then
    settings.blip = false;
end
 
addEventHandler("onResourceStart", resourceRoot, function()
    if (settings.database == "mysql") then
        local host, db, username, password, port, socket = unpack(settings.database_data);
        if not (host and db and username and password) then outputDebugString("نظام الوظيفة: لا يمكن الاتصال بقاعدة البيانات - معلومات غير صالحة"); return; end
        if (tonumber(port)) then port = "port="..port..";"; else port = ""; end
        if (socket and socket ~= "") then socket = "socket="..socket..";"; else socket = ""; end
        database = Connection("mysql", "host="..host..";dbname="..db..";"..port..socket, username, password);
        if (not database) then outputDebugString("نظام الوظيفة: لا يمكن الاتصال بقاعدة البيانات"); return; end
    else
        database = Connection("sqlite", "files/business.db");
        if (not database) then outputDebugString("نظام الوظيفة: لا يمكن الاتصال بملف قاعدة البيانات"); return; end
    end
    database:exec("CREATE TABLE IF NOT EXISTS business(id INT, name TEXT, owner TEXT, cost INT, pos TEXT, payout INT, payout_time INT, payout_otime INT, payout_unit TEXT, payout_cur_time INT, bank INT)");
    database:query(dbCreateBusinessesCallback,  "SELECT * FROM business");
end);
 
function dbCreateBusinessesCallback(query_handle)
    local sql = query_handle:poll(0);
    if (sql and #sql > 0) then
        for index, row in ipairs(sql) do
            local pos = split(row["pos"], ",");
            local b_marker = Marker(pos[1], pos[2], pos[3], "cylinder", 1.5, settings.marker_color[1], settings.marker_color[2], settings.marker_color[3], settings.marker_color[4]);
            b_marker.interior = pos[4];
            b_marker.dimension = pos[5];
            if (settings.blip ~= false) then
                if (row["owner"] == "للبيع") then
                    local b_blip = Blip.createAttachedTo(b_marker, settings.blip, 2, 255, 0, 0, 255, 0, 100.0);
                    b_blip.interior = pos[4];
                    b_blip.dimension = pos[5];
                else
                    local b_blip = Blip.createAttachedTo(b_marker, settings.blip, 2, 255, 0, 0, 255, 0, 100.0);
                    b_blip.interior = pos[4];
                    b_blip.dimension = pos[5];
                end
            end
            addEventHandler("onMarkerHit", b_marker, onBusinessMarkerHit);
            addEventHandler("onMarkerLeave", b_marker, onBusinessMarkerLeave);
            local timer = Timer(businessPayout, row["payout_cur_time"] , 1, b_marker);
            b_marker:setData("b_data", {row["id"], row["name"], row["owner"], row["cost"], row["payout"], row["payout_time"], row["payout_otime"], row["payout_unit"], row["bank"], timer});
        end
    end
end
 
addCommandHandler("business", function(player)
    if (ACL.hasObjectPermissionTo(player, "function.banPlayer")) then
        triggerClientEvent(player, "business.showCreateBusinessWindow", player);
    else
        player:outputMessage("نظام الوظيفة: ليس لديك الصلاحية للولوج لهذه الاعدادات", 255, 0, 0);
    end
end);
 
function Player:outputMessage(message, r, g, b)
    if (settings.info_messages_type == "dx") then
        dxOutputMessage(message, self, r, g, b);
    else
        self:outputChat(message, r, g, b, true);
    end
end
 
function outputMessage(message, player, r, g, b)
    if (settings.info_messages_type == "dx") then
        dxOutputMessage(message, player, r, g, b);
    else
        player:outputChat(message, r, g, b, true);
    end
end
 
function dxOutputMessage(message, player, r, g, b)
    triggerClientEvent(player, "business.dxOutputMessage", player, message, r, g, b);
end
 
addEvent("business.outputMessage", true);
addEventHandler("business.outputMessage", root, function(message, r, g, b)
    source:outputMessage(message, r, g, b);
end);
 
addEvent("business.createBusiness", true);
addEventHandler("business.createBusiness", root, function(x, y, z, interior, dimension, name, cost, payout, payout_time, payout_unit)
    database:query(dbCreateBusinessCallback,  {client, x, y, z, interior, dimension, name, cost, payout, payout_time, payout_unit}, "SELECT * FROM business");
end);
 
function dbCreateBusinessCallback(query_handle, client, x, y, z, interior, dimension, name, cost, payout, payout_time, payout_unit)
    local sql = query_handle:poll(0);
    if (sql) then
        local id;
        if (#sql > 0) then
            id = sql[#sql]["id"] + 1;
        else
            id = 1;
        end
        local unit;
        if (payout_unit == "ثواني") then
            unit = 1000;
        elseif (payout_unit == "دقائق") then
            unit = 60000;
        elseif (payout_unit == "ساعات") then
            unit = 3600000;
        elseif (payout_unit == "ايام") then
            unit = 86400000;
        end
 
        x = tonumber(x);
        y = tonumber(y);
        z = tonumber(z);
        interior = tonumber(interior);
        dimension = tonumber(dimension);
        cost = tonumber(cost);
        payout = tonumber(payout);
        payout_time = tonumber(payout_time);
 
        z = z - 1;
 
        database:exec("INSERT INTO business(id,name,owner,cost,pos,payout,payout_time,payout_otime,payout_unit,payout_cur_time,bank) VALUES(?,?,?,?,?,?,?,?,?,?,?)", id, name, "للبيع", cost, x..","..y..","..z..","..interior..","..dimension, payout, payout_time * unit, payout_time, payout_unit, payout_time * unit, 0);
 
        local b_marker = Marker(x, y, z, "cylinder", 1.5, settings.marker_color[1], settings.marker_color[2], settings.marker_color[3], settings.marker_color[4]);
        b_marker.interior = interior;
        b_marker.dimension = dimension;
        if (settings.blip ~= false) then
            local b_blip = Blip.createAttachedTo(b_marker, settings.blip, 2, 255, 0, 0, 255, 0, 100.0);
            b_blip.interior = interior;
            b_blip.dimension = dimension;
        end
        local timer = Timer(businessPayout, payout_time * unit , 1, b_marker);
        b_marker:setData("b_data", {id, name, "للبيع", cost, payout, payout_time * unit, payout_time, payout_unit, 0, timer});
        addEventHandler("onMarkerHit", b_marker, onBusinessMarkerHit);
        addEventHandler("onMarkerLeave", b_marker, onBusinessMarkerLeave);
        if (#tostring(id) == 1) then id = "0".. tostring(id) end
        client:outputMessage("بنجاح "..id.." نظام الوظيفة: لقد تم انشاء الوظيفة رقم", 0, 255, 0);
    end
end
 
function onBusinessMarkerHit(hElement, mDim)
    if (hElement:getType() ~= "player") then return; end
    if (hElement:isInVehicle()) then return; end
    if (not mDim) then return; end
    triggerClientEvent(hElement, "business.showInstructions", hElement);
end
 
function onBusinessMarkerLeave(hElement, mDim)
    if (hElement:getType() ~= "player") then return; end
    if (hElement:isInVehicle()) then return; end
    if (not mDim) then return; end
    triggerClientEvent(hElement, "business.hideInstructions", hElement);
end
 
function businessPayout(b_marker)
    local b_data = b_marker:getData("b_data");
    local id, name, owner, cost, payout, payout_time, payout_otime, payout_unit, bank, timer = unpack(b_data);
    if (owner ~= "للبيع") then
        bank = bank + payout;
        database:exec("UPDATE business SET bank = ? WHERE id = ?", bank, id);
        if (settings.inform_player_of_payout) then
            local account = Account(owner);
            if (account) then
                local player = account:getPlayer();
                if (player and player.isElement) then
                    player:outputMessage("($"..payout..") قامت بدفع \" "..name.." \" نظام الوظيفة: الوظيفة", 0, 255, 0);
                end
            end
        end
    end
    timer = Timer(businessPayout, payout_time, 1, b_marker);
    b_marker:setData("b_data", {id, name, owner, cost, payout, payout_time, payout_otime, payout_unit, bank, timer});
end
 
addEventHandler("onResourceStop", resourceRoot, function()
    for index, b_marker in ipairs(Element.getAllByType("marker", resourceRoot)) do
        local b_data = b_marker:getData("b_data");
        local id, name, owner, cost, payout, payout_time, payout_otime, payout_unit, bank, timer = unpack(b_data);
        if (timer and timer:isValid()) then
            local left = timer:getDetails();
            if (left >= 50) then
                database:exec("UPDATE business SET payout_cur_time = ? WHERE id = ?", left, id);
            else
                database:exec("UPDATE business SET payout_cur_time = ? WHERE id = ?", payout_time, id);
            end
        end
    end
end);
 
function Ped:isInMarker(marker)
    local colshape = marker.colShape;
    return self:isWithinColShape(colshape);
end
 
addEventHandler("onResourceStart", resourceRoot, function()
    for index, player in ipairs(Element.getAllByType("player")) do
        bindKey(player, settings.key, "up", onPlayerAttemptToOpenBusiness);
    end
end);
 
addEventHandler("onPlayerJoin", root,function()
    bindKey(source, settings.key, "up", onPlayerAttemptToOpenBusiness);
end);
 
function onPlayerAttemptToOpenBusiness(player)
    for index, b_marker in ipairs(Element.getAllByType("marker", resourceRoot)) do
        if (player:isInMarker(b_marker)) then
            local b_data = b_marker:getData("b_data");
            local id, name, owner, cost, payout, payout_time, payout_otime, payout_unit, bank, timer = unpack(b_data);
            triggerClientEvent(player, "business.showBusinessWindow", player, b_marker, getAccountName(getPlayerAccount(player)) == owner, ACL.hasObjectPermissionTo(player, "function.banPlayer"));
            break;
        end
    end
end
 
function Ped:getMarker()
    for index, b_marker in ipairs(Element.getAllByType("marker", resourceRoot)) do
        if (self:isInMarker(b_marker)) then
            return b_marker;
        end
    end
end
 
addEvent("business.buy", true);
addEventHandler("business.buy", root, function()
    local account = client.account;
    if (not account or account:isGuest()) then return; end
    local b_marker = client:getMarker();
    if (not isElement(b_marker)) then return; end
    local b_data = b_marker:getData("b_data");
    local id, name, owner, cost, payout, payout_time, payout_otime, payout_unit, bank, timer = unpack(b_data);
    if (owner ~= "للبيع") then
        client:outputMessage("نظام الوظيفة: هذه الوظيفة مباعة بالفعل", 255, 0, 0);
        return;
    end
    database:query(dbBuyBusinessCallback, {client, b_marker, id, name, owner, cost, payout, payout_time, payout_otime, payout_unit, bank, timer}, "SELECT * FROM business WHERE owner = ?", account.name);
end);
 
addEvent("business.sell", true);
addEventHandler("business.sell", root, function()
    local account = client.account;
    if (not account or account:isGuest()) then return; end
    local b_marker = client:getMarker();
    if (not
Link to comment
call(getResourceFromName("business"), "outputMessage", source, "the message bla bla bla...", 0, 245, 33) 

The source in this event is the player element.

Still not working my friend ..

It work's on client side, but don't work on server side

you can see in "business" mod it's different output in server/client side

This is really annoying ..

Any help please ? :(

Link to comment
1: Are there errors/warnings?

2: >if (settings.info_messages_type == "dx") then< is info_messages_type in the meta.xml set to dx?

1- The Error Is :

[12:10:31] WARNING: [gamemodes]\business\scripts\core.server.lua:83: Bad argument @ 'triggerClientEvent' [Expected element at argument 2, got string 'business.dxOutputMessage'] 

2- The Setting Set to "dx'.

Link to comment
and from where are you testing that code? Because it seems that, that code doesn't provide a valid source element.

I'am Testing it from a Normal Script, Server.lua

The Script doesn't have any thing linked with "business" mod ! So it's a normal Call !

<meta> 
<info author="NiGht" version="4.0.0" type="script" />  
  <script src="Client.lua" type="client" /> 
  <script src="Server.lua" type="server" /> 
</meta> 

If you are not understanding the problem yet, do you want to take a look in TeamViewer ?

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