Jump to content

outputMessage (Output Custom Function)


Zuher Laith

Recommended Posts

I just want to see your Server.lua File.

Here is my Mod Server File (Full) .. No edit's:

----------------------- 
-- Admin Shop 
-- Created By NiGht 
---------------------- 
  
----------------------- 
-- Get Player Groups -- 
----------------------- 
function getGroups() 
    if (isElement(source) and getElementType(source) == "player") then 
        local allGroups = aclGroupList(); 
        local groups = ""; 
        for _, v in ipairs(allGroups) do 
            if (isObjectInACLGroup("user." .. getAccountName(getPlayerAccount(source)), v)) then 
                groups = aclGroupGetName(v) .. ", " .. groups; 
            end 
        end 
        
        triggerClientEvent(source, "c_getGroups", source, groups); 
    end 
end 
addEvent("s_getGroups", true) 
addEventHandler("s_getGroups", root, getGroups) 
  
  
---------------------- 
-- Get Account Name -- 
---------------------- 
addEventHandler("onPlayerLogin",root, 
    function(_,account) 
        triggerClientEvent(source,"getAccName",source,getAccountName(account)) 
    end 
) 
  
------------------- 
-- Main Function -- 
------------------- 
xAddToGroupFunction_ = function ( Group,Price,Name ) 
    local account = getAccountName(getPlayerAccount(source)); 
    if isGuestAccount(getPlayerAccount(source)) then return call(getResourceFromName("business"), "outputMessage", "نظام الرتبة: يرجى تسجيل الدخول اولا", 255, 0, 255) end 
    if isObjectInACLGroup("user."..account, aclGetGroup(tostring(Group))) then return call(getResourceFromName("business"), "outputMessage", "نظام الرتبة: انت تمتلك هذه الرتبة بالفعل, يرجى اختيار اخرى", 255, 0, 255) end 
    local sValue = getElementData( source,'Time' ) 
    if not sValue then sValue = '0:0:0' end 
    local data = split(sValue,':') 
    local hour = tonumber( data[1] )   
    if hour == nil or not tonumber(hour) then hour = 0 end 
    if ( hour >= tonumber(Price))  then 
        aclGroupAddObject (aclGetGroup( tostring(Group)),"user."..account); 
        call(getResourceFromName("business"), "outputMessage", Name .. "نظام الرتبة: تهانينا! لقد تمت ترقيتك الى", 0, 245, 33) 
    else 
        call(getResourceFromName("business"), "outputMessage", source, "نظام الرتبة: لا تمتلك الساعات الكافية", 255, 0, 255) 
    end 
end 
addEvent("Accept:the:request",true) 
addEventHandler("Accept:the:request",root,xAddToGroupFunction_) 

for notice .. Check Line 49,51.

Link to comment
  • Moderators

Well, use the feedback I gave you on those. Because their structure are still not the same, as you said you did:

call(getResourceFromName("business"), "outputMessage", source, "Server Side Message Check", 255, 0, 255) 

Link to comment
Well, use the feedback I gave you on those. Because their structure are still not the same, as you said you did:
call(getResourceFromName("business"), "outputMessage", source, "Server Side Message Check", 255, 0, 255) 

I Used it , still giving me the same error:

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

I Tried it on Server/Client Side, Same Error.

Link to comment
  • Moderators
I see this:

Schermafbeelding_2016_01_19_om_17_11_56.png

This is the Part When i Call the outputMessage In Server Side (My Mod)

So it might be not "outputMessage" , maybe it's "player:outputMessage" just like in the "business" mod server side

The code from the screenshot does not have the same structure as:

call(getResourceFromName("business"), "outputMessage", source, "the message bla bla bla...", 0, 245, 33) 

Take a closer look, it is messed up.

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

Ermm, I didn't suggest you to change "player" to "nil". I said that you've inputted "nil" where you were meant to input a player element.
Link to comment
Can you tell me what arguments did you use when calling the function server-side?

look ..

In My Mod - Server Side

- I Didn't Used any arguments , i just used call ( Doesn't Work )

In My Mod - Client Side

- I Didn't Used any arguments , i just used call ( Work's Fine )

In business - Server Side

- he Used some functions .. I Wrote them in Page 2 Of topic (Full Code: core.server.lua)

In business - Client Side

- he Used Only one Function .. In "core.client.lua" .. here is the Code of It:

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

In business - Meta File

- I Exported the Following Functions ..

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

I guess that's Explains every thing right ? ..

Link to comment
In My Mod - Client Side

- I Didn't Used any arguments , i just used call ( Work's Fine )

How do you know it works fine on client side? I mean, if you haven't inputted any arguments then nothing should be outputted, since you didn't input a message to display.

