Ir para conteúdo

[7.8] Bless System


Posts Recomendados

Olá amigos decidi postar meu sistema de blessing para vocês.

Para quem não sabe sou Rappa Carnaúba(Sapphire da OTFans)

Vamos comecar,

em player.h abaixo de

 

void kickPlayer();

 

adicione

 

#ifdef __SAP_BLESS_SYSTEM__	int bless;#endif //__SAP_BLESS_SYSTEM__

 

substitua:

 

  virtual int getLostExperience(){ 	 return (int)std::floor(((double)experience * 0.1));	}

 

por:

 

#ifdef __SAP_BLESS_SYSTEM__	virtual int getLostExperience(){        switch(bless){    case 1: 	 return (int)std::floor(((double)experience * 0.09));    case 2: 	 return (int)std::floor(((double)experience * 0.08));    case 3: 	 return (int)std::floor(((double)experience * 0.07));    case 4: 	 return (int)std::floor(((double)experience * 0.06));    case 5: 	 return (int)std::floor(((double)experience * 0.05));    default: 	 return (int)std::floor(((double)experience * 0.1));    }  } #else    virtual int getLostExperience(){ 	 return (int)std::floor(((double)experience * 0.1));	} #endif //#ifdef __SAP_BLESS_SYSTEM__

 

agora em player.cpp

No construtor Player::Player

abaixo de

 

tradeItem = NULL;

 

 

#ifdef __SAP_BLESS_SYSTEM__	bless = 0;#endif //__SAP_BLESS_SYSTEM__

 

Agora na funcão void Player::die()

substitua

 

lostMana = (long)(sumMana * 0.1);

 

por

 

#ifdef __SAP_BLESS_SYSTEM__	switch(bless){    case 1: 	 lostMana = (long)(sumMana * 0.09);    case 2: 	 lostMana = (long)(sumMana * 0.08);    case 3: 	 lostMana = (long)(sumMana * 0.07);    case 4: 	 lostMana = (long)(sumMana * 0.06);    case 5: 	 lostMana = (long)(sumMana * 0.05);    default: 	 lostMana = (long)(sumMana * 0.1);    }   #else  	 lostMana = (long)(sumMana * 0.1);#endif //__SAP_BLESS_SYSTEM__

 

mais abaixo substitua

 

lostSkillTries = (long) (sumSkillTries * 0.1);

 

por:

 

#ifdef __SAP_BLESS_SYSTEM__	switch(bless){    case 1: 	 lostSkillTries = (long) (sumSkillTries * 0.09);    case 2: 	 lostSkillTries = (long) (sumSkillTries * 0.08);    case 3: 	 lostSkillTries = (long) (sumSkillTries * 0.07);    case 4: 	 lostSkillTries = (long) (sumSkillTries * 0.06);    case 5: 	 lostSkillTries = (long) (sumSkillTries * 0.05);    default: 	 lostSkillTries = (long) (sumSkillTries * 0.1);	}    #else  	 lostSkillTries = (long) (sumSkillTries * 0.1);#endif //__SAP_BLESS_SYSTEM__

 

abaixo de:

 

	if(newLevel != level){  std::stringstream lvMsg;  lvMsg << "You were downgraded from level " << level << " to level " << newLevel << ".";  client->sendTextMessage(MSG_EVENT_ADVANCE, lvMsg.str().c_str());	}

 

adicione

 

	#ifdef __SAP_BLESS_SYSTEM__	bless = 0;	#endif //__SAP_BLESS_SYSTEM__

 

Para quem usa mysql

ioplayersql.cpp

abaixo de

 

player->experience = result.getDataLong("experience");

 

adicione:

 

#ifdef __SAP_BLESS_SYSTEM__	player->bless = result.getDataInt("bless");#endif //__SAP_BLESS_SYSTEM__

 

agora em savePlayer

abaixo de:

 

query << "`experience` = " << player->experience << ", ";

 

adicione:

 

#ifdef __SAP_BLESS_SYSTEM__	query << "`bless` = " << player->bless << ", ";#endif //__SAP_BLESS_SYSTEM__

 

Para quem usa XML

ioplayerxml.cpp

abaixo de:

 

	if(readXMLInteger(root, "exp", intValue)){ 	 player->experience = intValue;  }  else 	 isLoaded = false;

 

adicione:

 

	if(readXMLInteger(root, "bless", intValue)){ 	 player->bless = intValue;  }  else 	 isLoaded = false;

 

agora em savePlayer,

abaixo de

 

	sb << player->experience;   xmlSetProp(root, (const xmlChar*)"exp", (const xmlChar*)sb.str().c_str());    sb.str("");

 

