Script to add JP to a pet

09/23/2011 09:00 SilentBill#1
I'm currently working on something I thought would be handy.
With [Only registered and activated users can see links. Click Here To Register...], I'm modding a Respec potion into giving the selected creature extra JPs in addition to the respec. The problem is the 'selected creature' part. I've already gotten the pot to add JPs to the first creature in formation, or even to add them to all creatures in formation, but I don't want that effect, since it favors pet classes and I want to keep it as fair as possible.

So, I come requesting some help. Anyone know the command to get the selected creature's handle in LUA?:confused:

Oh, and before I forget, i know it can easily be done via SQL, but I want this to be done in-game, without bothering the GMs.
09/23/2011 10:30 RoflcopterGoesSoiSoiSoi#2
Quickly read over this, but I'd do some extensive looking in the breeder LUA script. It recursively lists the pets and selects one based on an ID. I'd assume you could BS your way through it and get it to work without errors.
09/24/2011 09:27 SilentBill#3
Yeah, from going through the breeder script, I got the functions to get the creature handle and could easily infer how to add the JPs, no problem there. Thing is, the breeder doesn't care what pet you have selected, it cycles through your formation.
Therefore, I still don't know how to get the handle of the selected creature, which is needed as a parameter to add the JPs.
I've tried getting it from the 'main_summon' parameter/column/thingie and it seems to work, as long as it's the first one in formation, but then if you unsummon that one, and try the respec again on another pet, the first one in formation is the one that gets the bonus, not the selected one.
10/10/2011 04:18 SilentBill#4
I'd like to thank Kale as he was the only one who expressed any interest in actually helping.
In any case, I never did figure out how to get that damn handle, so I decided, fuck it, and just gave an NPC JP manipulation powers.
For the following, I'm gonna be as blunt as possible, if you can't get this to work, then maybe you shouldn't be messing with scripts at all. Moving on...
You need to add this to your favorite NPC's contact script
Code:
dlg_menu("[Insert menu item here]", "CreatureBuyJPMenu()")
And this is the actual function, it's probably crude as hell, but whatever, this is my first real foray with LUA.
Code:
	--========================================================================
	--             <<<<<< 4. Extra: Buy JPs for your pet with your own >>>>>>
	--========================================================================

function CreatureBuyJPMenu()
	local npc_id = get_npc_id()

	if npc_id == 7001 then --I gave it to the HV Breeder, so that's what this is for
		if is_premium() == false then
			return false
		end

		dlg_title("@90700100")
	end
	dlg_text_without_quest_menu("[Insert witty dialog here]")
	for i = 0, 5 do


		handle = 0
		handle = get_creature_handle( i )

		if handle ~= 0 and handle ~= nil then

			lv = get_creature_value( handle, "level" )
			petJp=get_creature_value( handle, "jp" )

			text = sconv("@90010009", "#@creature_name@#",tostring(get_creature_value( handle, "name" )) ,"#@creature_level@#",tostring(lv))

			command = 'Creature_Buy_JPS( ' .. handle .. ' )'

			dlg_menu( text, command )

		end
	end
	dlg_menu( "[Insert no thanks option here]", "" )

end

function Creature_Buy_JPS( handle )


			playerJPs = get_value("jp")
			petJp= get_creature_value( handle, "jp" )

	if playerJPs>=20000000 then --that is 20m JPs
		set_creature_value(handle, "jp", petJp+1)
		sv("jp", playerJPs-20000000)

	else
		dlg_title("@90700100")
		dlg_text("[Insert GTFO response here]")
		dlg_menu("[Insert player GTFO option here]", "")
        dlg_show()
	end
end
So, basically, it's a script that trades a character's JPs for one pet JP. I made it so 20m transform into 1, but up to you what value you wanna put in there. So there you go, no thanks to any one of you, it's working ;)