Look ..

I Used This Code On Client Side:

call(getResourceFromName("business"), "outputMessage", source, "the message bla bla bla...", 0, 245, 33) 

and when i tested it , the message showed up ! & no Error Given !

But When i called it on Server Side With the Same code , didn't work & gave me an error:

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

So let's guess ..

Maybe i should not use "outputMessage" , because in "business Meta.xml" i added 2 Functions with the Same name , but only changed the Type ..:

        function="outputMessage" type="client"/> 
        function="outputMessage" type="server"/> 

Maybe , this is not correct isn't it ?

Link to comment

This is because the first argument sent to triggerClientEven should be a player element, but something different is received, causing MTA to think this was the event name, not the sentTo argument, and thus argument 2 is expected to be the eventSource though in fact argument 2 is a string - causing an error.

To summarise, you did not input a valid player element as the target for the output.

call(getResourceFromName("business"), "outputMessage", source, "the message bla bla bla...", 0, 245, 33) -- source is not defined in the serverside 

Link to comment

@MrTasty

I Understand Now ..

Here is the Edit's i made in My Mod (server.lua):

----------------------- 
-- Admin Shop 
-- Created By NiGht 
---------------------- 
  
----------------------- 
-- Get Player Groups -- 
----------------------- 
function getGroups() 
    if (isElement(source) and getElementType(source) == "player") then 
        local allGroups = aclGroupList(); 
        local groups = ""; 
        for _, v in ipairs(allGroups) do 
            if (isObjectInACLGroup("user." .. getAccountName(getPlayerAccount(source)), v)) then 
                groups = aclGroupGetName(v) .. ", " .. groups; 
            end 
        end 
        
        triggerClientEvent(source, "c_getGroups", source, groups); 
    end 
end 
addEvent("s_getGroups", true) 
addEventHandler("s_getGroups", root, getGroups) 
  
  
---------------------- 
-- Get Account Name -- 
---------------------- 
addEventHandler("onPlayerLogin",root, 
    function(_,account) 
        triggerClientEvent(source,"getAccName",source,getAccountName(account)) 
    end 
) 
  
------------------- 
-- Main Function -- 
------------------- 
xAddToGroupFunction_ = function ( Group,Price,Name ) 
    local account = getAccountName(getPlayerAccount(source)); 
    if isGuestAccount(getPlayerAccount(source)) then return call(getResourceFromName("business"), "outputMessage", "نظام الرتبة: يرجى تسجيل الدخول اولا", 255, 0, 255) end 
    if isObjectInACLGroup("user."..account, aclGetGroup(tostring(Group))) then return call(getResourceFromName("business"), "outputMessage", "نظام الرتبة: انت تمتلك هذه الرتبة بالفعل, يرجى اختيار اخرى", 255, 0, 255) end 
    local sValue = getElementData( source,'Time' ) 
    if not sValue then sValue = '0:0:0' end 
    local data = split(sValue,':') 
    local hour = tonumber( data[1] )   
    if hour == nil or not tonumber(hour) then hour = 0 end 
    if ( hour >= tonumber(Price))  then 
        aclGroupAddObject (aclGetGroup( tostring(Group)),"user."..account); 
        call(getResourceFromName("business"), "outputMessage", source, Name .. "the message bla bla bla...", 0, 245, 33) 
    else 
        call(getResourceFromName("business"), "outputMessage", source, "the message bla bla bla...", 0, 245, 33) 
    end 
end 
addEvent("Accept:the:request",true) 
addEventHandler("Accept:the:request",root,xAddToGroupFunction_) 

Still Doesn't Work my friend ..

The Error Given:

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

This is Really Annoying problem ..

Link to comment

Try manually triggering the events in your code instead of using the export.

-- replace 
call(getResourceFromName("business"), "outputMessage", source, "the message bla bla bla...", 0, 245, 33) 
-- with 
triggerClientEvent(source, "business.dxOutputMessage", source, "the message bla bla bla...", 0, 245, 33) 

Link to comment
Try manually triggering the events in your code instead of using the export.
-- replace 
call(getResourceFromName("business"), "outputMessage", source, "the message bla bla bla...", 0, 245, 33) 
-- with 
triggerClientEvent(source, "business.dxOutputMessage", source, "the message bla bla bla...", 0, 245, 33) 

Freaking Hell :shock:

it worked :mrgreen:

After 43 Posts @@" even the Pinned Topics didn't get more than 10 reply :lol:

Thank you So much man ! you saved my life :D

and thanks to @tosfera and @IIYAMA

Also , I Think no body else keeped helping me to the end except you , You Deserve to be in Top :) .

Problem Solved.

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