~This is a Guide continued from Nome's Guide with a better explination and more stuff taught.~
Find a bug or wrong code please tell me and I will change.
Lesson 1
How to start a Npc
npc "map" "Name of Npc" npcspritename xpos ypos direction W H
Example: npc "prontera" "My Name" 4_f_job_hunter 103 143 4 5 5
Explination of what each thing means:
* npc - Delcares type of npc(npc, trader, guide, warp, mob) * "map" - You must enter the correct map name (ex. prontera, prt_fild01, moc_field04, etc...) * "name" - This is the name that appears under the NPC Sprite in game * spritename - This is where you delcate the sprite to use.(See Example) * xpos - This is the x postion on the map (the first number from the /where command) * ypos - This is the y postion on the map (the second number from the /where command) * dir - This declares the direction the npc will face (This is a number value of 0-7)(7 = UP 6 = UP + RIGHT, 5 = RIGHT, 4 = DOWN + RIGHT, 3 = DOWN, 2 = DOWN + LEFT, 1 = LEFT, 0 = UP + LEFT) * W - distance around the NPC that will activate it using the OnTouch: command(Thank you Ether) * H - Distance around the NPC that will activate it using the OnTouch: command(Thank you Ether)
Npc Sprite Names can be found here http://kalen.s79.xre.../npc/npce.shtml
Example Npc:
npc "prontera" "My Name" 4_f_job_hunter 103 153 2 5 5 OnClick: dialog "[Name]" dialog "Enter chat here" wait dialog "[Name]" dialog "Enter chat here" close
=====================================
Explination:
dialog
--- Tells the Npc what to do---
wait
--- Just type wait. Moves to the next screen---
close
--- Close the npc---
========================================================
Lesson 2
Now that we got through the very beginning stuff lets move into some more advanced stuff
Example Npc:
npc "prontera" "My Name" 4_f_job_hunter 103 153 2 5 5 OnClick: dialog "[My Name]" dialog "Hello would u like to go to Jawaii" wait choose menu "Yes" "No" case 1 dialog "[My Name]" dialog "That will cost you 500z" if v[VAR_MONEY] > 499 dialog "Thank you" dropgold 500 else dialog "[My Name]" dialog "Hmm don't see to have enough" endif close break case 2 dialog "[My Name]" dialog "Ok then good bye" close return break endchoose return
=======================================================
Explination:
if
if v[VAR_MONEY] > 499
--- This will check to make sure you meet the zeny requirement for the trip. Make sure you say 1z less then required so that you don't have to have more then zeny required---
Example:
--- if v[VAR_MONEY] > 299 will make it so they can check for 300---
else
--- This declares what will happen when the if statement is not met.---
endif
--- This ends the if - else statement---
choose menu
--- This shows the choices that the play has to choose from.---
Example:
choose menu "Option 1" "Option 2" "Option 3" "Option 4"
case #
case 1 --- Declares what will happen if you choose the first option---
case 2 --- Declares what will happen if you choose the second option---
break
--- Just type break, declares when the end of a case has been reached---
endchoose
--- Type by itself declares the end of the choose menu---
getgold
getgold 1000 --- Give the palyer money, number entered behind it is the amount given---
dropgold
dropgold 1000 --- Takes money from the player, number is ammount taken away---
getitem
getitem Jellopy 30 --- Gives item to the player, item's name, ammount to be given---
dropitem
dropitem Jellopy 30 --- Takes item from player, item's name, ammount to be taken---
=======================================================
Lesson 3
Now that we got use to some variables and case's lets add some more of both. Lets add some warps in there also =P I think your ready
Example Npc:
npc "prontera" "My Name" 4_f_job_hunter 103 153 2 5 5 OnClick: dialog "[My Name]" dialog "Welcome to Jawaii" dialog "The honeymoons island" wait dialog "[My Name]" dialog "What would you like to do?" while(1) choose menu "Warp back to Prontera" "Info on Island" "GoodBye" case 1 dialog "[My Name]" dialog "Have a safe trip" moveto "prontera" 138 208 close break case 2 dialog "[My Name]" dialog "This is the honeymooners Island only people who have recently gotten married should be here" dialog "Did you just get married?" while(1) choose menu "Yes" "No" case 1 dialog "[My Name]" dialog "Well then your ok to be here when you want a house just go to Bob and he will tell you how to rent one" close break case 2 dialog "[My Name]" dialog "Oooo well then you must leave right now" moveto "prontera" 138 208 close break endchoose case 3 dialog "[My Name]" dialog "Good bye" close break endchoose endwhile return
=======================================================
Explination:
while
while(1) --- This keeps a choose menu window open until canceled---
endwhile
endwhile --- Marks the end of the choose menu section to remain open---
exitwhile
exitwhile --- Continues script when window held open by while is closed.---
moveto
moveto --- Moves the player to that location specified.---
Example:
moveto "prontera" xpos ypos
=======================================================
Lesson 4
Now that we have learned how to warp and add more case's lets learn how to check for Gender and give exp and job exp.
Example Npc:
npc "prontera" "My Name" 4_f_job_hunter 103 153 2 5 5 OnClick: dialog "[Npc Name]" dialog "Welcome to New Training Grounds" dialog "Would you like to listen to the Basic Info of Ragnarok" wait choose menu "Yes" "No" case 1 dialog "[Npc Name]" dialog "Well Yada Yada Yada" wait dialog "[Npc Name]" dialog "Well thanks for listening here ya go for listening" giveexp 9232 dialog "and also here" getjexp 9234 close break case 2 dialog "[Npc Name]" dialog "Well then you seem like a smart" if v[VAR_SEX] == 1 dialog "[Npc Name]" dialog "boy. Maybe we will meet again" elseif v[VAR_SEX] == 0 dialog "[Npc Name]" dialog "young lady. Maybe we will meet again" endif dialog "Good Day" close break endchoose return
=======================================================
Explination:
giveexp
giveexp --- Gives that charcter that amount of exp.---
dropexp
dropexp --- Removes some of that charcters exp.---
givejexp
givejexp --- Gives that charcter that amount of job exp.---
dropjexp
dropjexp ---- Removes some of that charcters exp.----
if v[VAR_SEX] == 0
--- Checks for the charcters gender.---
(0 = Female, 1 = Male)
=======================================================
Lesson 5
Well sench we just learned how to warp and check gender lets learn how to Reset Stat and Skills. Also we are gonna learn how to heal hp or take away hp. Also on a note if you see something wrong in this script please just tell me don't be an ass and be like OMG YOU WERE WRONG ITS THIS AND YA.
Thanks
Example Npc:
npc "prontera" "My Name" 4_f_job_hunter 103 153 2 5 5 OnClick: dialog "[Npc Name]" dialog "Welcome would you like to restart your stats/skills?" wait choose menu "Yes" "No" case 1 dialog "[Npc Name]" dialog "Well then choose which one" while(1) choose menu "Reset Skills" "Reset Stats" "Nevermind" case 1 dialog "[Npc Name]" dialog "Well that will be 250,000z" if v[VAR_MONEY] > 249999 dropgold 250000 dialog "[Npc Name]" dialog "Well then here ya go" ResetSkill else dialog "[Npc Name]" dialog "Well sorry you don't have enough zeny" endif close break case 2 dialog "[Npc Name]" dialog "Well that will be 250,000" if v[VAR_MONEY] > 249999 dropgold 250000 dialog "[Npc Name]" dialog "Here ya go" ResetStat else dialog "[Npc Name]" dialog "Not enough zeny" dialog "So take this" hpheal -85 endif close break case 3 close break endchoose endwhile return
=======================================================
Explination:
ResetSkill
--- Restarts that charcters skills.----
RestartStat
--- Restarts that charcters Stats.-----
hpheal <amount>
--- Heals the charcters hp that amount. You can either take hp or give hp(Give = 85, Take = -85)----
spheal <amount>
--- Heals the charcters sp that amount. You can either take or give sp(Give = 85, Take = -85)------
hpfullheal
--- Heals the charcters hp full.-------
spfullheal
--- Heals the charcters sp full.-------
=======================================================
Lesson 6
In this lesson we are gonna learn how to make a npc say a characters name along with give them skills =).
Example Npc:
npc "prontera" "Npc Name" 4_f_job_hunter 103 153 2 5 5 OnClick: dialog "[Npc Name]" dialog "+ PcName + How are you doing today" wait dialog "[Npc Name]" dialog "Thats great to hear." dialog "So what would you like to do?" wait choose menu "Get Skills" "Nevermind" case 1 dialog "[Npc Name]" dialog "Well then that will be 250,000" if v[VAR_MONEY] > 249999 dropgold 250000 dialog "Thank you" EventAddSkill CR_DEVOTION 0 EventAddSkill CR_GRANDCROSS 0 EventAddSkill CR_HOLYCROSS 0 EventAddSkill CR_REFLECTSHIELD 0 EventAddSkill CR_SHIELDBOOMERANG 0 else dialog "[Npc NAME]" dialog "Sorry not enough zeny" endif close break case 2 dialog "[Npc Name]" dialog "Wll then GoodBye" close break endchoose return
=======================================================
Explination:
+ PcName +
--- Has the npc say the charcters name.----
EventAddSkill
--- Add the Skill to that person.--------
EventDelSkill
--- Delete that skill from that person.---------
=======================================================
Lesson 7
Well we have been making great progress haven't we... In this lesson we are gonna learn how to check for Base Level, Job Level, Skill Points, and there Job. I would like to thank Bongun for helping me with this.
Example Npc:
npc "prontera" "Npc Name" 4_f_job_hunter 103 153 2 5 5 OnClick: if (v[VAR_JOB] == ARCHER) dialog "[Npc Name]" dialog "Would you like to change into a Hunter?" wait choose menu "Yes" "No" case 1 if (v[VAR_JOBLEVEL] > 39) if (v[VAR_CLEVEL] > 52) if (v[VAR_SPPOINT] > 0) dialog "[Npc Name]" dialog "Well then here ya go" jobchange HUNTER close endif break case 2 dialog "[Npv Name]" dialog "Im sorry then good day" close endchoose return
=======================================================
Explination:
if (v[VAR_JOBLEVEL] > 39)
--- This checks for the charcters job level. Make sure to put 1 less then the number you actually want.---
if (v[VAR_CLEVEL] > 52)
--- This checks for the charcters base level. Make sure it is one less then you actually want so it checks to see if the charcter is 53 or greater.---
if (v[VAR_JOB] == ARCHER)
--- This checks to see what job the charcter is.----
if (v[SPPOINT] > 0)
--- Checks to see if the charcter has used all of there skillpoints.---
=======================================================
Lesson 8(Checking on this use at risk)
In this lesson you won't really learn any new commands but I wanna teach you what is the difference between ==, !=, >, <. So ya here ya go =P.
Explination
== means equal to xy
!= not equal to
> greater then xy
< less then xy
=======================================================
Lesson 9 (By Kasuha Full Credit)
Aegis normally handles negative numbers.
var a = 40 var b = 80 var c = a - b dialog "" + c wait
Gives you "-40"
however, aegis compiler does not support unary minus. Therefore if you want to assign a negative number to a variable, you must do it this way:
var a = 0 - 40
break command is not really necessary.
choose menu "first" "second" case 1 dialog "one" case 2 dialog "two" endchoose wait
It compiles without a problem and if you choose "first" you get only "one" output, not "one \ two".
However I still think you should use breaks.
Non-displayable choices are just skipped
var a = "one" var b = 2 var c = "" var d = "four" choose menu a b c d case 1 dialog "first" break case 2 dialog "second" break case 3 dialog "third" break case 2 dialog "fourth" break endchoose wait
This presents you with menu containing just "one" and "four" and if you choose "four", you get "second" as output.
Warps can talk
warp <blahblahblah> OnTouch: dialog "Ouch! You stepped on me!" wait moveto <somewhere> return
Works as you'd expect - displays you the message and after clicking on 'next' moves you to the destination. I expect the same (though I didn't test it) for hidden warps.
Beware dialogs around moveto!
The moveto commands closes the dialog window and removes displayed image (e.g. Kafra image) and does not let the dialog window appear again.
dialog "something before" moveto <somewhere> dialog "something after" close return
This code does not display anything, though the close command remains active until it times out, preventing you to use other NPCs.
And one curiosity at the end - relative movement warp.
warp "jawaii" "test warp 1" 200 230 5 5 OnTouch: var x = v[VAR_CURXPOS] + 20 var y = v[VAR_CURYPOS] moveto "jawaii" x y return
This warp moves you exactly 20 tiles east. This ofcourse works for movements between maps so it can be used to avoid warping all people to the same point if they enter the warp at different points.
=======================================================
No Explination(Still learning this one also =P)
Thanks Again Kasuha
=======================================================
Lesson 10(By Kasuha Full Credits to him)
I have been experimenting with Aegis scripting recently and here are some of my findings. Let's call it "advanced do's and don'ts":
The choose construct does not work only with the menu - you can put variable into it, too:
choose v[VAR_SEX] case 0 dialog "You're a girl!" break case 1 dialog "You're a boy!" break endcase close
The break command is only usable on base level of the choose construct.
Correct:
choose <something> case 1 ... break endchoose
Wrong:
choose <something> case 1 if <condition> break <-- translation error here endif endchoose
The break command is not mandatory. Putting break after return is just a waste of a perfect text line.
The moveto command does not stop script execution, even if it moves the player to another map. If the execution flow meets some wait or close command then, it locks the script and prevents the player to use NPCs until the script times out.
Integer division is possible, for instance 27 / 7 = 3.
The menu function can be used out of the choose command, for instance var a = menu "jedna" "dva" is correct, it displays the menu and lets you select, however the a variable contains zero afterwards.
If you forget to put the last close to your script and then perform the return command, the close command is added implicitly.
Attempts to comment out several lines using the /* and */ comment marks do not work. The compiler just ignores the two lines and compiles everything between them. Generally the compiler is very tolerant to errors if it does not recognize a command on the line - such a line is just skipped.
Empty strings and numbers do not appear in the menu function. Example:
var a = "one" var b = "" var c = 1 var d = "four" choose menu a b c d
This lets you choose from two choices - one and four. However I am not really sure which case parts get executed.
=======================================================
No Explination(Still learning this also =P)
Thanks Again Kasuha
=======================================================
Lesson 11(Full Credit to Kasuha)
Another article, today about cmdothernpc command.
The cmdothernpc command is used to invoke an OnCommand: code block on another or the same NPC. However, they are not subroutine calls; they are treated as events. Each event is added to the NPC's event queue and as soon as the script execution ends, another event is taken form the queue and processed.
Example:
npc "jawaii" "Command Tester" 4W_KID 200 240 4 1 1 OnClick: strlocalvar 0 "myvalue" SetLocalVar "myvalue" 10 broadcastinmap "1" cmdothernpc "Command Tester" "one" broadcastinmap "2" cmdothernpc "Command Tester" "two" broadcastinmap "3" cmdothernpc "Command Tester" "three" broadcastinmap "4" cmdothernpc "Command Tester" "four" broadcastinmap "5" SetLocalVar "myvalue" 20 return OnCommand: "one" broadcastinmap "6" return OnCommand: "two" broadcastinmap "7" cmdothernpc "Command Tester" "five" broadcastinmap "8" return OnCommand: "three" broadcastinmap "9" return OnCommand: "four" broadcastinmap "10" return OnCommand: "five" broadcastinmap "11" broadcastinmap "Value = " + lv["myvalue"] return
This NPC produces a nice series of broadcasts:
Command Tester : 1 Command Tester : 2 Command Tester : 3 Command Tester : 4 Command Tester : 5 Command Tester : 6 Command Tester : 7 Command Tester : 8 Command Tester : 9 Command Tester : 10 Command Tester : 11 Command Tester : Value = 20
If they were actually subroutine calls, we would get the following output, but it doesn't happen:
Command Tester : 1 Command Tester : 6 Command Tester : 2 Command Tester : 7 Command Tester : 11 Command Tester : Value = 10 Command Tester : 8 Command Tester : 3 Command Tester : 9 Command Tester : 4 Command Tester : 10 Command Tester : 5
Also note that NPC's local variables declared through strlocalvar can be used to transfer values between NPC's code blocks.
Commands grouped together need to be used together.
=======================================================
Explination
Well he did it pretty well =P
=======================================================
**Exception: Else does not always need to be used with an if statement, however it cannot be used outside an if statement.
=======================================================
Lesson 12
Darn its been a while sence I updated this :blink: but I guess ill start work on it again so you guys will get smarter :o. Well lets see maybe today we should learn Strength,Vit,Agi,Dex upgrade :P.
Coming Soon!
=======================================================
Lesson 13(Another Lesson from Kasuha)
Wanna know how much any of your NPCs is used? Wanna know how many people go through a particular warp? Wanna know things that are not logged otherwise? Here is a simple solution:
npc "jawaii" "Spy" 4_M_02 195 240 0 0 0 OnClick: SavePPL 0 dialog "[Spy]" dialog "You have been reported." close return
=======================================================
The SavePPL command stores the current player location, time and the number specified in the command to the presentLog database table.
You can put a lot of useful information into the number specified in the command.
Installing a NPC Script(Full Credit to Nome)
Foreword
Since this question comes up and most likely will come up a bit more. I'll try to make an easy-to-use painless guide to getting your custom made NPCs into the game.
There are 2 ways you can do it.
Option 1
Get your NPC script
Go to zone/npcdata/npc/folder
Click on npc.sc
Add the new NPC script to the end of npc.sc
I suggest making a comment that lets you know what script it is when you go back to it.
Save the file
Close the file
Load up Zone Server
If you get a failed to compile npc.sc error
Close Zone
Go back to npc.sc
Look over your new script and make sure it's coded right
Dialog should have both quotes ""
if statements should use [ ] and not { }
Make sure you use the database names for items from itp.txt
Make sure your other variables match up to database names
Choose menu needs and Endchoose
If statements need endif
case statements need break
should always end an npc script with return
Option 2
**This is for those of you who plan to make more than 1 or 2 NPC
Have your NPC script ready in its own .sc file
Make a folder, name it whatever you want (for this guide I'll call it mynpc)
QUOTE
Make sure the folder is located in the zone/npcdata directory
Put the new .sc file into the folder mynpc
Go to zone/npcdata
Open the List.txt file
I suggest near the top, put:
CODE
// mynpc Data
./npcdata/mynpc/scriptfilename.sc
Save List.txt as a text file and close
Run Zone Server to see if it loads
If it fails, see trouble shooting list from Option 1
* mynpc can be replaced with whatever name you want
** you should keep scriptfilename relativly short (some long names don't work)
*** if you put the wrong file name in list.txt, your zone server will not start.
**** You can also check the nps.asm file if an error pops up. It shoudl give you the exact line that is erroneous. (Thanks guryushka)
Credits:
Who/What they did Nome -- For some of the Definitions & the explination parts at the beginning of the guide and Installing Npc Guide Aukeri -- Directions Bongun -- Variables Ether -- Variables Mass Zero -- Help
Changelog 10/15/05 ++Redid the Guide made it look a little better :O
This post has been edited by Nate: 01 December 2005 - 09:58 PM

Help











