What's new

Follow System

Status
Not open for further replies.

Xauen

Active User
Joined
Aug 23, 2009
Messages
67
Reaction score
3
Game.cpp

Pod

Kod:
stopEvent(c->eventCheck);
stopEvent(c->eventCheckAttacking);

w

Kod:

bool Game::removeCreature(Creature* c)

Wklejamy

Kod:

stopEvent(c->eventCheckFollow);

Gdziekolwiek w game.cpp (najlepiej na dole )

Kod:


void Game::checkCreatureFollow(unsigned long id)
{
OTSYS_THREAD_LOCK_CLASS lockClass(gameLock, "Game::checkCreatureFollow");
Player *player = getPlayerByID(id);
if(!player)
return;
if(!player->pathList.empty()) {
Position toPos = player->pathList.front();
player->pathList.pop_front();
player->lastmove = OTSYS_TIME();
this->thingMove(player, player, toPos.x, toPos.y, player->pos.z, 1);
flushSendBuffers();
}
if(!player->pathList.empty()) {
long long delay = player->getSleepTicks();
stopEvent(player->eventCheckFollow);
player->eventCheckFollow = addEvent(makeTask(delay, std::bind2nd(std::mem_fun(&Game::checkCreatureFollow), id)));
}
else {
player->eventCheckFollow = 0;
}
}
void Game::playerFollow(Player* player, Creature *followCreature)
{
OTSYS_THREAD_LOCK_CLASS lockClass(gameLock, "Game::playerFollow()");
if(followCreature->isRemoved || player->isRemoved || !player || !followCreature){
player->eventCheckFollow = 0;
player->followCreature = 0;
return;
}
player->pathList = getPathTo(player, player->pos, followCreature->pos, false);
long long delay = player->getSleepTicks();
player->eventCheckFollow = addEvent(makeTask(delay, std::bind2nd(std::mem_fun(&Game::checkCreatureFollow), player->getID())));
}
void Game::playerSetFollowCreature(Player* player, unsigned long creatureid)
{
OTSYS_THREAD_LOCK_CLASS lockClass(gameLock, "Game::playerSetFollowCreature()");
if(player->isRemoved || !player)
return;
if(creatureid == 0) {
stopEvent(player->eventCheckFollow);
player->eventCheckFollow = 0;
player->followCreature = 0;
}
Creature* followCreature = NULL;
if(creatureid != 0) {
followCreature = getCreatureByID(creatureid);
}
if(followCreature) {
player->followCreature = followCreature->getID();
stopEvent(player->eventCheckFollow);
playerFollow(player, followCreature);
}
}

Game.h

Public

Kod:

void checkCreatureFollow(unsigned long id);
void playerFollow(Player* player, Creature *followCreature);
void playerSetFollowCreature(Player* player, unsigned long creatureid);

Creature.h
Pod

Kod:
unsigned long attackedCreature;

wklejamy

Kod:

unsigned long followCreature;
std::list<Position> pathList;
unsigned long eventCheckFollow;


Creature.cpp
Pod

Kod:

eventCheck = 0;
eventCheckAttacking = 0;

wklejamy

Kod:

eventCheckFollow = 0;
followCreature = 0;

Protocol76.cpp
Pod

Kod:

case 0xA1: // attack
parseAttack(msg);
break;
wklejamy

Kod:

case 0xA2: // attack
parseFollow(msg);
break;

Pod

Kod:

void Protocol76::parseAttack(NetworkMessage &msg)
{
unsigned long creatureid = msg.GetU32();
game->playerSetAttackedCreature(player, creatureid);
}
wklejamy

Kod:

void Protocol76::parseFollow(NetworkMessage &msg)
{
unsigned long creatureid = msg.GetU32();
game->playerSetFollowCreature(player, creatureid);
}

Protocol76.h

Pod

Kod:

void parseAttack(NetworkMessage &msg);

wklejamy

Kod:

void parseFollow(NetworkMessage &msg);

Player.cpp

Podmie?

Kod:

void Player:nThingMove(const Creature *creature, const Thing *thing, const Position *oldPos,
unsigned char oldstackpos, unsigned char oldcount, unsigned char count)
{
client->sendThingMove(creature, thing, oldPos, oldstackpos, oldcount, count);
}

Na to:

Kod:


void Player::eek:nThingMove(const Creature *creature, const Thing *thing, const Position *oldPos,
unsigned char oldstackpos, unsigned char oldcount, unsigned char count)
{
const Creature *constantCreature = dynamic_cast<const Creature*>(thing);
if(constantCreature && constantCreature->getID() == this->followCreature){
g_game.playerFollow(this, const_cast<Creature*>(constantCreature));
}
client->sendThingMove(creature, thing, oldPos, oldstackpos, oldcount, count);
}
Pozdrawiam i my?l?, ?e kod sie wam przyda. Testowany prze ze mnie idzia?a na 100% ;)


Notka moderatorska:
Wy??czaj u?mieszki, gdy wstawiasz skrypt.
 

Mr David

Advanced User
Joined
Nov 9, 2009
Messages
203
Reaction score
47
Odp: Follow System

Mam takie ma?e pytania co do tego kodu.
  • Kto jest jego autorem?
  • Czy je?li damy komu? follow a potem stracimy go z oczu, to nadal b?dzie follow dzia?a? czy przestanie?

PS: Niewiem czy tak ma by? (Niewiem ofc czy twojego kodu to tez dotyczy ale tak my?l?), ale o ile si? nie myl? to je?li damy follow to jest "ma?e" op??nienie czasowe.

Pozdrawiam,
Mr David.
 

loolester

User
Joined
Aug 8, 2009
Messages
17
Reaction score
0
Odp: Follow System

Game.h

Public

Kod:

Cytat:
void checkCreatureFollow(unsigned long id);
void playerFollow(Player* player, Creature *followCreature);
void playerSetFollowCreature(Player* player, unsigned long creatureid);

JA wiem gdzie to doda? ale inni mog? nie wiedzie?... napisz
 

pontiac1909

New User
Joined
Feb 22, 2010
Messages
2
Reaction score
0
Odp: Follow System

Nie dzia?a mi. Pe?no b??d?w wyskakuje, ?e nawet nie ma sensu ich tu wstawia?. A pozatym pisz poprowanie:

Code:
void Player[COLOR="Red"]:[/COLOR]:[COLOR="Red"]o[/COLOR]nThingMove(const Creature *creature, const Thing *thing, const Position *oldPos,
unsigned char oldstackpos, unsigned char oldcount, unsigned char count)
{
client->sendThingMove(creature, thing, oldPos, oldstackpos, oldcount, count);
}
 

Reput xD

User
Joined
Feb 27, 2010
Messages
11
Reaction score
0
Odp: Follow System

Kod dzi?a lecz ma jeen minus moze dac follow na monstery. Ogolnie kod mi sie podoba ale prosilbym autora o zmiane kodu zeby na monstery nie mozna bylo dac follow
 

dominikms1

Senior User
Joined
Feb 6, 2010
Messages
696
Reaction score
66
Odp: Follow System

Up
Dlaczego nie mo?e dzia?a? na monstery?? skoro na rl tibii to dzia?a i nikt na to si? nie skar?y :p
A jak na p??niejszych otsach jest to ju? nie pami?tam, bo nie sprawdza?em
 

menqazqaz

User
Joined
May 25, 2008
Messages
33
Reaction score
1
Odp: Follow System

:eek:ps:lol:);):(:D:p:confused::hah::>:curse:niee:O;(o_O genialny i beznadziejny na war si? przyda i lekkie enfo
 
Status
Not open for further replies.
Top