Help[FSOD] Need help with code...

Posts 1–15 of 17 · Page 1 of 2
[FSOD] Need help with code...
I tried to add my own 'task system' as in realm resolution source and I wrote some code where if you have the required item, it give you the reward and replaces the 'task tablet' with the next 'task tablet'.
Code:
case ActivateEffects.Task1:
                        {
                            for (int i = 0; i < Inventory.Length; i++)
                                if (Inventory[i].ObjectId == "Dragon Pearl")
                                {
                                    {
                                        if (Inventory[i] == null) continue;
                                        if (Inventory[i].ObjectId == "Dragon Pearl") ;true; }
                                        {
                                            Inventory[i] = Manager.GameData.Items[0x108e];
                                            UpdateCount++;
                                            SaveToCharacter();
                                            SendInfo("You have completed the task!");
                                            return true;
                                        };
                                        if (Inventory[i].ObjectId == "Task Tablet 1")
                                        {
                                            Inventory[i] = Manager.GameData.Items[0x42c9];
                                            UpdateCount++;
                                            SaveToCharacter();
                                            return true;
                                        }
                                    }
                                };
                        };
                        break;
What's the problem with this? Every time I use it, the reward works but the task tablet doesn't change.
P.S How to put this in 'code' thing again :P ?
Thanks in Advance!
Quote Originally Posted by LordChronos View Post
I tried to add my own 'task system' as in realm resolution source and I wrote some code where if you have the required item, it give you the reward and replaces the 'task tablet' with the next 'task tablet'.
Code:-
case ActivateEffects.Task1:
{
// try
//{
for (int i = 0; i < Inventory.Length; i++)
if (Inventory[i].ObjectId == "Dragon Pearl")
{
{
if (Inventory[i] == null) continue;
if (Inventory[i].ObjectId == "Dragon Pearl") ;
//if (Inventory[4] != null) { return false; }
//if (Inventory[5] != null) { return false; }
{
Inventory[i] = Manager.GameData.Items[0x108e];
//Inventory[5] = Manager.GameData.Items[0x42c9];
UpdateCount++;
SaveToCharacter();
SendInfo("You have completed the task!");
return true;
};
if (Inventory[i].ObjectId == "Task Tablet 1")
{
Inventory[i] = Manager.GameData.Items[0x42c9];
UpdateCount++;
SaveToCharacter();
return true;
}
}
};
//}
//catch
//{
// {
// SendHelp("You have to have your first 2 slots empty!");
// }
//return false;
//}
};
break;
What's the problem with this? Every time I use it, the reward works but the task tablet doesn't change.
P.S How to put this in 'code' thing again :P ?
Thanks in Advance!
Can you reenter the code in a [CODE] // [/ CODE] format and can you explain what your trying to do and what is happening better... cause its way too hard for me too read the code and problem, too unorganized
Quote Originally Posted by Demon View Post
Can you reenter the code in a [CODE] // [/ CODE] format and can you explain what your trying to do and what is happening better... cause its way too hard for me too read the code and problem, too unorganized
Done :P , I'm new here, didn't know how to do that, thanks!

- - - Updated - - -

Quote Originally Posted by Juix View Post
Also remove anything that is not essential to the code, the // lines just confuse anyone reading it.
I just removed it, it's useless anyways.
Also remove anything that is not essential to the code, the // lines just confuse anyone reading it.
Quote Originally Posted by LordChronos View Post
I tried to add my own 'task system' as in realm resolution source and I wrote some code where if you have the required item, it give you the reward and replaces the 'task tablet' with the next 'task tablet'.
Code:
case ActivateEffects.Task1:
                        {
                            for (int i = 0; i < Inventory.Length; i++)
                                if (Inventory[i].ObjectId == "Dragon Pearl")
                                {
                                    {
                                        if (Inventory[i] == null) continue;
                                        if (Inventory[i].ObjectId == "Dragon Pearl") ;true; }
                                        {
                                            Inventory[i] = Manager.GameData.Items[0x108e];
                                            UpdateCount++;
                                            SaveToCharacter();
                                            SendInfo("You have completed the task!");
                                            return true;
                                        };
                                        if (Inventory[i].ObjectId == "Task Tablet 1")
                                        {
                                            Inventory[i] = Manager.GameData.Items[0x42c9];
                                            UpdateCount++;
                                            SaveToCharacter();
                                            return true;
                                        }
                                    }
                                };
                        };
                        break;
What's the problem with this? Every time I use it, the reward works but the task tablet doesn't change.
P.S How to put this in 'code' thing again :P ?
Thanks in Advance!
First of all your code is extremely dirty and hard to read.
Reading your thread I still can't understand what your trying to do. If you could, please explain it better.

