Stevor Posted March 8, 2021 Share Posted March 8, 2021 (edited) hi i have colshape i want it to give player data "R",true this is my attempt client addEventHandler("onResourceStart", resourceRoot, function () MyZone = createColCuboid(-2034.9541015625,321.2734375, 200.75479125977, 40, 90.2, 17.9) end ) function dimensionChecker (theElement, matchingDimension) if matchingDimension then setElementData(localPlayer, "R", true) end end addEventHandler ("onClientColShapeHit", myZone, dimensionChecker) Edited March 8, 2021 by Stevor Link to comment
Moderators IIYAMA Posted March 8, 2021 Moderators Share Posted March 8, 2021 11 minutes ago, Stevor said: this is my attempt addEventHandler("onClientResourceStart", resourceRoot, function () MyZone = createColCuboid(-2034.9541015625,321.2734375, 200.75479125977, 40, 90.2, 17.9) addEventHandler ("onClientColShapeHit", myZone, dimensionChecker) end ) function dimensionChecker (theElement, matchingDimension) if matchingDimension and theElement == localPlayer then setElementData(localPlayer, "R", true) end end onResourceStart > onClientResourceStart (onResourceStart is serverside only) Moved addEventHandler directly after creating the element. The event onCientResourceStart is executed very late and therefore the element didn't exist when you tried to attach the addEventHandler. Checking if the one hitting the colshape is the localPlayer. Use code block for your code: Link to comment
Stevor Posted March 8, 2021 Author Share Posted March 8, 2021 17 minutes ago, IIYAMA said: addEventHandler("onClientResourceStart", resourceRoot, function () MyZone = createColCuboid(-2034.9541015625,321.2734375, 200.75479125977, 40, 90.2, 17.9) addEventHandler ("onClientColShapeHit", myZone, dimensionChecker) end ) function dimensionChecker (theElement, matchingDimension) if matchingDimension and theElement == localPlayer then setElementData(localPlayer, "R", true) end end onResourceStart > onClientResourceStart (onResourceStart is serverside only) Moved addEventHandler directly after creating the element. The event onCientResourceStart is executed very late and therefore the element didn't exist when you tried to attach the addEventHandler. Checking if the one hitting the colshape is the localPlayer. Use code block for your code: done , but colshape Not created i use command showcol Link to comment
Moderators IIYAMA Posted March 8, 2021 Moderators Share Posted March 8, 2021 35 minutes ago, Stevor said: done , but colshape Not created i use command showcol Are you sure that the code is clientside? -- put on top of script iprint(triggerClientEvent and "serverside" or "clientside") -- and check debugconsole Link to comment
Stevor Posted March 8, 2021 Author Share Posted March 8, 2021 2 minutes ago, IIYAMA said: Are you sure that the code is clientside? -- put on top of script iprint(triggerClientEvent and "serverside" or "clientside") -- and check debugconsole Sorry, I didn't notice, because I have two copies of this it's server Link to comment
Stevor Posted March 9, 2021 Author Share Posted March 9, 2021 17 hours ago, IIYAMA said: Are you sure that the code is clientside? -- put on top of script iprint(triggerClientEvent and "serverside" or "clientside") -- and check debugconsole what to do its server Link to comment
Moderators IIYAMA Posted March 9, 2021 Moderators Share Posted March 9, 2021 2 hours ago, Stevor said: what to do its server 1. changing the eventNames onClientResourceStart > onResourceStart onClientColShapeHit > onColShapeHit 2. Getting rid of localPlayer, since that predefined variable does not exist there. addEventHandler("onResourceStart", resourceRoot, function () MyZone = createColCuboid(-2034.9541015625,321.2734375, 200.75479125977, 40, 90.2, 17.9) addEventHandler ("onColShapeHit", myZone, dimensionChecker) end ) function dimensionChecker (theElement, matchingDimension) if matchingDimension and getElementType(theElement) == "player" then setElementData(theElement, "R", true) end end Link to comment
Stevor Posted March 9, 2021 Author Share Posted March 9, 2021 (edited) 3 hours ago, IIYAMA said: 1. changing the eventNames onClientResourceStart > onResourceStart onClientColShapeHit > onColShapeHit 2. Getting rid of localPlayer, since that predefined variable does not exist there. addEventHandler("onResourceStart", resourceRoot, function () MyZone = createColCuboid(-2034.9541015625,321.2734375, 200.75479125977, 40, 90.2, 17.9) addEventHandler ("onColShapeHit", myZone, dimensionChecker) end ) function dimensionChecker (theElement, matchingDimension) if matchingDimension and getElementType(theElement) == "player" then setElementData(theElement, "R", true) end end thank you its work but how to getElementData For "R" -- i do that function D (theElement, matchingDimension) if (getElementData (theElement, "R") == true) then outputChatBox("true",root,0,255,0,true) else outputChatBox("false",root,0,255,0,true) end end setTimer(D,15000,0) and Get Bad Argument Edited March 9, 2021 by Stevor Link to comment
Moderators IIYAMA Posted March 9, 2021 Moderators Share Posted March 9, 2021 29 minutes ago, Stevor said: and Get Bad Argument You can't magically make data/elements out of nothing. You have to be very specific about what you are trying to do and where your data should come from. 1 Link to comment
Stevor Posted March 10, 2021 Author Share Posted March 10, 2021 18 hours ago, IIYAMA said: You can't magically make data/elements out of nothing. You have to be very specific about what you are trying to do and where your data should come from. but From a player's , he has data true "R" now ? Link to comment
Moderators IIYAMA Posted March 10, 2021 Moderators Share Posted March 10, 2021 9 minutes ago, Stevor said: but From a player's , he has data true "R" now ? In that case you could get all players and loop through them. See first example of this page: https://wiki.multitheftauto.com/wiki/GetElementsByType 1 Link to comment
Stevor Posted March 10, 2021 Author Share Posted March 10, 2021 40 minutes ago, IIYAMA said: In that case you could get all players and loop through them. See first example of this page: https://wiki.multitheftauto.com/wiki/GetElementsByType Oh , do you mean I have to check if Element = Ped Or Vehicle or .... ? function D() local players = getElementsByType ( "player" ) -- get a table of all the players in the server for theKey,thePlayer in ipairs(players) do if (getElementData (thePlayer, "R") == true) then outputChatBox("true",root,0,255,0,true) else outputChatBox("false",root,0,255,0,true) end end end setTimer(D,15000,0) Link to comment
Moderators IIYAMA Posted March 10, 2021 Moderators Share Posted March 10, 2021 51 minutes ago, Stevor said: or .... ? This function collects all elements of a given type and puts them in a table. You do not have to check afterwards which type they are. Link to comment
Stevor Posted March 10, 2021 Author Share Posted March 10, 2021 24 minutes ago, IIYAMA said: This function collects all elements of a given type and puts them in a table. You do not have to check afterwards which type they are. I intend to when player get Data "R" true other Script give him something my problem How do I check does he have have Data "R" true or false Link to comment
Moderators IIYAMA Posted March 10, 2021 Moderators Share Posted March 10, 2021 11 minutes ago, Stevor said: my problem How do I check does he have have Data "R" true or false As you are already doing: 1 hour ago, Stevor said: if (getElementData (thePlayer, "R") == true) then 1 Link to comment
Stevor Posted March 10, 2021 Author Share Posted March 10, 2021 4 hours ago, IIYAMA said: As you are already doing: thank you so much it's work good ! can i change data To anything that is not true, false Link to comment
Scripting Moderators xLive Posted March 10, 2021 Scripting Moderators Share Posted March 10, 2021 9 minutes ago, Stevor said: thank you so much it's work good ! can i change data To anything that is not true, false Yes you can 1 Link to comment
Stevor Posted March 10, 2021 Author Share Posted March 10, 2021 (edited) 19 minutes ago, xLive said: Yes you can thx it's work 19 minutes ago, xLive said: Yes you can how to send value from server to client ? i get value from table what need ? Edited March 10, 2021 by Stevor Link to comment
Tekken Posted March 12, 2021 Share Posted March 12, 2021 You just replace « true/false » with a table or a number or a string or anything you need. 1 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