Jump to content

make a function available among other scripts


Derpy

Recommended Posts

hello, you probably already know whats my question as it can be seen on my topic name

anyway i have seen some scripts which basically call custom functions

e.g

  
if a = 1 then 
createError("#1") return end 
  

how could i share a function among all resources without exports?

if it's impossible then how could i pass an element(probably player) to another script so that it would make that error only for the sent player element?

i also know that type of a script can be "shared" in meta, can anyone explain what does that exactly mean?

i hope you guys have understanded my question, if you know an answer to this, please reply.Thanks in advance.

Link to comment

alright and thank you for your replies.

@eAi there's nothing wrong with it, I've just been wondering if there was an other way to do it.

edit: if i was using an export from client to client to trigger an error message(with dx text) for a single client, would using localPlayer(in exported function) draw it for only the client that i've sent dx text to or would it draw for anyone?

Link to comment
  • MTA Team

If you call a clientside exported function then it will be called for the player, whose script called the exported function.

But if you call a serverside exported function, which should show an error message for a specific player, then you have to pass the player as a parameter and use it in the exported function defintion-file.

Link to comment

thanks, i have been doing some tests with exports as i haven't used them before and it worked fine when i was exporting a function which would get text from my command 'ctrigger' and it'd output it to chatbox perfectly fine

however when i have tried using dxDrawText function it simply outputted that the function didnt recieve any text

exportResource(client.lua)

local sw,sh = guiGetScreenSize() 
  
function errorMessage(text) 
if text then 
dxDrawText(tostring(text),sw/2,sh/2,sw/2,sh/2,tocolor(255,255,255,255),1,"bankgothic","center","top",false,false,false,true) 
else outputDebugString("exportResource: error; no text") return end 
end 
  
function removeErrorMessage() 
removeEventHandler("onClientRender",root,errorMessage) 
outputDebugString("exportResource: render handler removed!") 
end 
  
function addErrorMessage() 
addEventHandler("onClientRender",root,errorMessage) 
outputDebugString("exportResource: handler was added, it will be removed in 5 seconds") 
setTimer(removeErrorMessage,5000,1) 
end 

test(client.lua) -- the resource which was supposed to send the text to exported resource

function commandError(commandName,text) 
exports.exportResource:errorMessage(text) 
exports.exportResource:addErrorMessage() 
outputDebugString("test:4: Export call was sent.") 
end 
addCommandHandler("ctrigger",commandError) 

Additional Info of custom debugging:

INFO: exportResource: handler was added, it will be removed in 5 seconds

INFO: exportResource: Export call was sent.

*** SPAM ***

INFO: exportResource: error; no text

*** END ***

INFO: exportResource: render handler removed

what am i doing wrong?

Link to comment
  
local sw,sh = guiGetScreenSize() 
local text = nil 
function errorMessage() 
if text then 
dxDrawText(text,sw/2,sh/2,sw/2,sh/2,tocolor(255,255,255,255),1,"bankgothic","center","top",false,false,false,true) 
else outputDebugString("exportResource: error; no text") return end 
end 
  
function removeErrorMessage() 
removeEventHandler("onClientRender",root,errorMessage) 
outputDebugString("exportResource: render handler removed!") 
end 
  
function addErrorMessage() 
addEventHandler("onClientRender",root,errorMessage) 
outputDebugString("exportResource: handler was added, it will be removed in 5 seconds") 
setTimer(removeErrorMessage,5000,1) 
end 
  
function commandError(commandName,text2) 
if text2 == false or text2 == nil then return end 
text = text2 
addErrorMessage() 
outputDebugString("test:4: Export call was sent.") 
end 
addCommandHandler("ctrigger",commandError) 
  

Link to comment

alright thanks

and im having a problem when using space key between text

if i want to write

hello world

it would just draw 'hello'

so i'd need to use hello_world to make both words visible and i dont wanna do that

how could i make this draw the spaces between characters too?

Link to comment

Use table.concat!

Don't let us make the script! Try yourself next time!

  
local sw,sh = guiGetScreenSize() 
local text = nil 
function errorMessage() 
if text then 
dxDrawText(text,sw/2,sh/2,sw/2,sh/2,tocolor(255,255,255,255),1,"bankgothic","center","top",false,false,false,true) 
else outputDebugString("exportResource: error; no text") return end 
end 
  
function removeErrorMessage() 
removeEventHandler("onClientRender",root,errorMessage) 
outputDebugString("exportResource: render handler removed!") 
end 
  
function addErrorMessage() 
addEventHandler("onClientRender",root,errorMessage) 
outputDebugString("exportResource: handler was added, it will be removed in 5 seconds") 
setTimer(removeErrorMessage,5000,1) 
end 
  
function commandError(commandName,text2) 
if text2 == false or text2 == nil then return end 
text = table.concat({string.gsub(text2, '#%x%x%x%x%x%x', '')}, " ") 
addErrorMessage() 
outputDebugString("test:4: Export call was sent.") 
end 
addCommandHandler("ctrigger",commandError) 
  

Link to comment
Use table.concat!

Don't let us make the script! Try yourself next time!

actually if you look better, i made this script and only asked for help for it as my text wasnt being sent via exports

and how the fuck am i supposed to make something by myself if i dont know how to?

i thought this section was about helping people if they need it regarding scripts, it looks like its just people saying "make everything by yourself"

also, your line is drawing 'Hello World' into 'Hello 0'

Link to comment
  
  
local sw,sh = guiGetScreenSize() 
local text = nil 
function errorMessage() 
if text then 
dxDrawText(text,sw/2,sh/2,sw/2,sh/2,tocolor(255,255,255,255),1,"bankgothic","center","top",false,false,false,true) 
else outputDebugString("exportResource: error; no text") return end 
end 
  
function removeErrorMessage() 
removeEventHandler("onClientRender",root,errorMessage) 
outputDebugString("exportResource: render handler removed!") 
end 
  
function addErrorMessage() 
addEventHandler("onClientRender",root,errorMessage) 
outputDebugString("exportResource: handler was added, it will be removed in 5 seconds") 
setTimer(removeErrorMessage,5000,1) 
end 
  
function commandError(commandName,text2) 
if text2 == false or text2 == nil then return end 
text = table.concat({text2}, " ") 
addErrorMessage() 
outputDebugString("test:4: Export call was sent.") 
end 
addCommandHandler("ctrigger",commandError) 
  
  

You could see local chat scripts for this idea.

Link to comment
  
  
  
local sw,sh = guiGetScreenSize() 
local text = nil 
function errorMessage() 
if text then 
dxDrawText(text,sw/2,sh/2,sw/2,sh/2,tocolor(255,255,255,255),1,"bankgothic","center","top",false,false,false,true) 
else outputDebugString("exportResource: error; no text") return end 
end 
  
function removeErrorMessage() 
removeEventHandler("onClientRender",root,errorMessage) 
outputDebugString("exportResource: render handler removed!") 
end 
  
function addErrorMessage() 
addEventHandler("onClientRender",root,errorMessage) 
outputDebugString("exportResource: handler was added, it will be removed in 5 seconds") 
setTimer(removeErrorMessage,5000,1) 
end 
  
function commandError(commandName, ...) 
text = table.concat({...}, " ") 
if text == "" then return end 
addErrorMessage() 
outputDebugString("test:4: Export call was sent.") 
end 
addCommandHandler("ctrigger",commandError) 
  

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