Talk:CallServerFunction: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(An inmproved one discussion)
 
mNo edit summary
 
(6 intermediate revisions by 3 users not shown)
Line 17: Line 17:
end
end
)
)
-- and call them like
-- @see down below for this
triggerServerEvent("onClientRequest", rootElement, "changeResStateS", resource, state)
--and call them like
-- triggerServerEvent("onClientRequest", rootElement, "changeResStateS", resource, state)
-- while I have defined a function changeResStateS(resource, state) end on server side and vice versa.
-- while I have defined a function changeResStateS(resource, state) end on server side and vice versa.
</syntaxhighlight>
</syntaxhighlight>
[[User:LordAzamath|LordAzamath]] 19:47, 14 May 2009 (CEST)
[[User:LordAzamath|LordAzamath]] 19:47, 14 May 2009 (CEST)
----
Yeah, nice idea to save some space except for the trigger-Event solution. CallClient/ServerFunction should enshorten this. [[User:NeonBlack|NeonBlack]] 20:23, 15 May 2009 (CEST)<br />
By the way: I think the yellow note isn't needed since there is no way hacking mta to call some function. To get the possibility for calling functions the scripter needs adding this possibility manually. So this note would be just as well be added to banPlayer. [[User:NeonBlack|NeonBlack]] 20:37, 15 May 2009 (CEST)
----
* The yellow box is needed.  If, for example this is added to the Admin resource (which has full admin access) then any resource
could trigger this event and have full admin rights. [[User:Talidan|Talidan]]
----
: In that case the triggerEvent part should be replaced with
<syntaxhighlight lang="lua">
[lua]
function callServerFunction(functionName, ...)
return triggerServerEvent("onClientRequest", rootElement, functionName, ...)
end
-- and
function callClientFunction( player, functionName, ...)
        if getElementType(player) = "player" then
return triggerClientEvent(player, "onClientRequest", rootElement, functionName, ...)
else -- while here player will actually be the function name and functionName the first argument given actually
return triggerClientEvent("onClientRequest", rootElement, player, functionName, ...)
end
end
</syntaxhighlight>
[[User:LordAzamath|LordAzamath]] 08:20, 16 May 2009 (CEST)
----
You should really think of some new discussion post style. I added some horizontal lines to mark the ends of a users comment. You should do so as well. [[User:NeonBlack|NeonBlack]] 11:24, 18 May 2009 (CEST)

Latest revision as of 09:24, 18 May 2009

I would rather use this variant for both calling client and server functions..

[lua]
-- client side
addEvent("onServerRequest", true)
addEventHandler("onServerRequest", rootElement,
	function (funcname, ...)
		 _G[funcname](...)
	end
)
-- server side
addEvent("onClientRequest", true)
addEventHandler("onClientRequest", rootElement,
	function (funcname, ...)
		 _G[funcname](...)
	end
)
-- @see down below for this
--and call them like
--	triggerServerEvent("onClientRequest", rootElement, "changeResStateS", resource, state)
-- while I have defined a function changeResStateS(resource, state) end on server side and vice versa.

LordAzamath 19:47, 14 May 2009 (CEST)


Yeah, nice idea to save some space except for the trigger-Event solution. CallClient/ServerFunction should enshorten this. NeonBlack 20:23, 15 May 2009 (CEST)
By the way: I think the yellow note isn't needed since there is no way hacking mta to call some function. To get the possibility for calling functions the scripter needs adding this possibility manually. So this note would be just as well be added to banPlayer. NeonBlack 20:37, 15 May 2009 (CEST)


  • The yellow box is needed. If, for example this is added to the Admin resource (which has full admin access) then any resource

could trigger this event and have full admin rights. Talidan


In that case the triggerEvent part should be replaced with
[lua]
function callServerFunction(functionName, ...)
	return triggerServerEvent("onClientRequest", rootElement, functionName, ...)
end
-- and
function callClientFunction( player, functionName, ...)
        if getElementType(player) = "player" then
		return triggerClientEvent(player, "onClientRequest", rootElement, functionName, ...)
	else -- while here player will actually be the function name and functionName the first argument given actually
		return triggerClientEvent("onClientRequest", rootElement, player, functionName, ...)
	end
end

LordAzamath 08:20, 16 May 2009 (CEST)


You should really think of some new discussion post style. I added some horizontal lines to mark the ends of a users comment. You should do so as well. NeonBlack 11:24, 18 May 2009 (CEST)