Adding spells♪

Post Reply
Saraneth
Posts: 19
Joined: Sun Sep 02, 2012 2:15 am

Adding spells♪

Post by Saraneth » Thu Oct 25, 2012 8:27 am

Quick Edit-- I am so sorry if this is in the wrong place><;

Out of curiosity, I was wondering how one would go about adding say... spells 1-287 automatically to every character. (I have a long winded reason for wanting to do this, but it's nearly 6:30am ; ; haha or I'd totally try to explain!)

I'm not very good with scripting, hell I know nothing of scripting lol but I did dig up on the old site a script for adding all maps to each new character:

Code: Select all

-- ADD ALL MAPS
       		-- MAIN NATIONS SANDY BASTOK WINDURST JEUNO
       		player:addKeyItem(385);
      		player:addKeyItem(386);
       		player:addKeyItem(387);
       		player:addKeyItem(388);
       
       -- ITEMS 389 to 447
       z = 389;
       while z <= 447 do
          player:addKeyItem(z);
          z = z + 1;
       end


end;
Now, I'm very curious if it was rigged up for spells, if that same scripting would work? (This next script is probably wrong, but I am gonna show you just to get my idea across D: haha)

Code: Select all

-- ADD ALL SPELLS
       		-- BLACK WHITE
       		player:addSpell(1);
      		player:addSpell(2);
       		player:addSpell(3);
       		player:addSpell(4);
       
       -- ITEMS 1 to 297
       z = 5;
       while z <= 287 do
          player:addSpell(z);
          z = z + 1;
       end


end;
If anyone knows how I could get something like this to work, I would be most grateful!

Thank you so much for your time and all your guys' hard work!

Saraneth
Posts: 19
Joined: Sun Sep 02, 2012 2:15 am

Re: Adding spells♪

Post by Saraneth » Thu Oct 25, 2012 8:50 am

I guess I answered my own question with a little tweaking @_@;, remove the last end; and it works!
I really should learn more scripting D: haha.


Thanks for your time guys^^b and thank you to the person who submitted the original map script, it's come in really handy!

User avatar
kjLotus
Special Guest
Posts: 1813
Joined: Sun Jul 22, 2012 2:16 pm

Re: Adding spells♪

Post by kjLotus » Thu Oct 25, 2012 2:31 pm

Answered your question via telepathic channeling of answer.

My work here is done!

Any further questions have a high possibility of being answered.

PrBlahBlahtson
Developer
Posts: 539
Joined: Sun Jul 22, 2012 12:17 am

Re: Adding spells♪

Post by PrBlahBlahtson » Thu Oct 25, 2012 3:09 pm

To make it automatic, there's a character creation section in /scripts/globals/server.lua, in case you don't want to modify NPCs :)

bluekirby0
Developer
Posts: 707
Joined: Sun Jul 22, 2012 12:11 am

Re: Adding spells♪

Post by bluekirby0 » Thu Oct 25, 2012 5:10 pm

I would have used a for loop...hate using while loops when I don't have to because if you miss you can create an infinite loop.

Saraneth
Posts: 19
Joined: Sun Sep 02, 2012 2:15 am

Re: Adding spells♪

Post by Saraneth » Thu Oct 25, 2012 7:36 pm

@PR- I've stashed this script in scripts/globals/server.lua right under where I slid in the map script so now it does it all right off the bat for me and is easy for me to remove if needed^^;;

@KJ: Thank you! The script-Fu is strong with you! haha XD

@Bluekirby: I'm still learning so I'm not sure what a loop is^^:, I don't even really understand the script I posted to the full extent ;;, I'm trying to teach myself though so maybe I can contribute in the future^^

Thanks guys for your time, have a wonderful day!!

User avatar
whasf
Site Admin
Posts: 1312
Joined: Thu Jul 19, 2012 9:11 pm

Re: Adding spells♪

Post by whasf » Thu Oct 25, 2012 8:54 pm

I think you used up your emoticons for the rest of the month
-- Whasf

bluekirby0
Developer
Posts: 707
Joined: Sun Jul 22, 2012 12:11 am

Re: Adding spells♪

Post by bluekirby0 » Thu Oct 25, 2012 10:05 pm

This is a while loop:

Code: Select all

       z = 5;
       while z <= 287 do
          player:addSpell(z);
          z = z + 1;
       end
It is called a loop because you use a few lines of code to perform a similar action several times until the exit conditions are met (in this case, the exit condition is that z > 287). If you were to, say, forget the last line, then the exit condition could never possibly be met, and thus you create an infinite loop.

A for loop mostly guarantees that an exit condition will be reached eventually. There are some exceptions to this, but they are much harder errors to make than what you can do to mess up a while loop. The same functionality as above in a for loop would be:

Code: Select all

       for local z=5, 287 do
          player:addSpell(z);
       end
Above z is automatically augmented by 1 each time the loop is executed until the exit condition (z = 287) is reached. You can also specify how much z is augmented by or specify a decrement instead by passing a third parameter to the for loop.

Code: Select all

       for local z=5, 287, 2 do
          player:addSpell(z);
       end
The above would add every odd spell between 5 and 287 instead of every spell. Notice I also use local before z to guarantee that z goes out-of-scope once the loop is done so its resources are freed and it is safe to use elsewhere.

Saraneth
Posts: 19
Joined: Sun Sep 02, 2012 2:15 am

Re: Adding spells♪

Post by Saraneth » Fri Oct 26, 2012 3:12 am

Haha, I'm sorry Whasf, it's a bad habit @_@;!

And thanks Bluekirby! That makes lots of sense now^^!!

You're all so awesome, thanks so much for your time♪

bluekirby0
Developer
Posts: 707
Joined: Sun Jul 22, 2012 12:11 am

Re: Adding spells♪

Post by bluekirby0 » Sat Oct 27, 2012 2:42 am

No problem. Glad to help people who are willing to learn :D

Post Reply