Klesh Posted February 4, 2012 Share Posted February 4, 2012 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
Evil-Cod3r Posted February 4, 2012 Share Posted February 4, 2012 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
Castillo Posted February 4, 2012 Share Posted February 4, 2012 triggerServerEvent will only return if it was success or not, it doesn't work like a function using "return". Link to comment
Evil-Cod3r Posted February 4, 2012 Share Posted February 4, 2012 Castillo you mean my script wont work ? Link to comment
Castillo Posted February 4, 2012 Share Posted February 4, 2012 Of course it won't, you have the "pThink" variable in the server side and you want to use it on the client side. Link to comment
Evil-Cod3r Posted February 4, 2012 Share Posted February 4, 2012 Castillo Can You Give us an example so i wont fall in the same mistake ? please Link to comment
Castillo Posted February 4, 2012 Share Posted February 4, 2012 An example of what? I already posted that triggerServerEvent doesn't do what Klesh want's, just find another way to do it. Link to comment
Klesh Posted February 4, 2012 Author Share Posted February 4, 2012 Didn't know how to call it, hard cuz i want it to dxDrawCreateText, then the getPlayerEXP is server-side, i cant make once, i have to do in 2 files, server and client, i dont made it, im confused. Link to comment
Castillo Posted February 4, 2012 Share Posted February 4, 2012 Can't you use element data to store the experience temporary? P.S: It's dxDrawText Not dxDrawCreateText Link to comment
Klesh Posted February 4, 2012 Author Share Posted February 4, 2012 I knew that, just i want to show it in a text, but the exported function is client, and the message is server. Link to comment
Cadu12 Posted February 4, 2012 Share Posted February 4, 2012 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now