Thread Tools Display Modes
12-12-10, 09:38 AM   #1
weasoug
A Flamescale Wyrmkin
 
weasoug's Avatar
AddOn Author - Click to view addons
Join Date: May 2010
Posts: 127
Thumbs up Cancelform

Hey all, i wanted to update my mount code, so it was cancel the form im in say boomkin. to then mount. but i can work out this part. any hekp would be good.


Code:
    if CanCancelform() then 
        Cancelform()
        return
    end
__________________
wMmap :: Is a lightweight Minimap, with a sleek look & custom imagery.
wIn1 :: In one addon. and is very lightweight & simple to use.
wChat :: Is a lightweight chat mod.
wBroker :: Is A simple broker add-on.
wPetXPBar :: Is A simple lightweight Pet XP Bar.
wBuffs :: Is A simple Buffs Bar.
  Reply With Quote
12-12-10, 09:54 AM   #2
Nobgul
A Molten Giant
 
Nobgul's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 693
Originally Posted by weasoug View Post
Hey all, i wanted to update my mount code, so it was cancel the form im in say boomkin. to then mount. but i can work out this part. any hekp would be good.


Code:
    if CanCancelform() then 
        Cancelform()
        return
    end


CancelShapeshiftForm();

You will have to do a check to see if they are shape shifted to begin with.
GetShapeshiftFormInfo(index);

So something like.
lua Code:
  1. if GetShapeshiftFormInfo(5) == true then
  2. CancelShapeshiftForm() else
  3. end
  4. end

incidently the 5 in the get shapeshiftform refers to boomkin. there is a list here. http://www.wowwiki.com/API_GetShapeshiftFormInfo
__________________
[SIGPIC][/SIGPIC]

Last edited by Nobgul : 12-12-10 at 10:01 AM.
  Reply With Quote
12-12-10, 10:32 AM   #3
weasoug
A Flamescale Wyrmkin
 
weasoug's Avatar
AddOn Author - Click to view addons
Join Date: May 2010
Posts: 127
ok i still cant seem to get it to work. maybe if i post all the code it will help.

Code:
function Mountz(groundmount, flyingmount, underwatermount)
    local num = GetNumCompanions("MOUNT")
    if GetShapeshiftFormInfo(5) == true then
        CancelShapeshiftForm() else
    end
    if not num or IsMounted() then
        Dismount()
        return
    end
    if CanExitVehicle() then 
        VehicleExit()
        return
    end
	local swimablex = IsSwimming()
	local v = GetBuildInfo()
    local flyablex 
	flyablex = IsFlyableArea()
    if IsControlKeyDown() then
        flyablex = not flyablex
    end
	if IsShiftKeyDown() then
        swimablex = not swimablex
    end
    for i=1, num, 1 do
        local _, info = GetCompanionInfo("MOUNT", i)
        if flyingmount and info == flyingmount and flyablex and not swimablex then
            CallCompanion("MOUNT", i)
            return
        elseif groundmount and info == groundmount and not flyablex and not swimablex then
            CallCompanion("MOUNT", i)
            return
		elseif underwatermount and info == underwatermount and swimablex then
			CallCompanion("MOUNT", i)
            return
        end
    end
end
--/run if GetShapeshiftFormInfo(5) == true then CancelShapeshiftForm() else end;if CanExitVehicle()then VehicleExit()return end;z=GetCurrentMapContinent()l=UnitLevel("player")if not(IsMounted())then M=3;if(IsFlyableArea()and(z==4 and l>67)or(z==3 and l>59))then M=12 end CallCompanion("mount",M)end /dismount
__________________
wMmap :: Is a lightweight Minimap, with a sleek look & custom imagery.
wIn1 :: In one addon. and is very lightweight & simple to use.
wChat :: Is a lightweight chat mod.
wBroker :: Is A simple broker add-on.
wPetXPBar :: Is A simple lightweight Pet XP Bar.
wBuffs :: Is A simple Buffs Bar.
  Reply With Quote
12-12-10, 10:57 AM   #4
Nobgul
A Molten Giant
 
Nobgul's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 693
You need to register a event, and then create a function to check it. Something like


addonname:RegisterEvent("EVENT_TO_LISTEN_FOR")

