FutScripter Posted January 31, 2021 Share Posted January 31, 2021 (Sorry if the text contains errors, I'm Russian). Hello! I decided to make a telephone. As we know, in order to create a picture on the screen, we need a client. But, since the main part is on the server, you need to call the client function on the server. It seems like I did everything right (you can see the screenshots below), but it does not work: the picture does not appear. No errors are displayed in the console. Can you please help with this error? Server Client Link to comment
Administrators Tut Posted January 31, 2021 Administrators Share Posted January 31, 2021 Hi @FutScripter Thread's been moved into the Scripting section for best results. MTA Chat is not for receiving support, but for general discussion of MTA. Link to comment
Moderators Patrick Posted January 31, 2021 Moderators Share Posted January 31, 2021 (edited) Hi. Okay, so there are 3 problems with your code, what I can see now. 1) You have to use every dxDraw... functions inside a render event (onClientRender), because when you call these functions, the image visible only for 1 frame. 2) On client-side 3rd parameter of addEventHandler is missing, the attached function. 3) On server-side your triggerClientEvent is bad, because now you send this trigger to every(!) clients, you have the define "sendTo" parameter, it's root (everyone) by default. Should look something like this: -- CLIENT function phoneRender() dxDrawImage(540, 290, 281, 512, "images/phone.png") end function openPhone() addEventHandler("onClientRender", root, phoneRender) end addEvent("openPhone", true) addEventHandler("openPhone", root, openPhone) -- how to stop render: function closePhone() removeEventHandler("onClientRender", root, phoneRender) end -- SERVER -- only the trigger -- send this trigger only to "player", who entered the command triggerClientEvent(player, "openPhone", root) Here you can read about events: https://forum.multitheftauto.com/topic/114541-tut-events/ Edited January 31, 2021 by Patrick 1 Link to comment
FutScripter Posted February 1, 2021 Author Share Posted February 1, 2021 20 hours ago, Patrick said: Hi. Okay, so there are 3 problems with your code, what I can see now. 1) You have to use every dxDraw... functions inside a render event (onClientRender), because when you call these functions, the image visible only for 1 frame. 2) On client-side 3rd parameter of addEventHandler is missing, the attached function. 3) On server-side your triggerClientEvent is bad, because now you send this trigger to every(!) clients, you have the define "sendTo" parameter, it's root (everyone) by default. Should look something like this: -- CLIENT function phoneRender() dxDrawImage(540, 290, 281, 512, "images/phone.png") end function openPhone() addEventHandler("onClientRender", root, phoneRender) end addEvent("openPhone", true) addEventHandler("openPhone", root, openPhone) -- how to stop render: function closePhone() removeEventHandler("onClientRender", root, phoneRender) end -- SERVER -- only the trigger -- send this trigger only to "player", who entered the command triggerClientEvent(player, "openPhone", root) Here you can read about events: https://forum.multitheftauto.com/topic/114541-tut-events/ Oh, thank you very much! You helped me a lot! Link to comment
Moderators Patrick Posted February 1, 2021 Moderators Share Posted February 1, 2021 1 hour ago, FutScripter said: Oh, thank you very much! You helped me a lot! Welcome 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