Page 1 of 2

Pets

Posted: 20 Sep 2010, 17:03
by alfaodin
hi, Sorry for bothering you, the question is how can I add a pet to my character, how can i have control over it (for example the pet has animations and with a button you make the animations play). I am lost.
Thank you

Posted: 21 Sep 2010, 14:41
by Bax
A couple of ideas:
1) Pet is an NPC, controlled by your server-side extension. Not so easy to implement
2) Pet is part of the avatar class itself, just like if it was an avatar skin. You can control it in your avatar class

Posted: 21 Sep 2010, 15:34
by TiagoR
Regarding the subject on this topic, is there any avatar action example ?

Posted: 21 Sep 2010, 15:39
by Bax
We don't have a specific example on avatar actions, but the usage is very similar to the avatar skin change. In your avatar class, when the action method is called, show the proper animation.

Pets

Posted: 21 Sep 2010, 20:55
by alfaodin
Thank you men, You gave me some ideas, another question in the new version of SmartfoxSever, Are you going to include a features like this??. Again thank you.

Posted: 22 Sep 2010, 20:07
by gl0om
I use Vector<User> for controlled avatars and Timer for controlling them, but I suppose it's too ugly approach for making npc with "brain"... Please, bax, can you suggest better idea for this?

Posted: 24 Sep 2010, 11:38
by Bax
gl0om, how can you control npc avatars on a single client. This is a bad approach.
All npc controlling should be made on the server-side, inside your extension.

Posted: 24 Sep 2010, 12:25
by gl0om
Seems like you answered on my unedited reply... Actually I found in docs article about scheduler, hope it'll help me in controlling my army of npc

Posted: 24 Sep 2010, 20:44
by gl0om
I met a problem. I pass Npc-user as parameter to Task and perform moveAvatar in it. When I kick user Task doesn't stop and I begin to receive warnings like "moveAvatar is ignored because user is not in room".

I tried to do such tricks inside doTask

Code: Select all

if (!npc.isInRoom(npc.getRoom()))
{
      task.active = false;
}

and

Code: Select all

try {
   moveAvatar(npc, npc.getRoom(), (int) Math.round(Math.random() * 10), (int) Math.round(Math.random() * 10), 0);
} catch (Exception e) {
   task.active = false;               
}


So how to kill Task when user is lost, disconnected, kicked?

Posted: 27 Sep 2010, 08:46
by Lapo
task.active = false
is correct, but... are you absolutely sure you are pointing to the right task?

Posted: 27 Sep 2010, 08:59
by gl0om
Lapo wrote:task.active = false
is correct, but... are you absolutely sure you are pointing to the right task?

I suppose that task is correct. It's an argument for doTask(Task task)

Posted: 27 Sep 2010, 09:31
by Lapo
What I mean is that it sounds like you are running several tasks, maybe one per User... am I getting this correctly? So I am suggesting that you debug your code and make sure that the task object you are de-activating is really the one connected with the User that just left.

Posted: 28 Sep 2010, 15:55
by gl0om
Yes, you are right, I use 1 task per User.
I tried to figure out what's happening inside doTask..

Code: Select all

public void doTask(Task task) throws Exception
{
            String id = (String) task.id;
            String message = "Handling Task >>> { " + id + " }";
           
            Map params = task.parameters;
            User npc = (User)params.get("npc");
            trace("Check user: " + npc.getUserId());
            if (!npc.isInRoom(npc.getRoom()))
            {
               task.active = false;
            }
            else
            {
               trace("User is in room: " + npc.getRoom());
            }
}


After User is disconnected or kicked, I still receive message "User is in room: #"
So task.active = false; is never fired

Posted: 30 Sep 2010, 08:28
by gl0om
I tried to solve this issue without success. I have no idea why User npc = (User)params.get("npc"); always exists, even after the user is lost.

Now I see the only solution:

1. Store all NPC in DB.

2. Mark lost users in internalEvent for removing in DB.

3. Check if it's makred for removing on each tick in doTask. If it's - deactivate task and remove NPC from DB.

I'm not sure that it's good solution because of it's complexity and additional stress for DB. What do you think?

Posted: 04 Oct 2010, 13:49
by Lapo
I am a little puzzled.
I have no idea why User npc = (User)params.get("npc"); always exists, even after the user is lost.

Can you better explain this?
In the USER_LOST event you are passed the User object. Where else do you get that User? I don't understand. After the USER_LOST you should not receive any more events about that User.