Construct a script engine using C language (1)
Author: kevin_qing
Please note
Requirements:
Implement the NPC logic and interact with the game (server.
For example, if you want to open a window with the merchant NPC
Design:
After referring to the legendary 2 server-side script (poor implementation), the script rules are defined as follows:
1. C language is used, because many people are familiar with C, and C syntax is more rigorous and easy to use
2. Data Types only support int and const string (parameters or return values for external functions). variables can only be int and do not need to be declared.
3. The supported syntax is function call (external), if-[else], switch-case, Goto, and only one main () function can be defined.
External function return value
4. Considering the efficiency, the script is compiled and executed in the VM.
Example:
Main (){
Say ("Hello, ^ 1% s ^ 0 I am here to provide you with a variety of quality services/N"
"Such as red name, job transfer, buy baby, drugs, and so on ...... And so on/N"
"If ^ 1% s ^ 0 are you sure you need the service, please go to select the required service/N"
"<SELECT> allow <forget it>", username (), username ());
Switch (wait (0 )){
1 :{
Say ("<transfer> quit <drug> quit <beauty>/N ");
Switch (wait (0 )){
1: {// Transfer
If (JOB () = 0) // warrior
{
Say ("are you tired of blood and fire as a warrior? /N"
"Transferred to <wizards> <monks>/N ");
Switch (wait (0 )){
1:
2:
}
} Else //........
//.........
}
//.......
}
}
2:
Return;
}
}
Explanation:
The above script uses two external function calls
The say () parameter is the same as that of printf (). ^ 1 ^ 0 in the string changes the font color, and <> the content in the string is optional (like the link in HTML)
Wait () is a waiting event. 0 is currently the event selected by the user.
Main (){
Say ("Hello, ^ 1% s ^ 0 I am here to provide you with a variety of quality services/N"
"Such as red name, job transfer, buy baby, drugs, and so on ...... And so on/N"
"If ^ 1% s ^ 0 are you sure you need the service, please go to select the required service/N"
"<SELECT> allow <forget it>", username (), username ());
Switch (wait (0 )){
1 :{
Say ("<transfer> quit <drug> quit <beauty>/N ");
Switch (wait (0 )){
1: {// Transfer
If (JOB () = 0) // warrior
{
Say ("are you tired of blood and fire as a warrior? /N"
"Transferred to <wizards> <monks>/N ");
Switch (wait (0 )){
1:
2:
}
} Else //........
//.........
}
//.......
}
}
2:
Return;
}
}
Explanation:
The above script uses two external function calls
The say () parameter is the same as that of printf (). ^ 1 ^ 0 in the string changes the font color, and <> the content in the string is optional (like the link in HTML)
Wait () is a waiting event. 0 is currently the event selected by the user.