mjau Posted July 21, 2011 Share Posted July 21, 2011 hi i tried to script a marker to warp me into my andromada i attached the marker to it but it says bad argument at addEventHandler heres my code where the wrong part is function warptheplayer ( player ) setElementInterior ( player, 9, 315.48, 984.13, 1959.11 ) end addEventHandler ( "onMarkerHit", arrowMarker, warptheplayer ) Link to comment
DarkLink Posted July 21, 2011 Share Posted July 21, 2011 hi i tried to script a marker to warp me into my andromada i attached the marker to it but it says bad argument at addEventHandlerheres my code where the wrong part is function warptheplayer ( player ) setElementInterior ( player, 9, 315.48, 984.13, 1959.11 ) end addEventHandler ( "onMarkerHit", arrowMarker, warptheplayer ) On marker hit event is trigger when u hit a marker, so arrowMarker is the marker that will trigger the event. It needs to be a marker declared on that script, dont know if it is. You dont need to attach a marker to andromada. You create a marker that will trigger the function that teleport. Simple Just make the marker where you want to teleport when you hit it, u can use createMarker I hope I could help . Link to comment
mjau Posted July 21, 2011 Author Share Posted July 21, 2011 function androint ( andro, commandName ) local arrowMarker = createMarker ( -1357.26953125, -76.0087890625, 14.146192550659, "arrow", .75, 255, 0, 0, 170 ) local andro = createVehicle ( 592, -1357.4599609375, -55.9248046875, 14.1484375 + 5 ) --Create a Andro attachElements ( arrowMarker, andro, 0, 0, 5 ) --Attach the marker to the adnro end addCommandHandler ( "hat", androint ) function warptheplayer ( player ) setElementInterior ( player, 9, 315.48, 984.13, 1959.11 ) end addEventHandler( "onMarkerHit", arrowMarker, warptheplayer )] this is the whole script i didnt understand waht you ment Link to comment
mjau Posted July 21, 2011 Author Share Posted July 21, 2011 and the reason i attached it is cuz i want them to be able to stand in my andromada Link to comment
mjau Posted July 22, 2011 Author Share Posted July 22, 2011 really need help wiht this Link to comment
AGENT_STEELMEAT Posted July 22, 2011 Share Posted July 22, 2011 The variable "arrowMarker" is local - so it can only be used within that function. to fix this, declare arrowMarker as local OUTSIDE of the function. Second, addCommandHandler passes at least 3 variables to the handler function as arguments (if this is serverside). I have added an example of this in your script. Also, the onMarkerHit passes two variables as arguments - the element that hit the marker, and whether or not the element is in the same dimension as the marker. I have added an example on how this works as well in your script. local arrowMarker function androint ( playerSource, commandName, arg1 ) --arg1 is just the first argument, more can be passed on. arrowMarker = createMarker ( -1357.26953125, -76.0087890625, 14.146192550659, "arrow", .75, 255, 0, 0, 170 ) local andro = createVehicle ( 592, -1357.4599609375, -55.9248046875, 19.1484375) --Create a Andro. No need to perform arithmetic on constants.. attachElements ( arrowMarker, andro, 0, 0, 5 ) --Attach the marker to the adnro end addCommandHandler ( "hat", androint ) function warptheplayer (hitElement, dimensionMatch) if dimensionMatch then --Straightfoward - if the dimensions match, then continue. setElementInterior(hitElement, 9, 315.48, 984.13, 1959.11 ) end end addEventHandler( "onMarkerHit", arrowMarker, warptheplayer ) Link to comment
DarkLink Posted July 22, 2011 Share Posted July 22, 2011 Ye john is right, your problem is on arrowMarker variable its local of the function, make it ousite, or use example of john that is global Good luck. Link to comment
AGENT_STEELMEAT Posted July 22, 2011 Share Posted July 22, 2011 my example doesn't make arrowMarker global - it just changes the scope of the variable. Link to comment
mjau Posted July 22, 2011 Author Share Posted July 22, 2011 Still i get bad argument at addeventhandler Link to comment
DarkLink Posted July 22, 2011 Share Posted July 22, 2011 my example doesn't make arrowMarker global - it just changes the scope of the variable. And that scope wont be global? I mean for all the files server side? Maybe I dont know this much too, need learning Link to comment
AGENT_STEELMEAT Posted July 22, 2011 Share Posted July 22, 2011 no, heres an example of how variable scoping works: globalVariable = "global" --A global variable available across all scripts local localVariable1 = "local" --A local variable only available in this script (the SCOPE here is the entire script) function testFunction() --A global function local localVariable3 = "local" --A local variable only available in this function end local function testFunction2() --A local function only available in this script return end As for you, kimmis, try this: local arrowMarker function warptheplayer (hitElement, dimensionMatch) if dimensionMatch then --Straightfoward - if the dimensions match, then continue. setElementInterior(hitElement, 9, 315.48, 984.13, 1959.11 ) end end function androint ( playerSource, commandName, arg1 ) --arg1 is just the first argument, more can be passed on. arrowMarker = createMarker ( -1357.26953125, -76.0087890625, 14.146192550659, "arrow", .75, 255, 0, 0, 170 ) local andro = createVehicle ( 592, -1357.4599609375, -55.9248046875, 19.1484375) --Create a Andro. No need to perform arithmetic on constants.. attachElements ( arrowMarker, andro, 0, 0, 5 ) --Attach the marker to the adnro addEventHandler( "onMarkerHit", arrowMarker, warptheplayer ) end addCommandHandler ( "hat", androint ) Link to comment
mjau Posted July 22, 2011 Author Share Posted July 22, 2011 no errors but nothing happens when i enetr the marker Link to comment
mjau Posted July 22, 2011 Author Share Posted July 22, 2011 srry for being impatient but it is a bit important Link to comment
mjau Posted July 22, 2011 Author Share Posted July 22, 2011 HELP omg im getting nerves i cant finish this before its to late Link to comment
Johnniey Posted July 22, 2011 Share Posted July 22, 2011 I usually use this: local markername1 = createMarker( 3719.865234375, -3209.11328125, 3.5984575748444, "corona", 3, 0, 255, 0, 255) function masterfunction (player) if source == markername1 then Scripts on markerhit here end end addEventHandler("onClientMarkerHit", getRootElement(), masterfunction) Link to comment
AGENT_STEELMEAT Posted July 23, 2011 Share Posted July 23, 2011 Why would you attach the handler to the root element when you only care about the single marker? kimmis - post any error you are getting. Link to comment
Castillo Posted July 23, 2011 Share Posted July 23, 2011 John, check his marker variable name: markername1, maybe he's going to add more? ex: markername2, markername3, etc, etc. Link to comment
Johnniey Posted July 23, 2011 Share Posted July 23, 2011 Thats why i use this one: local markername1 = createMarker( 0, 0, 0, "corona", 3, 0, 255, 0, 255) local markername2 = createMarker( 1, 1, 1 "corona", 3, 0, 255, 0, 255) function masterfunction (player) if source == markername1 then Scripts on markerhit markername1 here end if source == markername2 then Scripts on markerhit markernam2 here end end addEventHandler("onClientMarkerHit", getRootElement(), masterfunction) Link to comment
AGENT_STEELMEAT Posted July 23, 2011 Share Posted July 23, 2011 Well, if you have a bunch of markers of the same function, it would be cleaner to do: local titsMarkerRoot = createElement("markerRoot", "titsMarkerRoot") --A parent element for all markers that output "TITS" when entered local assMarkerRoot = createElement("markerRoot", "assMarkerRoot") --A parent element for all markers that output "ASS" when entered local titsMarker1 = createMarker( 0, 0, 0, "corona", 3, 0, 255, 0, 255) local titsMarker2 = createMarker( 1, 1, 1, "corona", 3, 0, 255, 0, 255) setElementParent(titsMarker1, titsMarkerRoot) setElementParent(titsMarker2, titsMarkerRoot) local assMarker1 = createMarker( 2, 2, 2, "corona", 3, 0, 255, 0, 255) local assMarker2 = createMarker( 0, 0, 0, "corona", 3, 0, 255, 0, 255) setElementParent(assMarker1, assMarkerRoot) setElementParent(assMarker2, assMarkerRoot) function markerHit(hitElement, dimensionMatch) --Note the dimension match - which is true if the player and the marker are in the same dimension if not dimensionMatch then return false end local parent = getElementParent(source) if parent == titsMarkerRoot then outputChatBox("TITS") return true --Don't forget to RETURN, to end execution of the function elseif parent == assMarkerRoot then outputChatBox("ASS") return true else outputChatBoc("ASS AND TITTIES!") return true end end addEventHandler("onMarkerHit", root, markerHit) Also - you should be RETURNING some value (whether it be true, false, or nil (nothing)). Once you do what you want to do for that marker, there's no need to continue execution. Another thing: you should only bother to execute the function if the dimensions match (in most cases). Link to comment
SDK Posted July 23, 2011 Share Posted July 23, 2011 That's all nice, but his script won't work, since you can't use markerhits when the marker is attached to something afaik. Link to comment
AGENT_STEELMEAT Posted July 23, 2011 Share Posted July 23, 2011 Ohh shit I didn't notice his post about it not working. If that's the problem then, using a colshape would be better then, and should work. Link to comment
mjau Posted July 23, 2011 Author Share Posted July 23, 2011 can u make the colshape part please just make it at the coords where i created the marker Link to comment
mjau Posted July 23, 2011 Author Share Posted July 23, 2011 how to do it with colshape waht i want is i enter the andro at the back of it and get in the andro interior and when i go out again i will be placed at the back of the andro anyway where it is even if it is midair cuz thats what i need i need it for paragliding tests 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