What's new

-Tibia 7.60 Funkcja doPlayerAddPremium

Status
Not open for further replies.

Saelasti

Advanced User
Joined
Apr 1, 2014
Messages
192
Reaction score
25
Nast?pny kod.

Autor: Blizzar?aviD
Link ?rod?owy: LINK
Testowany na: YurOTS 0.4.9f
Opis: Po wprowadzeniu tego kodu, mo?liwe stanie si? dodawanie do plik?w akcji (data\actions\scripts) funkcji: doPlayerAddPremium. Dzi?ki niej, mo?emy dodawa? okre?lon? ilo?? minut Premium (Pacc'a) w takich akcjach jak np: u?ycie/wej?cie na/zej?cie z jakiego? przedmiotu.​



Kod:
1. w actions.cpp
pod:
[CPP]//doPlayerAddMana(uid,mana)
lua_register(luaState, "doPlayerAddMana", ActionScript::luaActionDoPlayerAddMana);[/CPP]
dodaj:
[CPP] //doPlayerAddPremium(uid,pacc)
lua_register(luaState, "doPlayerAddPremium", ActionScript::luaActionDoPlayerAddPremium);[/CPP]

2. w actions.cpp
pod:
[CPP]int ActionScript::luaActionDoPlayerAddMana(lua_State *L)
{
//doPlayerAddMana(uid,mana)
int addmana = (int)internalGetNumber(L);
unsigned int cid = (unsigned int)internalGetNumber(L);

ActionScript *action = getActionScript(L);

const KnownThing* tmp = action->GetPlayerByUID(cid);
if(tmp){
Player *player = (Player*)(tmp->thing);
player->mana = std::min(player->manamax,player->mana+addmana);
player->sendStats();
}
else{
lua_pushnumber(L, -1);
std::cout << "luaDoPlayerAddMana: player not found" << std::endl;
return 1;
}

lua_pushnumber(L, 0);
return 1;
}[/CPP]
dodaj:
[CPP]int ActionScript::luaActionDoPlayerAddPremium(lua_State *L)
{
//doPlayerAddPremium(uid,pacc)
int pacc = (int)internalGetNumber(L);
unsigned int cid = (unsigned int)internalGetNumber(L);

ActionScript *action = getActionScript(L);

const KnownThing* tmp = action->GetPlayerByUID(cid);
if(tmp){
Player *player = (Player*)(tmp->thing);
player->premiumTicks += 1000*60*(pacc);
}
else{
lua_pushnumber(L, -1);
std::cout << "luaDoPlayerAddPremium: player not found" << std::endl;
return 1;
}

lua_pushnumber(L, 0);
return 1;
}[/CPP]

3. w actions.h
pod:
[CPP]static int luaActionDoPlayerAddMana(lua_State *L);[/CPP]
dodaj:
[CPP]static int luaActionDoPlayerAddPremium(lua_State *L);[/CPP]

Projekt przebudowa? (Ctrl+F11) i gotowe.


Dodatkowe opcje:
a) Po wprowadzeniu kodu mo?na zrobi? test,
1. w data\actions w actions.xml
pod:
[XML]<?xml version="1.0"?>
<actions>[/XML]
dodaj:
[XML]<action itemid="5022" script="test.lua" />[/XML]

2. w data\actions\scripts tworzymy plik test.lua, a w nim dodajemy to:
[LUA]function onUse(cid, item, frompos, item2, topos)
doPlayerAddPremium(cid,15)
end[/LUA]


Po zapisaniu obu powy?szych plik?w i odpaleniu silnika, trzeba zalogowa? si? na posta? z GMem, wpisa? ni? /i 5022 1. Pod nasz? postaci? pojawi si? bia?a per?a (white pearl) o ID 5022, po jej u?yciu powinni?my otrzyma? 15 minut Premium.
Je?eli test powi?d? si?, mo?na spokojnie usun?? plik test.lua oraz fraz? w pliku actions.xml i dodawa? funkcj? doPlayerAddPremium do w?asnych akcji.


b) Je?eli chcemy, aby nasz przedmiot dodawa? godziny zamiast minut - nie trzeba si? trudzi? z obliczaniem, nale?y dopisa? na pomara?czowo:
[LUA]doPlayerAddPremium(cid,15*60)[/LUA]


I tak z 15 minut, mamy 15 godzin.
 

#NOOB

Senior User
Joined
May 25, 2014
Messages
901
Reaction score
89
Odp: Funkcja doPlayerAddPremium

#t
Mo?na te? doda? jaki? komunikacik.
[LUA]function onUse(cid, item, frompos, item2, topos)
doPlayerSendTextMessage(cid,22,"Doladowano PACC.")
doPlayerAddPremium(cid,15)
end[/LUA]

#off
Masz tam jeszcze co? ciekawego... ? ;p
 
Status
Not open for further replies.
Top