adicione:

 

	sb << player->bless;   xmlSetProp(root, (const xmlChar*)"bless", (const xmlChar*)sb.str().c_str());    sb.str("");

 

agora em npc.cpp

no lua_register adicione

 

	#ifdef __SAP_BLESS_SYSTEM__	lua_register(luaState, "getPlayerBless", NpcScript::luaGetPlayerBless);	lua_register(luaState, "doPlayerAddBless", NpcScript::luaDoPlayerAddBless);	#endif //__SAP_BLESS_SYSTEM__

 

no final do npc.cpp adicione:

 

#ifdef __SAP_BLESS_SYSTEM__int NpcScript::luaGetPlayerBless(lua_State* L){	int cid = (int)lua_tonumber(L, -1);	lua_pop(L, 1);	Npc* mynpc = getNpc(L);	Player* player = dynamic_cast<Player*>(g_game.getCreatureByID(cid));	if(player)   lua_pushnumber(L, player->bless);	else   lua_pushnumber(L, -1);	return 1;}int NpcScript::luaDoPlayerAddBless(lua_State* L){   	int cid = (int)lua_tonumber(L, -2);	int bless = (int)lua_tonumber(L, -1);	lua_pop(L, 2);	Npc* mynpc = getNpc(L);	Player* player = dynamic_cast<Player*>(g_game.getCreatureByID(cid));	if(player) {   if(player->bless < 5){   player->bless += 1;   mynpc->doSay("Here you are your bless, take care young adventure.");   player->sendMagicEffect(player->getPosition(), NM_ME_MAGIC_POISON);   }   else{   mynpc->doSay("Sorry, young adventurer you already have all bless.");   lua_pushnumber(L, 0);   }   }   else{  std::cout << "Error when giving a bless to player." << std::endl;  lua_pushnumber(L, -1);   }   return 0;}  #endif //__SAP_BLESS_SYSTEM__

 

npc.h

abaixo de:

 

static int luaSelfGetPos(lua_State *L);

 

adicione

 

#ifdef __SAP_BLESS_SYSTEM__	static int luaDoPlayerAddBless(lua_State* L);	static int luaGetPlayerBless(lua_State* L);#endif //__SAP_BLESS_SYSTEM__

 

Agora em project->project options "C++ Compiler" adicionem -D__SAP_BLESS_SYSTEM__

Creditos:

Rappa Carnaúba;(Eu)

Abraços!

bless.lua

 

focus = 0talk_start = 0target = 0following = falseattacking = falsetalk_state = 0price = 20000function onThingMove(creature, thing, oldpos, oldstackpos)endfunction onCreatureAppear(creature)endfunction onCreatureDisappear(cid, pos) 	 if focus == cid then          selfSay('Good bye then.')          focus = 0          talk_start = 0 	 endendfunction onCreatureTurn(creature)endfunction msgcontains(txt, str) 	 return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))endfunction onCreatureSay(cid, type, msg) 	 msg = string.lower(msg) 	 if (msgcontains(msg, 'hi') and (focus == 0)) and getDistanceToCreature(cid) < 4 then 	 selfSay('Hello ' .. creatureGetName(cid) .. '! Im selling bless.') 	 focus = cid 	 talk_start = os.clock()	elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then    selfSay('Sorry, ' .. creatureGetName(cid) .. '! I talk to you in a minute.') 	 elseif focus == cid then  talk_start = os.clock()  if msgcontains(msg, 'blessing') or msgcontains(msg, 'bless') then                        if getPlayerBless(cid) > 4 then                                selfSay('Sorry, young adventurer you already have all bless.')                                talk_state = 0    elseif getPlayerLevel(creatureGetName(cid)) < 20 then    selfSay('Sorry, you need level 20 to buy bless.')    talk_state = 0 	 elseif not isPremium(cid) then    selfSay('Sorry, you must be premium to be blessed.')    talk_state = 0 	 else    selfSay('Do you want to buy bless for ' .. price ..' gold coins ?')    talk_state = 1 	 end  elseif talk_state == 1 then 	 if msgcontains(msg, 'yes') then    if pay(cid,price) then   	 doPlayerAddBless(cid, 1)    else   	 selfSay('Sorry, you do not have enough money.')    end    end 	 talk_state = 0    elseif msgcontains(msg, 'bye')  and getDistanceToCreature(cid) < 4 then   	 selfSay('Good bye, ' .. creatureGetName(cid) .. '!')   	 focus = 0   	 talk_start = 0    end 	 endendfunction onCreatureChangeOutfit(creature)endfunction onThink() 	 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  endend

 

Link para o comentário
Compartilhar em outros sites

  • 2 weeks later...
  • 2 weeks later...
  • 1 month later...
  • 1 year later...
  • 5 months later...
  • 1 year later...
×
×
  • Criar Novo...