2008年4月17日 星期四

如何自己新增NPC

Step 1. 首先要建立一個新的CPP-> cody.cpp

Step 2.在cody.cpp中,我們首先要插入下列這段程式碼

#include "NPCs.h"
#include "NPCsScripts.h"


3.我們接下來要著手比較困難的部分,我們必須在NPCsScripts中宣告一個void的function,如下

void NPCsScripts::npc_2100(NPC* npc){

}



現在也許你會擔心,我該如何取得npc_2100這代碼呢?
非常簡單,你可以到這網站尋找所有的NPC代碼

Step 4. 我們必須宣告state及map
state-> Current State
map-> Game map..

所以我們必須在下列這段程式碼這裡面

void NPCsScripts::npc_2100(NPC* npc){

}


新增這段程式碼

int state = npc->getState();
int map = npc->getPlayerMap();



所以看起來會像

void NPCsScripts::npc_2100(NPC* npc){
int state = npc->getState();
int map = npc->getPlayerMap();
}


Step5. 現在我們需要在我們的地圖上新增檢查

這段程式碼之後

int state = npc->getState();
int map = npc->getPlayerMap();


新增這段

if(npc->getPlayerMap() == 100000000){

}


也許你不知道地圖的代碼,所以可以到這查詢地圖代碼

Step6. 這裡可能會讓你造成困惑,但是在後面我會有更詳細的介紹,state[0]代表開始對話,state[1]代表選擇[是/否] (記住這邊只是範例而已!! 詳細的用法需要到程式碼中查詢)
接下來我們在

if(npc->getPlayerMap() == 100000000){

}

裡面新增

if(state == 0){

}


所以我們現在的程式碼看起來會像

void NPCsScripts::npc_2100(NPC* npc){
int state = npc->getState();
int map = npc->getPlayerMap();
if(npc->getPlayerMap() == 100000000){
if(state == 0){

}
}


這樣我們就完成啦!!

接下來我們只需要設定何時使用這個NPC就好了,接下來是實際新增NPC的例子


#include "NPCs.h"
#include "NPCsScripts.h"

void NPCsScripts::npc_2100(NPC* npc){
int state = npc->getState();
int map = npc->getPlayerMap();
if(npc->getPlayerMap() == 100000000){
if(state == 0){

npc->addText("");//Send Text For Cody To Output
npc->sendNext();//Just think of this to enable you to Click "next" button for continuing....
npc->addText("Good Bye");
npc->sendOK();//Think of this to Enable click "ok" before continuing...
npc->end();//You should know what this is.....Quit Talking to NPC...?

}
}


現在讓我們把NPC ID換成9200000


void NPCsScripts::npc_2100(NPC* npc)


換成

void NPCsScripts::npc_9200000(NPC* npc)


接著開啟NPCsScripts.h,你應該可以看到下列這兩段程式碼


switch(npcid){
case 2100: npc_2100(npc); break;
case 2101: npc_2101(npc); break;
case 2020005: npc_2020005(npc); break;
case 9101001: npc_9101001(npc); break;
case 9900000: npc_9900000(npc); break;
default: npc->end(); break;
}



private:
static void npc_2100(NPC* npc);
static void npc_2101(NPC* npc);
static void npc_2020005(NPC* npc);
static void npc_9101001(NPC* npc);
static void npc_9900000(NPC* npc);


將下列兩個程式碼加進去即可

static void npc_9200000(NPC* npc);



case 9900000: npc_9200000(npc); break;


這樣就完成啦! 非常簡單吧~ 只是過程瑣碎XD

底下是npc的一些指令


npc->addChar(char cha);
npc->addQuest(int QuestID);
npc->addText(char string);
npc->cend();
npc->end();
npc->endQuest();
npc->getItemNum(int itemid);
npc->getMesos();
npc->getNpcID();
npc->getnum();
npc->getNumber();
npc->getPlayer();
npc->getPlayerEyes();
npc->getPlayerHP();
npc->getPlayerMap();
npc->getSelected();
npc->getState();
npc->getState();
npc->getText();
npc->gettext();
npc->getVariable(char *name);
npc->giveEXP(int exp);
npc->giveItem(int itemid,short amount);
npc->giveMesos(int amount);
npc->isEnd();//bool
npc->isQuest();//bool
npc->isquest();
npc->isStart();//bool
npc->isstart();
npc->npcid();
npc->npcPacket(char type);
npc->player();//More to come....
npc->selected();
npc->sendAcceptDecline();
npc->sendBackNext();
npc->sendOK();
npc->sendBackOK();
npc->sendGetNumber(int def,int min,int max);
npc->sendGetText();
npc->sendOK();
npc->sendNext();
npc->sendSimple();
npc->sendStyle();
npc->sendYesNo();
npc->setGetNumber(int num);
npc->setGetText(char *text);
npc->setIsStart(bool what);
npc->setPlayerHP(short hp);
npc->setSelected(int selected);
npc->setState(int state);
npc->setStyle(int id);
npc->setVariable(char *name,int val);
npc->showShop();
npc->state();
npc->teleport(int mapid);
npc->text();
npc->vars();
npc->~NPC();


原文網址:http://forum.ragezone.com/f428/guide-scripting-your-npc-381658/

沒有留言: