- Dołączył
- Czerwiec 9, 2014
- Posty
- 123
- Liczba reakcji
- 5
Witam.
Skompilowa?em sobie silnik Devland 0.97 jako baz? pod Wodbo ots. Skopiowa?em najprostszy npc Yama i wywala mi b??d (tak jest z ka?dym npc)
Umiem sobie z nim poradzi? ?eby b??d nie wyskakiwa? ale zastanawiam si? czy nie jest to niepotrzebne obci??anie silnika, i czy kod jest dobrze napisany.
Gdy skopiuj? npc z oryginalnego Deva jest ok. Skrypt lua si? nieco r??ni, ale te? wygl?da mi na ?le zoptymalizowany.
Npc z Devland:
[LUA]function onThink()
if focus > 0 then
x, y, z = creatureGetPosition(focus)
myx, myy, myz = selfGetPosition()
if ((myy-y==0) and (myx-x<=0 and myx-x>=-4)) then
selfTurn(1)
end
if ((myy-y==0) and (myx-x>=0 and myx-x<=4)) then
selfTurn(3)
end
if ((myx-x==0) and (myy-y<=0 and myy-y>=-4)) then
selfTurn(2)
end
if ((myx-x==0) and (myy-y>=0 and myy-y<=4)) then
selfTurn(0)
end
if ((myy-y==-2) and (myx-x>=-1 and myx-x<=1)) then
selfTurn(2)
end
if ((myy-y==2) and (myx-x>=-1 and myx-x<=1)) then
selfTurn(0)
end
if ((myx-x==2) and (myy-y>=-1 and myy-y<=1)) then
selfTurn(3)
end
if ((myx-x==-2) and (myy-y>=-1 and myy-y<=1)) then
selfTurn(1)
end
if ((myy-y==-3) and (myx-x>=-2 and myx-x<=2)) then
selfTurn(2)
end
if ((myy-y==3) and (myx-x>=-2 and myx-x<=2)) then
selfTurn(0)
end
if ((myx-x==3) and (myy-y>=-2 and myy-y<=2)) then
selfTurn(3)
end
if ((myx-x==-3) and (myy-y>=-2 and myy-y<=2)) then
selfTurn(1)
end
if ((myy-y==-4) and (myx-x>=-3 and myx-x<=3)) then
selfTurn(2)
end
if ((myy-y==4) and (myx-x>=-3 and myx-x<=3)) then
selfTurn(0)
end
if ((myx-x==4) and (myy-y>=-3 and myy-y<=3)) then
selfTurn(3)
end
if ((myx-x==-4) and (myy-y>=-3 and myy-y<=3)) then
selfTurn(1)
end
end
if (os.clock() - talk_start) > 30 then
if focus > 0 then
selfSay('Next Please...')
end
focus = 0
end
if focus ~= 0 then
if getDistanceToCreature(focus) > 5 then
selfSay('Good bye then.')
focus = 0
end
end
end[/LUA]
Npc z Wodbo:
[LUA]function onThink()
doNpcSetCreatureFocus(focus)
if (os.clock() - talk_start) > 45 then
if focus > 0 then
selfSay('Next Please...')
end
focus = 0
end
if focus ~= 0 then
if getDistanceToCreature(focus) > 5 then
selfSay('Good bye then.')
focus = 0
end
end
end[/LUA]
Kod c++ ten funkcji:
[CPP]int NpcScriptInterface::luaSetNpcFocus(lua_State *L)
{
//doNpcSetCreatureFocus(cid)
uint32_t cid = popNumber(L);
ScriptEnviroment* env = getScriptEnv();
Npc* mynpc = env->getNpc();
if(mynpc){
Creature* creature = env->getCreatureByUID(cid);
if(creature){
mynpc->setCreatureFocus(creature);
}
else{
reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
}
}
return 0;
} [/CPP]
I moim pytaniem jest czy funkcja lua z Devlanda nie obci??a za bardzo silnika gdy jest du?o npc, oraz czy jest wszystko w niej ok.
Pozdrawiam
Skompilowa?em sobie silnik Devland 0.97 jako baz? pod Wodbo ots. Skopiowa?em najprostszy npc Yama i wywala mi b??d (tak jest z ka?dym npc)
Umiem sobie z nim poradzi? ?eby b??d nie wyskakiwa? ale zastanawiam si? czy nie jest to niepotrzebne obci??anie silnika, i czy kod jest dobrze napisany.
Gdy skopiuj? npc z oryginalnego Deva jest ok. Skrypt lua si? nieco r??ni, ale te? wygl?da mi na ?le zoptymalizowany.
Npc z Devland:
[LUA]function onThink()
if focus > 0 then
x, y, z = creatureGetPosition(focus)
myx, myy, myz = selfGetPosition()
if ((myy-y==0) and (myx-x<=0 and myx-x>=-4)) then
selfTurn(1)
end
if ((myy-y==0) and (myx-x>=0 and myx-x<=4)) then
selfTurn(3)
end
if ((myx-x==0) and (myy-y<=0 and myy-y>=-4)) then
selfTurn(2)
end
if ((myx-x==0) and (myy-y>=0 and myy-y<=4)) then
selfTurn(0)
end
if ((myy-y==-2) and (myx-x>=-1 and myx-x<=1)) then
selfTurn(2)
end
if ((myy-y==2) and (myx-x>=-1 and myx-x<=1)) then
selfTurn(0)
end
if ((myx-x==2) and (myy-y>=-1 and myy-y<=1)) then
selfTurn(3)
end
if ((myx-x==-2) and (myy-y>=-1 and myy-y<=1)) then
selfTurn(1)
end
if ((myy-y==-3) and (myx-x>=-2 and myx-x<=2)) then
selfTurn(2)
end
if ((myy-y==3) and (myx-x>=-2 and myx-x<=2)) then
selfTurn(0)
end
if ((myx-x==3) and (myy-y>=-2 and myy-y<=2)) then
selfTurn(3)
end
if ((myx-x==-3) and (myy-y>=-2 and myy-y<=2)) then
selfTurn(1)
end
if ((myy-y==-4) and (myx-x>=-3 and myx-x<=3)) then
selfTurn(2)
end
if ((myy-y==4) and (myx-x>=-3 and myx-x<=3)) then
selfTurn(0)
end
if ((myx-x==4) and (myy-y>=-3 and myy-y<=3)) then
selfTurn(3)
end
if ((myx-x==-4) and (myy-y>=-3 and myy-y<=3)) then
selfTurn(1)
end
end
if (os.clock() - talk_start) > 30 then
if focus > 0 then
selfSay('Next Please...')
end
focus = 0
end
if focus ~= 0 then
if getDistanceToCreature(focus) > 5 then
selfSay('Good bye then.')
focus = 0
end
end
end[/LUA]
Npc z Wodbo:
[LUA]function onThink()
doNpcSetCreatureFocus(focus)
if (os.clock() - talk_start) > 45 then
if focus > 0 then
selfSay('Next Please...')
end
focus = 0
end
if focus ~= 0 then
if getDistanceToCreature(focus) > 5 then
selfSay('Good bye then.')
focus = 0
end
end
end[/LUA]
Kod c++ ten funkcji:
[CPP]int NpcScriptInterface::luaSetNpcFocus(lua_State *L)
{
//doNpcSetCreatureFocus(cid)
uint32_t cid = popNumber(L);
ScriptEnviroment* env = getScriptEnv();
Npc* mynpc = env->getNpc();
if(mynpc){
Creature* creature = env->getCreatureByUID(cid);
if(creature){
mynpc->setCreatureFocus(creature);
}
else{
reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
}
}
return 0;
} [/CPP]
I moim pytaniem jest czy funkcja lua z Devlanda nie obci??a za bardzo silnika gdy jest du?o npc, oraz czy jest wszystko w niej ok.
Pozdrawiam