Chaos Project

RPG Maker => RPG Maker Scripts => Script Requests => Topic started by: Shek on December 02, 2013, 02:03:54 pm

Title: [Resolved!] *Assign Skill or Item to next available Hotkey*
Post by: Shek on December 02, 2013, 02:03:54 pm
This script will assign a skill_ID of your choice to a free hotkey (it won't overwrite any hotkeys that are already filled with skills)

This script call will assign a Skill to a hotkey:
for i in 1..10
if $game_player.skill_hotkeys[i%10] <= 0
if $game_player.item_hotkeys[i%10] <= 0
$game_player.skill_hotkeys[i%10] = Skill_ID #Enter your Skill ID here
break
end
end
end


This script call will assign an Item to a hotkey:
for i in 1..10
if $game_player.skill_hotkeys[i%10] <= 0
if $game_player.item_hotkeys[i%10] <= 0
$game_player.item_hotkeys[i%10] = Item_ID #Enter your Item ID here
break
end
end
end


Script by KK20 (edited by me.. yay)
Original Post:

I know how to assign a skill to a hotkey using this call:
$game_player.skill_hotkeys[Hotkey_Number] = Skill_ID

Is there a simple way to make it check all the hotkeys, find the first one that is free, and then assign a skill to that hotkey?
Title: Re: Request: *Assign Skill to next available Hotkey*
Post by: KK20 on December 02, 2013, 02:44:09 pm
Script call:

for i in 1..10
if $game_player.skill_hotkeys[i%10] <= 0
$game_player.skill_hotkeys[i%10] = SKILL_ID
break
end
end
Title: Re: Request: *Assign Skill to next available Hotkey*
Post by: Shek on December 02, 2013, 09:02:37 pm
This is such an elegant solution,
man I need to take the time to learn how to script.  It's hard for me to *think* in the way that a scripter/programmer thinks.

I used to use Qbasic back in the day, and in that language I would have solved this as:

FOR i = 1 to 10
IF $game_player.skill_hotkeys[i] = 0 THEN
$game_player.skill_hotkeys[i] = Skill_ID
BREAK
END IF
NEXT i


The thing that has me confused, is in the second line of your script, you use [i%10]
The script works great, but I don't understand why it needs the modulus operator (%).  Why couldn't you just use this script:

for i in 1..10
if $game_player.skill_hotkeys[i] <= 0
$game_player.skill_hotkeys[i] = SKILL_ID
break
end
end


I'm sure the answer is simple; but like I said, my brain doesn't work like a programmer's.
Title: Re: [Resolved] *Assign Skill to next available Hotkey*
Post by: Shek on December 03, 2013, 01:25:47 pm
Just discovered something about this script,
it will overwrite a hotkey slot of there is an Item placed there instead of a skill.

Hmmmmmmm...

Would this work?


for i in 1..10
if ($game_player.skill_hotkeys[i%10] <= 0 && $game_player.item_hotkeys[i%10] <= 0)
$game_player.skill_hotkeys[i%10] = SKILL_ID
break
end
end


Not sure if this is the right syntax...
Title: Re: [Resolved] *Assign Skill to next available Hotkey*
Post by: KK20 on December 03, 2013, 04:07:13 pm
That syntax looks fine.

The i%10 is actually really obvious. Take a look at your number row. Notice how it starts with 1 and ends with 0? If I just did i, the last number that would be iterated is 10. There is no such thing as a 10 key. And if I did it like this:

for i in 0..9
if $game_player.skill_hotkeys[i] <= 0
$game_player.skill_hotkeys[i] = SKILL_ID
break
end
end

The first number iterated would be 0...which is the right-most key. It's better if we start from the left key (1) and work our way to the right.
Title: Re: [Resolved] *Assign Skill to next available Hotkey*
Post by: Shek on December 03, 2013, 09:52:11 pm
This script:

for i in 1..10
if ($game_player.skill_hotkeys[i%10] <= 0 && $game_player.item_hotkeys[i%10] <= 0)
$game_player.skill_hotkeys[i%10] = SKILL_ID
break
end
end


Is giving me a syntax error :(

AHH!!! FIXED IT!

Okay posting the correction at the top. YAY! My first script.. (well modification of a smarter person's script).
Title: Re: [Resolved] *Assign Skill to next available Hotkey*
Post by: KK20 on December 04, 2013, 12:02:03 am
Script calls are picky as hell. As soon as your code wraps to the next line, you have to be careful with your syntax. Good work fixing it yourself. ;)
See? Scripting isn't so hard. Baby steps at a time.
Title: Re: [Resolved] *Assign Skill to next available Hotkey*
Post by: Shek on December 04, 2013, 01:15:43 am
Seems like the script still isn't working. 

The AddSkill to Hotkey script no longer overwrites an item hotkey, but it seems to overwrite skills ...

for i in 1..10
if $game_player.skill_hotkeys[i%10] && $game_player.item_hotkeys[i%10] <= 0
$game_player.skill_hotkeys[i%10] = Skill_ID #Enter your skill ID here
break
end
end


I think it has something to do with the "<= 0" part only being applying to $game_player.item, and not the left side of the expression with $game_player.skill...

Alas , I don't know if it's the way that it's rearranging the lines when I paste it into the Script Call box.  I thought this would work but I get a syntax error:

for i in 1..10
if ($game_player.skill_hotkeys[i%10] <= 0) && ($game_player.item_hotkeys[i%10] <= 0)
$game_player.skill_hotkeys[i%10] = Skill_ID #Enter your skill ID here
break
end
end