How exactly is your task system supposed to function? And what is it doing?

Normally I would rewrite your code for you, but i'm at school and can't be bothered to do so until I get more details.
I'm sorry about that, I'm new to coding and to pservers in general.
What I wanted the task system to do was that for example if I have the first task tablet, and the item required to complete it (for example a UT or a token or something), when you consume the tablet, it would replace the item required to the reward designated, and the task tablet 1 to the next task tablet.
The whole reward giving mechanic is working but the 'next task tablet' code is unreachable apparently.

- - - Updated - - -

Quote Originally Posted by Demon View Post
extremely dirty and hard to read
I don't see how it's hard to read, but any ideas on how to improve?
Quote Originally Posted by LordChronos View Post
I'm sorry about that, I'm new to coding and to pservers in general.
What I wanted the task system to do was that for example if I have the first task tablet, and the item required to complete it (for example a UT or a token or something), when you consume the tablet, it would replace the item required to the reward designated, and the task tablet 1 to the next task tablet.
The whole reward giving mechanic is working but the 'next task tablet' code is unreachable apparently.

- - - Updated - - -


I don't see how it's hard to read, but any ideas on how to improve?
Let me ask you a question. Is task tablet 1 consumed?

but heres a more organized code
Code:
         for (var i = 0; i < Inventory.Length; i++)
            {
               if (Inventory[i].ObjectId == "Dragon Pearl")
               {
                   Inventory[i] = Manager.GameData.Items[0x108e];
                   Player.SendInfo("Quest Complete");
                   UpdateCount++;
                   SaveToCharacter();
               }
               if(Inventory[i].ObjectId == "Task Tablet 1")
               {
                   Inventory[i] = Manager.GameData.Items[0x42c9];
                   UpdateCount++;
                   SaveToCharacter();  
               }
            }
didn't test it or anything so might not even be functional
Quote Originally Posted by Demon View Post
Is task tablet 1 consumed?
Yup, and I'll test this code once I get my laptop, Thanks!

- - - Updated - - -

Just Checked, though it gives :- "ERROR wServer.realm.LogicTicker - System.*********enceException: Object reference not set to an instance of an object.
at wServer.realm.entities.player.Player.Activate(Real mTime time, Item item, UseItemPacket pkt) in F:\Chronos Realm (AS3)\wServer\realm\entities\player\Player.UseItem .cs:line 1418
at wServer.networking.handlers.UseItemHandler.<>c__Di splayClass2_0.<HandlePacket>b__0(RealmTime t) in F:\Chronos Realm (AS3)\wServer\networking\handlers\UseItemHandler.c s:line 244
at wServer.realm.LogicTicker.TickLoop() in F:\Chronos Realm (AS3)\wServer\realm\LogicTicker.cs:line 84"
But it works and that's the important thing
Code:
                    case ActivateEffects.XmasTablet2:
                        {
                            int LockboxChance = Random.Next(0, 1);
                            Random rand = new Random();
                            string taskname = "";
                            switch (LockboxChance)

                            {
                                case 0:
                                    for (int i = 0; i < Inventory.Length; i++)
                                    {
                                        if (Inventory[i] == null) continue;
                                        if (Inventory[i].ObjectId == "Xmas Santa Hat")
                                        {
                                            Inventory[i] = Manager.GameData.Items[0x441a];
                                            UpdateCount++;
                                            SaveToCharacter();
                                            SendHelp("Next task unlocked!");
                                            TextPacket packet = new TextPacket
                                            {
                                                BubbleTime = 0,
                                                Stars = -1,
                                            };
                                            return false;
                                        }
                                    };
                                    break;
                            }
                            if (taskname == "")
                            {
                                SendHelp("You do not have to correct materials to activate a task.");
                            }
                            else
                            {
                                TextPacket packet = new TextPacket
                                {
                                    BubbleTime = 0,
                                    Stars = -1,
                                    Name = "",
                                    Text = Name + " has activated the task [" + taskname + "]"
                                };
                                Owner.BroadcastPacket(packet, null);
                                SendHelp("Xmas task has been activated!");
                            }
                            return true;
                        }
                        break;
