Jump to content

addEventHandler fail


mjau

Recommended Posts

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
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 ) 

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
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 xD

Link to comment

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

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

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

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

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

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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...