Sign in to follow this  
Szymixo

onClientResourceStart doesn't work

Recommended Posts

Hello, i have small problem. 

My event 'onClientResourceStart' doesn't work correctly.

i have this code in client-side: 

function starts()
	outputChatBox("Resource started")
	setPlayerHudComponentVisible("all", false)
	showCursor(true)
	showChat(false)
	addEventHandler("onClientRender", getResourceRootElement(), drawPanel)
end
addEventHandler("onClientResourceStart", getResourceRootElement(), starts)

it's doesn't work. For testing i add this code for server-side and it's work correctly: 

addEventHandler("onResourceStart", resourceRoot, function()
	outputDebugString("Resource login started")
end)

 

Where is the problem?

Thank you for the help

Share this post


Link to post

Try this and make sure the client script is defined into the meta.xml as a client side script.

function starts()
	outputChatBox("Client started.")
	setPlayerHudComponentVisible("all", false)
	showCursor(true)
	showChat(false)
	addEventHandler("onClientRender", getResourceRootElement(), drawPanel)
end

addEventHandler("onClientResourceStart", getResourceRootElement( getThisResource() ), starts )

 

  • Like 1

Share this post


Link to post

You can always simply use "resourceRoot" client side as well instead of that ugly long thing :P

Share this post


Link to post

It's not working, it's all of my meta.xml

<meta>
	<info author="Szymixo" name="Panel logowania" version="1.0" type="script" /> 

	<script src="login_s.lua" type="server" />
	<script src="client.lua" type="client" />
	
	<file src="images/tlo.png" />
	<file src="images/zaloguj.png" />
	<file src="images/zarejestruj.png" />
</meta>

and it's my client.lua:


local sX, sY = guiGetScreenSize()
local data = { showed = nil, button = {}, info = nil, misc = nil }
-------------------------------------------------------------------------
function isMouseIn(psx, psy, pssx, pssy, abx, aby)
	if not isCursorShowing() then return end
	cx, cy = getCursorPosition()
	cx, cy = cx*sX, cy*sY
	if cx >= psx and cx <= psx + pssx and cy >= psy and cy <= psy + pssy then
		return true cx, cy
	else
		return false
	end
end
-------------------------------------------------------------------------
GUIEditor = {
    staticimage = {},
    label = {},
	button = {}
}
function drawPanel()
	GUIEditor.staticimage[1] = guiCreateStaticImage(sX*0/1280, sY*0/720, sX*1280/1280, sY*720/720, ":truck_login/images/tlo.png", false)
    GUIEditor.login = guiCreateEdit(sX*526/1280, sY*322/720, sX*228/1280, sY*52/720, "", false, GUIEditor.staticimage[1])
    GUIEditor.pass = guiCreateEdit(sX*525/1280, sY*414/720, sX*229/1280, sY*53/720, "", false, GUIEditor.staticimage[1])
    guiEditSetMasked(GUIEditor.pass, true)
    GUIEditor.button[1] = guiCreateStaticImage(sX*579/1280, sY*475/720, sX*124/1280, sY*32/720, ":truck_login/images/zaloguj.png", false, GUIEditor.staticimage[1])
	GUIEditor.button[2] = guiCreateStaticImage(sX*579/1280, sY*509/720, sX*124/1280, sY*32/720, ":truck_login/images/zarejestruj.png", false, GUIEditor.staticimage[1])
    if data.info then GUIEditor.label[1] = guiCreateLabel(sX*483, sY*248/720, sX*314/1280, sY*22/720, "Dokonałeś pomyślnej rejestracji!", false, GUIEditor.staticimage[1]) end
    guiSetFont(GUIEditor.label[1], "default-bold-small")
    guiLabelSetHorizontalAlign(GUIEditor.label[1], "center", false)    
end

addCommandHandler("panel", function(plr, cmd)
	outputChatBox("Uzywasz /panel, "..name)
end)
-------------------------------------------------------------------------
addEventHandler("onClientGUIClick", GUIEditor.button[1], resourceRoot, function()
	local login = guiGetText(GUIEditor.login)
	local pass = guiGetText(GUIEditor.pass)
	if string.len(login) < 2 or string.len(pass) < 2 then
		data.info = "Wypełnij wszystkie pola!"
		return
	end
	triggerServerEvent("checkAccount", resourceRoot, login, pass)
end)

addEventHandler("onClientGUIClick", GUIEditor.button[2], resourceRoot, function()
	local login = guiGetText(GUIEditor.login)
	local pass = guiGetText(GUIEditor.pass)
	if string.len(login) < 2 and string.len(pass) < 2 then
		data.info  = "Wypełnij wszystkie pola!"
		return
	end
	triggerServerEvent("createAccount", resourceRoot, login, pass)
end)
-------------------------------------------------------------------------
addEventHandler( "onClientResourceStart", getResourceRootElement(getThisResource()), function()
	outputChatBox("Resource started");
    setPlayerHudComponentVisible("all", false);
    showCursor(true);
    showChat(false);
    addEventHandler("onClientRender", getResourceRootElement(), drawPanel);
end);
-------------------------------------------------------------------------
addEvent("loginResult", true)
addEventHandler("loginResult", resourceRoot, function(value, info)
	if not info then info = "" end
	if value then
		removeEventHandler("onClientRender", resourceRoot, drawPanel)
	else
		data.info = tostring(info)
		setTimer(function() data.info = nil end, 3000, 1)
	end
		
end)
-------------------------------------------------------------------------

 

all of client.lua doesn't work. /panel command too.

Share this post


Link to post

Firth the GUIEditor. login and pass not exist because the GUIEditor is a table 

Share this post


Link to post

you don't need onClientResourceStart when you use onClientRender.

 

just 

addEventHandler("onClientRender", root, function()

 

--- Your code here.


    onStart()

end)

And if you want to something with player when they join, just use this:

function onStart()

    showCursor(true)

   showChat(false)

end

 

Share this post


Link to post
On 12/24/2017 at 10:23, TheMOG said:

you don't need onClientResourceStart when you use onClientRender.

OnClientRender is dynamic, which means it updates constantly (every time GTA renders a new frame)
So every time ANYTHING moves on the clients screen it'll execute the code he places on OnClientRender.
This isn't an efficient method for what he's doing.

Quote

onClientRender

Clientside event

This event is triggered every time GTA renders a new frame. It is required for the DirectX drawing functions, and also useful for other clientside operations that have to be applied repeatedly with very short time differences between them.

 

Edited by Justin|X5|

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.