This is what I use for a task system. Is sorta messy but it works. 0x441a in this is the next tablet and it's given if you have "xmas santa hat"
Quote Originally Posted by swankhawk View Post
Code:
                    case ActivateEffects.XmasTablet2:
                        {
                            int LockboxChance = Random.Next(0, 1);
                            Random rand = new Random();
                            string taskname = "";
                            switch (LockboxChance)

                            {
                                case 0:
                                    for (int i = 0; i < Inventory.Length; i++)
                                    {
                                        if (Inventory[i] == null) continue;
                                        if (Inventory[i].ObjectId == "Xmas Santa Hat")
                                        {
                                            Inventory[i] = Manager.GameData.Items[0x441a];
                                            UpdateCount++;
                                            SaveToCharacter();
                                            SendHelp("Next task unlocked!");
                                            TextPacket packet = new TextPacket
                                            {
                                                BubbleTime = 0,
                                                Stars = -1,
                                            };
                                            return false;
                                        }
                                    };
                                    break;
                            }
                            if (taskname == "")
                            {
                                SendHelp("You do not have to correct materials to activate a task.");
                            }
                            else
                            {
                                TextPacket packet = new TextPacket
                                {
                                    BubbleTime = 0,
                                    Stars = -1,
                                    Name = "",
                                    Text = Name + " has activated the task [" + taskname + "]"
                                };
                                Owner.BroadcastPacket(packet, null);
                                SendHelp("Xmas task has been activated!");
                            }
                            return true;
                        }
                        break;
This is what I use for a task system. Is sorta messy but it works. 0x441a in this is the next tablet and it's given if you have "xmas santa hat"
@swankhawk Wait, this seems a bit too complicated and does it need any changes in the database?

- - - Updated - - -

Quote Originally Posted by Demon View Post
Let me ask you a question. Is task tablet 1 consumed?

but heres a more organized code
Code:
         for (var i = 0; i < Inventory.Length; i++)
            {
               if (Inventory[i].ObjectId == "Dragon Pearl")
               {
                   Inventory[i] = Manager.GameData.Items[0x108e];
                   Player.SendInfo("Quest Complete");
                   UpdateCount++;
                   SaveToCharacter();
               }
               if(Inventory[i].ObjectId == "Task Tablet 1")
               {
                   Inventory[i] = Manager.GameData.Items[0x42c9];
                   UpdateCount++;
                   SaveToCharacter();  
               }
            }
didn't test it or anything so might not even be functional
@Demon Here if where the problem lied, you see I wanted the task tablet 1 to change to task tablet 2 only if the character had the item to complete the task.
With your code, if the person uses the tablet without having the item, it just directly switches over to the next task....

And when I tried to fix this problem myself, the code had the "unreachable code detected" error.
Quote Originally Posted by LordChronos View Post
@swankhawk Wait, this seems a bit too complicated and does it need any changes in the database?
No its not complicated. No db change. You consume tablet one and if u have the item it asks for it lets you go to tablet 2. Then to tablet 3 etc. Then when ever the task is complete you get a reward.
Quote Originally Posted by LordChronos View Post
@swankhawk Wait, this seems a bit too complicated and does it need any changes in the database?

- - - Updated - - -


@Demon Here if where the problem lied, you see I wanted the task tablet 1 to change to task tablet 2 only if the character had the item to complete the task.
With your code, if the person uses the tablet without having the item, it just directly switches over to the next task....

And when I tried to fix this problem myself, the code had the "unreachable code detected" error.

Then just add another for () loop in the if statement.

But the reason why it's not working is because Task Tablet 1 is consumed, therefore it doesn't exist anymore, so you'll need to add some checks to make sure they have the required item, before it consumes Task Tablet 1.

oops didn't realize that Activate was a boolean, mabad

Code:
if (Inventory[i] == "Dragon Pearl")
{
    Inventory[i] = Manager.GameData.Items[0x108e];
    Player.SendInfo("Quest Complete");
    UpdateCount++;
    SaveToCharacter();
    for (var i = 0; i<= Inventory.Length; i++)
    {
        if (Inventory[i] == "Task Tablet 1")
        {
            Inventory[i] = Manager.GameData.Items[...];
            return true;
        }
    }
} else {
    Player.SendError("You do not have the required item.");
    return false;
}
I had the exact same idea (though the code needed some work)
Thank you!
@Demon Just a doubt, if I make the item reusable , are the 'checks' not needed?
Update : New error...
Quote Originally Posted by LordChronos View Post
I had the exact same idea (though the code needed some work)
Thank you!
@Ahl Problem solved.
@Demon Just a doubt, if I make the item reusable , are the 'checks' not needed?
No if you made the item reusable then you would come to a whole other set of troubles... if you wanted to change the item requirement on the same item, you would need something like the SD's ItemData which is tough to implement in FSOD.
@Demon dude I'm stupid... I din't really test your code back then and now I have an error : (Attachment not verified) The problem is " 'i' does not exist in the current context.

Now if I try to fix it my way, the previous problem arises.
What should I do?

OOC, I sent you a friend request
Posts 1–15 of 17 · Page 1 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us