once you have the event registered then you can call your function

function:EVENT_TO_LISTEN_FOR()
if GetShapeshiftFormInfo(5) == true then
CancelShapeshiftForm() else
end


Now my syntax may be off and i cant think of what to listen for atm but thats what you would need. something that isn't always triggered i guess you could register for a button press down or soemthing.
__________________
[SIGPIC][/SIGPIC]
  Reply With Quote
12-13-10, 05:58 AM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
1. Why would he need to register an event when his goal is a function that will be called on-demand through user interaction?

2. Your syntax is really off. function:EVENT_TO_LISTEN_FOR() is not valid code, the dummy event name aside. >_<

Code:
    if GetShapeshiftFormInfo(5) == true then
        CancelShapeshiftForm() else
    end
3. The first value returned by GetShapeshiftFormInfo is a string containing the file path to the icon, for existing forms, or nil for nonexistent form indices. Neither of those are equivalent to true. The value you're looking for is the third returned value, and it returns 1/0, not a boolean, so:

Code:
if select(3, GetShapeshiftFormInfo(5)) == 1 then
4. Even if you correct that error, your code will only unshift for druids in Flight Form (or Moonkin/Tree for low-level druids who haven't learned Flight yet). If you wanted to check if any form was active, you have several options:

4a. Loop through all possible forms and check each one:

Code:
for i = 1, GetNumShapeshiftForms() do
    if select(3, GetShapeshiftFormInfo(i)) == 1 then
        -- form is active, do something
    end
end
4b. Use a different function, such as GetShapeshiftForm:

Code:
if GetShapeshiftForm() > 0 then
    -- form is active, do something
end
5. The biggest problem, however, is not with your code at all, but with the fact that CancelShapeshiftForm is a protected function and cannot be called by addons. The closest you'd be able to get would be by calling your function from a macro:

Code:
/run Mountz("Gray Kodo", "Tawny Wind Rider", "Abyssal Seahorse")
/cancelform
Also, the rest of your code can be simplified to:
Code:
function Mountz(groundmount, flyingmount, underwatermount)
	if GetShapeshiftForm() > 0 then
		return
	elseif CanExitVehicle() then
		return VehicleExit()
	elseif IsMounted() then
		return Dismount()
	end

	local flyable = IsFlyableArea() and not IsControlKeyDown()
	local swimmable = IsSwimming() and not IsShiftKeyDown()

	for i = 1, GetNumCompanions("MOUNT") do
		local _, name = GetCompanionInfo("MOUNT", i)
		if ( name == flyingmount and flyable and not swimmable ) or ( name == groundmount and not flyable and not swimmable ) or ( name == underwatermount and swimmable ) then
			return CallCompanion("MOUNT", i)
		end
	end
end

Last edited by Phanx : 12-14-10 at 01:48 AM.
  Reply With Quote
12-13-10, 06:49 AM   #6
weasoug
A Flamescale Wyrmkin
 
weasoug's Avatar
AddOn Author - Click to view addons
Join Date: May 2010
Posts: 127
Thumbs up

thanks so much Phanx. and i was thinknig last night before i had seen this. is to just add /cancelform. thank you very much on updating the mount code for me. very welcome.
__________________
wMmap :: Is a lightweight Minimap, with a sleek look & custom imagery.
wIn1 :: In one addon. and is very lightweight & simple to use.
wChat :: Is a lightweight chat mod.
wBroker :: Is A simple broker add-on.
wPetXPBar :: Is A simple lightweight Pet XP Bar.
wBuffs :: Is A simple Buffs Bar.
  Reply With Quote
12-13-10, 09:36 AM   #7
Nobgul
A Molten Giant
 
Nobgul's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 693
after being awake for 3 days cause my boss went on vacation my brain became scrambled eggs. >_<
__________________
[SIGPIC][/SIGPIC]
  Reply With Quote
12-13-10, 11:50 AM   #8
weasoug
A Flamescale Wyrmkin
 
weasoug's Avatar
AddOn Author - Click to view addons
Join Date: May 2010
Posts: 127
Wink

Originally Posted by nobgul View Post
after being awake for 3 days cause my boss went on vacation my brain became scrambled eggs. >_<
well have a few days off and play wow. hehe
__________________
wMmap :: Is a lightweight Minimap, with a sleek look & custom imagery.
wIn1 :: In one addon. and is very lightweight & simple to use.
wChat :: Is a lightweight chat mod.
wBroker :: Is A simple broker add-on.
wPetXPBar :: Is A simple lightweight Pet XP Bar.
wBuffs :: Is A simple Buffs Bar.
  Reply With Quote
01-28-11, 04:43 AM   #9
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by weasoug
i wanted to edit it. so sted of people putting in the mount name. and put the mount number. i tryed all types of ways i can think off. but nothing works.

I knnow its todo with the local name. and the use of name in the main part of the code. i have messed about with changing GetNumCompanions.

any help would be great thanks.
I'm not sure which "mount number" you're referring to, so here are examples for all three possible numbers. Replace the for-loop with this:

For mount index:
Code:
if ( flyable and not swimmable ) then
	return CallCompanion("MOUNT", flyingmount)
elseif ( not flyable and not swimmable )
	return CallCompanion("MOUNT", groundmount)
elseif ( swimmable ) then
	return CallCompanion("MOUNT", underwatermount)
end
For mount ID:
Code:
for i = 1, GetNumCompanions("MOUNT") do
	local id = GetCompanionInfo("MOUNT", i)
	if ( id == flyingmount and flyable and not swimmable ) or ( id == groundmount and not flyable and not swimmable ) or ( id == underwatermount and swimmable ) then
		return CallCompanion("MOUNT", i)
	end
end
For mount spell ID:
Code:
for i = 1, GetNumCompanions("MOUNT") do
	local _, _, spellID = GetCompanionInfo("MOUNT", i)
	if ( spellID == flyingmount and flyable and not swimmable ) or ( spellID == groundmount and not flyable and not swimmable ) or ( spellID == underwatermount and swimmable ) then
		return CallCompanion("MOUNT", i)
	end
end
  Reply With Quote
03-26-11, 09:00 AM   #10
weasoug
A Flamescale Wyrmkin
 
weasoug's Avatar
AddOn Author - Click to view addons
Join Date: May 2010
Posts: 127
Exclamation

im trying to add the number and name mount. no errors, but when set to false. nothing happens.'


Code:
local mountfalse			        = true
local mountnumbers                      = false
Code:
if mountfalse then
function Mountz(groundmount, flyingmount, underwatermount)
	if GetShapeshiftForm() > 0 then
		return
	elseif CanExitVehicle() then
		return VehicleExit()
	elseif IsMounted() then
		return Dismount()
	end

	local flyable = IsFlyableArea() and not IsControlKeyDown()
	local swimmable = IsSwimming() and not IsShiftKeyDown()

if mountnumbers then
        if ( flyable and not swimmable ) then
	      return CallCompanion("MOUNT", flyingmount)
        elseif ( not flyable and not swimmable )  then
	      return CallCompanion("MOUNT", groundmount)
        elseif ( swimmable ) then
	     return CallCompanion("MOUNT", underwatermount)
else
	for i = 1, GetNumCompanions("MOUNT") do
		local _, name = GetCompanionInfo("MOUNT", i)
		if ( name == flyingmount and flyable and not swimmable ) or ( name == groundmount and not flyable and not swimmable ) or ( name == underwatermount and swimmable ) then
			return CallCompanion("MOUNT", i)
                    end
		end
             end
         end
    end
end
__________________
wMmap :: Is a lightweight Minimap, with a sleek look & custom imagery.
wIn1 :: In one addon. and is very lightweight & simple to use.
wChat :: Is a lightweight chat mod.
wBroker :: Is A simple broker add-on.
wPetXPBar :: Is A simple lightweight Pet XP Bar.
wBuffs :: Is A simple Buffs Bar.
  Reply With Quote
03-27-11, 08:22 PM   #11
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
You have several glaringly obvious syntax errors in your second [code] block, and should be getting at least one Lua error in-game. Your "if mountfalse then" check is outside of your function, so if that variable is set, then the function isn't even defined. Also, it's missing an "end"... which should probably be an "elseif" preceding the "mountnumbers" check.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Cancelform


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