1. Autor: Miziak
2. Link do oryginalnego tematu:
3. Opis: Po dodaniu tego kodu b?dziemy mogli ustawi? napis nad dan? kratk?, przyk?adowo nad teleportem.zale? i rosn?? co 1 wypowiedziany czar o 1 poziom magiczny, dlatego teraz mo?esz ustali? jaki najwi?kszy magic level mo?e dana profesja osi?gn??."
4. Kod:
W npc.cpp pod:
[CPP]lua_register(luaState, "selfGetPosition", NpcScript::luaSelfGetPos);[/CPP]
dajemy:
[CPP]lua_register(luaState, "doNpcSendAnimatedText", NpcScript::luaSendAnimatedText);
lua_register(luaState, "doNpcSendMagicEffect", NpcScript::luaSendMagicEffect);[/cpp]
i dalej w tym samym pliku pod:
[CPP]int NpcScript::luaActionMoveTo(lua_State* L){
Position target;
target.z=(int)lua_tonumber(L, -1);
lua_pop(L,1);
target.y=(int)lua_tonumber(L, -1);
lua_pop(L,1);
target.x=(int)lua_tonumber(L, -1);
lua_pop(L,1);
Npc* mynpc=getNpc(L);
if(mynpc)
mynpc->doMoveTo(target);
return 0;
} [/CPP]
doklejamy:
[CPP]int NpcScript::luaSendAnimatedText(lua_State* L)
{
std::string text = lua_tostring(L, -5);
int color = (int)lua_tonumber(L, -4);
int x = (int)lua_tonumber(L, -3);
int y = (int)lua_tonumber(L, -2);
int z = (int)lua_tonumber(L, -1);
lua_pop(L, 5);
Npc* mynpc = getNpc(L);
Position pos(x,y,z);
SpectatorVec list;
mynpc->game->getSpectators(Range(pos, true), list);
for(SpectatorVec::iterator it = list.begin(); it != list.end(); ++it){
Player *p = dynamic_cast<Player*>(*it);
if(p){
p->sendAnimatedText(pos, color, text);
}
}
return 0;
}
int NpcScript::luaSendMagicEffect(lua_State* L)
{
int efekt = (int)lua_tonumber(L, -4);
int x = (int)lua_tonumber(L, -3);
int y = (int)lua_tonumber(L, -2);
int z = (int)lua_tonumber(L, -1);
lua_pop(L, 4);
Position pos(x,y,z);
for(AutoList<Player>::listiterator it = Player::listPlayer.list.begin(); it != Player::listPlayer.list.end(); ++it){
(*it).second->sendMagicEffect(pos, efekt);
}
return 0;
}[/CPP]
teraz w npc.h pod:
[CPP]static int luaSelfGetPos(lua_State *L);[/CPP]
wklejamy:
[cpp]static int luaSendAnimatedText(lua_State *L);
static int luaSendMagicEffect(lua_State *L);[/cpp]
Teraz w game.h t? linijk?:
[CPP]void getSpectators(const Range& range, SpectatorVec& list); [/CPP]
PRZENOSIMY pod t?:
[CPP]void checkSpell(Player* player, SpeakClasses type, std::string text); [/CPP]
COMPILE
Teraz lua:
do config.lua:
[LUA]--czy efekty s? w??czone (yes/no)
effects_emblamed = "yes"
--czy kolor textu jest losowy(yes/no)
random_colour = "yes"
--czy efekt jest losowy(yes/no)
random_effect = "yes"
--co jaki czas sie wy?wietla efekt w sekundach
co_ile = 1
-- {text="tekst", pos={x=pozycja_x, y=pozycja_y, z=pozycja_z}, color=kolor_textu, effect=nr_efektu}
efekty = {
{text="Depo", pos={x=160, y=49, z=6}, color=1, effect=12},
{text="Ammo", pos={x=155, y=49, z=6}, color=2, effect=13},
{text="Aol", pos={x=165, y=49, z=6}, color=3, effect=14}
} [/LUA]
teraz npc wywo?uj?cy efekty - data/np/scripts tworzymy plik efekciarz.lua i wklejamy:
[LUA]start = nil
focus = 0
talk_start = 0
target = 0
following = false
attacking = false
dofile("./config.lua")
function onThingMove(creature, thing, oldpos, oldstackpos)
end
function onCreatureAppear(creature)
end
function onCreatureDisappear(cid, pos)
end
function onCreatureTurn(creature)
end
function msgcontains(txt, str)
end
function onCreatureSay(cid, type, msg)
end
function onCreatureChangeOutfit(creature)
end
function onThink()
if start == nil then
start = os.time()
end
if(effects_emblamed == "yes")then
if os.difftime (os.time(), start) >= (co_ile) then
for i,v in pairs(efekty) do
doNpcSendAnimatedText(v.text, (random_colour == "yes" and math.random(1, 254) or v.color), v.pos.x, v.pos.y, v.pos.z)
doNpcSendMagicEffect((random_effect == "yes" and math.random(0, 24) or v.effect), v.pos.x, v.pos.y, v.pos.z)
end
start = os.time()
end
end
end [/LUA]
Efekt.xml w data/npc i wklejamy:
[XML]<?xml version="1.0"?>
<npc name="Efekt" script="data/npc/scripts/efekciarz.lua" access="5">
<look type="128" head="78" body="71" legs="82" feet="114"/>
</npc> [/XML]
Teraz npc o imieniu Efekt stawiamy gdzie? na mapie w podziemiach ?eby nie przeszkadza? ca?? konfiguracj? mamy w config.lua
Testowane wszystko dzia?a poprawnie.
Enjoy.
2. Link do oryginalnego tematu:
3. Opis: Po dodaniu tego kodu b?dziemy mogli ustawi? napis nad dan? kratk?, przyk?adowo nad teleportem.zale? i rosn?? co 1 wypowiedziany czar o 1 poziom magiczny, dlatego teraz mo?esz ustali? jaki najwi?kszy magic level mo?e dana profesja osi?gn??."
4. Kod:
W npc.cpp pod:
[CPP]lua_register(luaState, "selfGetPosition", NpcScript::luaSelfGetPos);[/CPP]
dajemy:
[CPP]lua_register(luaState, "doNpcSendAnimatedText", NpcScript::luaSendAnimatedText);
lua_register(luaState, "doNpcSendMagicEffect", NpcScript::luaSendMagicEffect);[/cpp]
i dalej w tym samym pliku pod:
[CPP]int NpcScript::luaActionMoveTo(lua_State* L){
Position target;
target.z=(int)lua_tonumber(L, -1);
lua_pop(L,1);
target.y=(int)lua_tonumber(L, -1);
lua_pop(L,1);
target.x=(int)lua_tonumber(L, -1);
lua_pop(L,1);
Npc* mynpc=getNpc(L);
if(mynpc)
mynpc->doMoveTo(target);
return 0;
} [/CPP]
doklejamy:
[CPP]int NpcScript::luaSendAnimatedText(lua_State* L)
{
std::string text = lua_tostring(L, -5);
int color = (int)lua_tonumber(L, -4);
int x = (int)lua_tonumber(L, -3);
int y = (int)lua_tonumber(L, -2);
int z = (int)lua_tonumber(L, -1);
lua_pop(L, 5);
Npc* mynpc = getNpc(L);
Position pos(x,y,z);
SpectatorVec list;
mynpc->game->getSpectators(Range(pos, true), list);
for(SpectatorVec::iterator it = list.begin(); it != list.end(); ++it){
Player *p = dynamic_cast<Player*>(*it);
if(p){
p->sendAnimatedText(pos, color, text);
}
}
return 0;
}
int NpcScript::luaSendMagicEffect(lua_State* L)
{
int efekt = (int)lua_tonumber(L, -4);
int x = (int)lua_tonumber(L, -3);
int y = (int)lua_tonumber(L, -2);
int z = (int)lua_tonumber(L, -1);
lua_pop(L, 4);
Position pos(x,y,z);
for(AutoList<Player>::listiterator it = Player::listPlayer.list.begin(); it != Player::listPlayer.list.end(); ++it){
(*it).second->sendMagicEffect(pos, efekt);
}
return 0;
}[/CPP]
teraz w npc.h pod:
[CPP]static int luaSelfGetPos(lua_State *L);[/CPP]
wklejamy:
[cpp]static int luaSendAnimatedText(lua_State *L);
static int luaSendMagicEffect(lua_State *L);[/cpp]
Teraz w game.h t? linijk?:
[CPP]void getSpectators(const Range& range, SpectatorVec& list); [/CPP]
PRZENOSIMY pod t?:
[CPP]void checkSpell(Player* player, SpeakClasses type, std::string text); [/CPP]
COMPILE
Teraz lua:
do config.lua:
[LUA]--czy efekty s? w??czone (yes/no)
effects_emblamed = "yes"
--czy kolor textu jest losowy(yes/no)
random_colour = "yes"
--czy efekt jest losowy(yes/no)
random_effect = "yes"
--co jaki czas sie wy?wietla efekt w sekundach
co_ile = 1
-- {text="tekst", pos={x=pozycja_x, y=pozycja_y, z=pozycja_z}, color=kolor_textu, effect=nr_efektu}
efekty = {
{text="Depo", pos={x=160, y=49, z=6}, color=1, effect=12},
{text="Ammo", pos={x=155, y=49, z=6}, color=2, effect=13},
{text="Aol", pos={x=165, y=49, z=6}, color=3, effect=14}
} [/LUA]
teraz npc wywo?uj?cy efekty - data/np/scripts tworzymy plik efekciarz.lua i wklejamy:
[LUA]start = nil
focus = 0
talk_start = 0
target = 0
following = false
attacking = false
dofile("./config.lua")
function onThingMove(creature, thing, oldpos, oldstackpos)
end
function onCreatureAppear(creature)
end
function onCreatureDisappear(cid, pos)
end
function onCreatureTurn(creature)
end
function msgcontains(txt, str)
end
function onCreatureSay(cid, type, msg)
end
function onCreatureChangeOutfit(creature)
end
function onThink()
if start == nil then
start = os.time()
end
if(effects_emblamed == "yes")then
if os.difftime (os.time(), start) >= (co_ile) then
for i,v in pairs(efekty) do
doNpcSendAnimatedText(v.text, (random_colour == "yes" and math.random(1, 254) or v.color), v.pos.x, v.pos.y, v.pos.z)
doNpcSendMagicEffect((random_effect == "yes" and math.random(0, 24) or v.effect), v.pos.x, v.pos.y, v.pos.z)
end
start = os.time()
end
end
end [/LUA]
Efekt.xml w data/npc i wklejamy:
[XML]<?xml version="1.0"?>
<npc name="Efekt" script="data/npc/scripts/efekciarz.lua" access="5">
<look type="128" head="78" body="71" legs="82" feet="114"/>
</npc> [/XML]
Teraz npc o imieniu Efekt stawiamy gdzie? na mapie w podziemiach ?eby nie przeszkadza? ca?? konfiguracj? mamy w config.lua
Testowane wszystko dzia?a poprawnie.
Enjoy.