Thread Tools Display Modes
10-13-12, 08:39 AM   #1
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
An event to take place when entering Vehicles?

Hi, I want to create an event that when a player enters a vehicle something happens. In this case I want to hide two action bars using bartender. I have that part covered but I want to find an event for this to work but I am having difficulties.

Could anyone help me out with this? Thank you for your time!
  Reply With Quote
10-13-12, 09:07 AM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,935
You could try http://wowprogramming.com/docs/event...TERING_VEHICLE.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
10-13-12, 10:20 AM   #3
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Thank you, that was what I needed
  Reply With Quote
10-13-12, 11:37 AM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Or you could just put

[vehicleui]hide;show

in the macro conditionals section for each bar in Bartender.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
10-19-12, 03:08 PM   #5
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Having a real problem with this. When I use:
self:RegisterEvent("UNIT_ENTERING_VEHICLE")

it works but not just for the player but for the target too since I noticed the bars were disappearing on their own whether or not I was in a vehicle.

I changed it to

self:RegisterEvent("PLAYER_ENTERING_VEHICLE")

but nothing works at all. No idea why.
  Reply With Quote
10-19-12, 03:24 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
That's because there is no PLAYER_ENTERING_VEHICLE event.

If you only want to respond to the event when it's the player entering a vehicle, use frame:RegisterUnitEvent("UNIT_ENTERING_VEHICLE"[b], "player"]) instead of frame:RegisterEvent("UNIT_ENTERING_VEHICLE") so that your frame only receives the event when it fires for the player unit.

If you want to respond to the event for other units, but in different ways, add code to your frame's event handler to check the first argument passed with the event to see which unit the event fired for:

Code:
frame:SetScript("OnEvent", function(self, event, unit)
    if event == "UNIT_ENTERING_VEHICLE" then
        if unit == "player" then
            print("You are entering a vehicle.")
        else
            -- Anyone else.
            print((UnitName(unit)), "is entering a vehicle")
        end
    elseif event == "UNIT_EXITED_VEHICLE" then
        if unit == "player" then
            print("You left a vehicle.")
        else
            -- Anyone else.
            print((UnitName(unit)), "left a vehicle")
        end
    end
end
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
10-19-12, 03:34 PM   #7
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Thank you, I will try that out. I would have thought of this sooner but I am using KgPanels for this script and I thought it works a little differently and it is really confusing me. This is because I have to place the script in a GUI OnEvent page so I did not think it was necessary to state that it was an OnEvent script.
  Reply With Quote
10-19-12, 03:40 PM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
It's not; for kgPanels, you can either (still) use RegisterUnitEvent instead of RegisterEvent in the panel's OnLoad code box, or you can just copy everything inside the OnEvent script function I posted above into the panel's OnEvent code box. You don't need the SetScript and function() .. end parts in kgPanels.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
10-19-12, 04:10 PM   #9
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
I've tried this for the OnEvent Panel:

Code:
if event == "UNIT_ENTERING_VEHICLE" then
    if unit == "player" then

-- Do stuff	
	
    end
elseif event == "UNIT_EXITED_VEHICLE" then
    if unit == "player" then

-- Do other stuff	
	
    end
end
and tried having this in the OnLoad Panel as well as without it:
Code:
self:RegisterUnitEvent("UNIT_ENTERING_VEHICLE")
self:RegisterUnitEvent("UNIT_EXITING_VEHICLE")
But none of that worked. Did I miss understand? This is giving me a head ache lol.
  Reply With Quote
10-19-12, 04:37 PM   #10
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Don't use both RegisterUnitEvent and the if unit == "player" then check. Just use one or the other. If you use RegisterUnitEvent, your frame only receives events for the specified unit, so the argument passed will always be that unit, so there's no need to check it.

Though, it just occurred to me that with kgPanels, the event arguments are just named arg1, arg2, and so on, so you'd need to either change unit to arg1, or rename it by declaring local unit = arg1 in the OnEvent script.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
10-19-12, 04:53 PM   #11
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Nothing would work until I added:

Code:
local unit = arg1
and
Code:
if arg1 == "player" then
and now it appears to finally be working. That was all I needed to do it seems. Now to test it out in a bg. Thank you so much for your help. Could not have done that without you. KgPanels confuse me. Hopefully all works well, fingers crossed lol
  Reply With Quote
10-19-12, 05:43 PM   #12
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Again, one or the other. Pick one of these three:

Code:
ONLOAD:

self:RegisterUnitEvent("UNIT_ENTERING_VEHICLE", "player")
self:RegisterUnitEvent("UNIT_EXITING_VEHICLE", "player")

ONEVENT:

if event == "UNIT_ENTERING_VEHICLE" then
    -- Do stuff
elseif event == "UNIT_EXITED_VEHICLE" then
    -- Do other stuff
end
Code:
ONLOAD:

self:RegisterEvent("UNIT_ENTERING_VEHICLE")
self:RegisterEvent("UNIT_EXITING_VEHICLE")

ONEVENT:

if event == "UNIT_ENTERING_VEHICLE" then
    if arg1 == "player" then
        -- Do stuff
    end
elseif event == "UNIT_EXITED_VEHICLE" then
    if arg1 == "player" then
        -- Do other stuff
    end
end
Code:
ONLOAD:

self:RegisterEvent("UNIT_ENTERING_VEHICLE")
self:RegisterEvent("UNIT_EXITING_VEHICLE")

ONEVENT:

if event == "UNIT_ENTERING_VEHICLE" then
    local unit = arg1
    if unit == "player" then
        -- Do stuff
    end
elseif event == "UNIT_EXITED_VEHICLE" then
    local unit = arg1
    if unit == "player" then
        -- Do other stuff
    end
end
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » An event to take place when entering Vehicles?


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off