Jump to content

call triggerServerEvent


Klesh

Recommended Posts

Hello, i want to call from something from the server side, because other function are clientSide.

Example :

--Server 
addEventHandler("playerSide", getRootElement(getThisResource()) 
addEvent("playerSide", true) 
function (thePlayer) 
pThink = exports["something"]:getSomething(thePlayer) 
end 

--Client  
pthink = triggerServerEvent("playerSide", getLocalPlayer()) 
think = '*' ..pthink 

It don't works, some other way?

Link to comment

not Tested :)

---- serverSide 
function whatever (thePlayer) 
pThink = exports["something"]:getSomething(thePlayer) 
end 
addEvent( "playerSide", true ) 
addEventHandler( "playerSide", getRootElement(), whatever) 
  
------ clientSide 
function Here (thePlayer) 
triggerServerEvent("playerSide", getLocalPlayer()) 
think = '*' ..pthink 
end 

Link to comment

I made it looooong time.

Client-side:

  
MessagesTable = {} 
  
function SCreateMessages(str) 
    table.insert(MessagesTable, {str, 255, false}) 
    if #MessagesTable >= 11 then 
        table.remove(MessagesTable, 1) 
    end 
end 
addEvent( "onCreateMessages", true ) 
addEventHandler( "onCreateMessages", getRootElement(), SCreateMessages ) 
  
function onMessagesReader() 
    local screenx, screeny = guiGetScreenSize() 
    for i, v in ipairs(MessagesTable) do 
        if v[2] <= 255 and v[3] == false then 
            if v[2] <= 0 then 
                v[3] = true 
            else 
                v[2] = v[2] - 0.50 
            end 
        end 
        dxDrawColorTextM(string.gsub(v[1], '#%x%x%x%x%x%x', '#000000'), 1+(((screenx-20)-(dxGetTextWidth(string.gsub(v[1], '#%x%x%x%x%x%x', ''),(screenx/1024)*1.2,"default-bold")))/1024)*screenx, 1+((250 + dxGetFontHeight(1.2,"default-bold") * (i - 1))/768)*screeny, 1+(((screenx-20)-(dxGetTextWidth(string.gsub(v[1], '#%x%x%x%x%x%x', ''),(screenx/1024)*1.2,"default-bold")))/1024)*screenx, 1+((250 + dxGetFontHeight(1.2,"default-bold") * (i - 1))/768)*screeny, tocolor(0,0,0,v[2]), (screenx/1024)*1.2, "default-bold", v[2]) 
        dxDrawColorTextM(v[1], (((screenx-20)-(dxGetTextWidth(string.gsub(v[1], '#%x%x%x%x%x%x', ''),(screenx/1024)*1.2,"default-bold")))/1024)*screenx, ((250 + dxGetFontHeight(1.2,"default-bold") * (i - 1))/768)*screeny, (((screenx-20)-(dxGetTextWidth(string.gsub(v[1], '#%x%x%x%x%x%x', ''),(screenx/1024)*1.2,"default-bold")))/1024)*screenx, ((250 + dxGetFontHeight(1.2,"default-bold") * (i - 1))/768)*screeny, tocolor(255,255,255,v[2]), (screenx/1024)*1.2, "default-bold", v[2]) 
    end 
end 
addEventHandler("onClientRender", getRootElement(), onMessagesReader) 
  
function dxDrawColorTextM(str, ax, ay, bx, by, color, scale, font, alpha) 
    local pat = "(.-)#(%x%x%x%x%x%x)" 
    local s, e, cap, col = str:find(pat, 1) 
    local last = 1 
    while s do 
        if cap == "" and col then color = tocolor(tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)), alpha) end 
        if s ~= 1 or cap ~= "" then 
            local w = dxGetTextWidth( cap, scale, font) 
            dxDrawText(cap, ax, ay, ax + w , by, color, scale, font, "center", "bottom", false, false, false ) 
            ax = ax + w 
            color = tocolor(tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)), alpha) 
        end 
        last = e + 1 
        s, e, cap, col = str:find(pat, last)     
    end 
    if last <= #str then 
        cap = str:sub(last) 
        local w = dxGetTextWidth(cap, scale, font) 
        dxDrawText(cap, ax, ay, ax + w , by, color, scale, font, "center", "bottom", false, false, false ) 
    end 
end 
  

Server-side:

  
function CreateMessages(str) 
    triggerClientEvent ( getRootElement(), "onCreateMessages", getRootElement(), str) 
end 
  
function onJoinPlayerMessages() 
    triggerClientEvent ( getRootElement(), "onCreateMessages", getRootElement(), "#ffffff" .. getPlayerName(source) .. "#60f8ff has joined the server from: #00ff00" .. getPlayerFlag(source)) 
end 
addEventHandler('onPlayerJoin', getRootElement(), onJoinPlayerMessages) 
  
function onPlayerChangeNickMessages(old, new) 
    triggerClientEvent ( getRootElement(), "onCreateMessages", getRootElement(), "#ffffff" .. old .. "#60f8ff is now known as #ffffff " .. new) 
end 
addEventHandler('onPlayerChangeNick', getRootElement(), onPlayerChangeNickMessages) 
  
function onQuitPlayerMessages(reason) 
    triggerClientEvent ( getRootElement(), "onCreateMessages", getRootElement(), "#ffffff" .. getPlayerName(source) .. "#60f8ff has left the server [#ffffff" .. reason .. "#60f8ff]") 
end 
addEventHandler('onPlayerQuit', getRootElement(), onQuitPlayerMessages) 
  
function onPlayerLoginMessages() 
    triggerClientEvent ( getRootElement(), "onCreateMessages", getRootElement(), "#ffffff" .. getPlayerName(source) .. "#60f8ff has logged in!") 
end 
addEventHandler('onPlayerLogin', getRootElement(), onPlayerLoginMessages) 
  

function serverside: CreateMessages( string )

function clientside: SCreateMessages( string )

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