Perfect Posted April 21, 2015 Share Posted April 21, 2015 Hello Everyone, Since few hours i am trying to run this simple script which uses 'trigerClientEvent'. scripts:- server: myMessages = { "Message 1", "Message 2", "Message 3" } function startIt() for i=1,3 do triggerClientEvent(resourceRoot, "sendMessage", root, myMessages[i]) --I tried replacing 'root' with resourceRoot,source,v(looping getElementsByType('player') end outputChatBox("Resource started") end addEventHandler("onResourceStart", resourceRoot, startIt) client: addEvent("sendMessage", true) function myMessage(message) outputChatBox(message) end addEventHandler("sendMessage",resourceRoot,myMessage) The problem is when i start the resource nothing happened except 'Resource Started' message was showed and there were/are no errors/warnings in debugscript 3. I tried removing 1st argument from 'triggerClientEvent' but that causes an error: Event is not added client side. Hope you guys can help me in solving this. Link to comment
WhoAmI Posted April 21, 2015 Share Posted April 21, 2015 onResourceStart event is called before loading client-side script. You are triggering an event which isn't loaded yet. Link to comment
Perfect Posted April 21, 2015 Author Share Posted April 21, 2015 Oh, thanks for info. If i am right, then it can be fix with setTimer() but still there are any other ways to solve it ? Link to comment
WhoAmI Posted April 21, 2015 Share Posted April 21, 2015 viewtopic.php?f=91&t=87245 User had similar problem. The solution is onClientResourceStart event. Link to comment
Perfect Posted April 21, 2015 Author Share Posted April 21, 2015 You mean, i need to do something like this ? scripts:- server: addEvent("sendMessageAgain", true) myMessages = { "Message 1", "Message 2", "Message 3" } function sendMessageBack() for i=1,3 do triggerClientEvent(resourceRoot, "sendMessage", resourceRoot, myMessages[i]) end outputChatBox("Resource started") end addEventHandler("sendMessageAgain", resourceRoot, sendMessageBack) client: addEvent("sendMessage", true) function myMessage(message) outputChatBox(message) end addEventHandler("sendMessage",resourceRoot,myMessage) function startIt() triggerServerEvent("sendMessageAgain", resourceRoot) end addEventHandler("onClientResourceStart", resourceRoot, startIt) Link to comment
TAPL Posted April 21, 2015 Share Posted April 21, 2015 "Resource started" will appear to all players when any player join and his/her resource started. And resourceRoot isn't player, you should use client. Link to comment
WhoAmI Posted April 22, 2015 Share Posted April 22, 2015 addEvent("sendMessageAgain", true) myMessages = { "Message 1", "Message 2", "Message 3" } addEvent("sendMessageAgain", true) function sendMessageBack() for i=1,3 do triggerClientEvent(source, "sendMessage", source, myMessages[i]) end outputChatBox("Resource started") end addEventHandler("sendMessageAgain", resourceRoot, sendMessageBack) addEvent("sendMessage", true) function myMessage(message) outputChatBox(message) end addEventHandler("sendMessage",resourceRoot,myMessage) function startIt() triggerServerEvent("sendMessageAgain", localPlayer) end addEventHandler("onClientResourceStart", resourceRoot, startIt) Link to comment
Walid Posted April 22, 2015 Share Posted April 22, 2015 (edited) Try to use my solution here , WhoAmI already gave it to you Edited April 22, 2015 by Guest Link to comment
Perfect Posted April 22, 2015 Author Share Posted April 22, 2015 (edited) @TAPL, thanks,It solved the problem. @WhoIAm,I already solved the problem with TAPL's solution but your solution may also work so thank you too. @Walid,I tried that but it is a bit complicated for me but thanks for replying. But now, i am in new problem. I made a simple script which gets table data from server side and use it in client side but it is not working It gives errors/warnings debuscript. scripts:- server: --tables Pos = { {-2.73642, 24.87629, 114.14844}, {12.32154, 51.76832, 14.14844}, {-13.67212, -15.60738, 14.14844} } myPed = {} for i=1,10 do myPed[i] = createPed(0,Pos[i][1],Pos[i][2],Pos[i][3]) setElementHealth(myPed[i], 50) end --trigger function triggerIt() for i=1,10 do triggerClientEvent("sendTableData", resourceRoot, myPed[i]) end end function delayStart() addEventHandler("onResourceStart", resourceRoot, triggerIt) end addEventHandler("onResourceStart", resourceRoot, function() setTimer(delayStart, 10000, 1) end ) client: addEvent("sendTableData", true) function movePedForward(ped) local players = getElementsByType('player') local vehicles = getElementByType('vehicle') for pi,p in pairs(players) do setElementCollidableWith(ped, p, false) end for vi,v in pairs(vehicles) do setElementCollidableWith(ped, v, false) end end function pedRender(ped) posx,posy = getElementPosition(ped) setPedCameraRotation(ped, (posx+posy+180)) end --Event Handlers setTimer (function() addEventHandler("onClientRender", root, pedRender) end, 15000, 1 ) addEventHandler("sendTableData", root, pedRender) addEventHandler("sendTableData", root, movePedForward) debugscript: WARNING: MTrigger\script_c.lua:15: Bad argument @ 'getElementPosition' [Expected elemant at argument 1, got nil] ERROR:MTrigger\script_c.lua:16: attempt to perform arithmetic on global 'posx' (a boolean value) Can someone please help me in solving this problem ? Edited April 22, 2015 by Guest Link to comment
Perfect Posted April 22, 2015 Author Share Posted April 22, 2015 Oh, sorry. that was a typo. still the same error/warning. Link to comment
Mega9 Posted April 22, 2015 Share Posted April 22, 2015 function pedRender() posx,posy = getElementPosition(localPlayer) setPedCameraRotation(localPlayer, posx+90, posy+90,posx, posy) end Try this. EDIT: setPedCameraRotation requires only 1 rotation argument (a float), so your function will not work nevertheless. https://wiki.multitheftauto.com/wiki/Se ... raRotation Link to comment
Perfect Posted April 22, 2015 Author Share Posted April 22, 2015 It looks like you didn't read my scripts as i want position of ped not a player, so maybe localplayer will not work. Link to comment
Mega9 Posted April 22, 2015 Share Posted April 22, 2015 Indeed, my bad. You're triggering from serverside "SendTableData" event name, while you named your clientside event "sendTableData". That might be the reason of the ped element not being passed. Link to comment
Perfect Posted April 22, 2015 Author Share Posted April 22, 2015 Thanks, I fixed setPedCameraRotation and sendTableData but still same errors occur in debugscript. Debugscript:- WARNING: MTrigger\script_c.lua:15: Bad argument @ 'getElementPosition' [Expected elemant at argument 1, got nil] ERROR: MTrigger\script_c.lua:16: attempt to perform arithmetic on global 'posx' (a boolean value) 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