Status
Not open for further replies.
I'm trying to add a [fill command that calls Fill(Mobile m) for the Master Storage Key. Can someone point me to the right way to reference the mobile in this command. I have never worked much with commands and keep getting "an object reference is required for the non-static... "

This is what I have...

Code:
public class Fill
{
public static void Initialize()
{
CommandSystem.Register("fill",AccessLevel.Player,new CommandEventHandler(Fill_Callback));
        }
        [Usage("fill")]
[Description("Call fill method")]
public static void Fill_Callback(CommandEventArgs e)
{

// reference


MasterItemStoreKey.Fill(pm);
}  }

This is the method I am trying to make the command call...

Code:
//these are accessed through the context menu use
public void Fill( Mobile from )
{
if( _KeyTypes == null )
{
return;
}

FillEntriesFromBackpack( from );

}

Thanks
 
This is barely helpful info, like you dont even say how you want it to work in the first place.
To reference the Mobile itself? You get that from the CommandEventArgs. But you do not have a reference to the key there.

Also you do not need a class Fill, put this in your mastet key storage itself, why create a class for that?
Furthermore I dont even know how the actual class is called for the master storage so I went with MasterItemStoreKey since I was
not sure if that was your variable name or the name of the class itself.

Generally if you have something you want to do and you already have something similar and you know it works. Take a look at it
and see how it works. Then you can copy and adapt it to your needs. Help with learning as well as you basically disect the other code
to see how it actually works and why.

Lastly here is an example, not sure if it works with your class name for the storage key, this example will give you a target and you
have to target the key itself. You could also go and check the mobiles backpack and find the key that way.


C#:
    public static void Initialize()
    {
        CommandSystem.Register("fill",AccessLevel.Player,new CommandEventHandler(Fill_Callback));
    }

    [Usage("fill")]
    [Description("Call fill method")]
    public static void Fill_Callback(CommandEventArgs e)
    {
        e.Mobile?.Target = FillStoreKeyTarget();
    }

    private class FillStoreKeyTarget : Target
    {
        private static Mobile m_Mobile;
        public FillStoreKeyTarget()
            : base(-1, false, TargetFlags.None)
        { }

        protected override void OnTarget(Mobile from, object targeted)
        {
            if (targeted is MasterItemStoreKey)
            {
                MasterItemStoreKey key = (MasterItemStoreKey)targeted;

                if(!key.Movable)
                {
                    from.SendMessage("You have no access to this Storage Key.");
                }
                if (!from.InRange(key.GetWorldLocation(), 3))
                {
                    from.SendLocalizedMessage(500446); // That is too far away.
                    return;
                }
                else if (!key.IsChildOf(from.Backpack))
                {
                    from.SendMessage("You need to carry the Storage Key in your backpack.");
                    return;
                }
                key.Fill(from);
            }
        }
    }
 
I thought I explained my intention when I said I'm trying to add a command to the master key that would call the key's fill command which I put in a second code tag. It's pretty obvious that I did attempt to try to figure out how to do it on my own. This is why I never ask questions and should have went with my hunch of not asking here. Thanks.
 
This is barely helpful info, like you dont even say how you want it to work in the first place.
To reference the Mobile itself? You get that from the CommandEventArgs. But you do not have a reference to the key there.

Lastly here is an example, not sure if it works with your class name for the storage key, this example will give you a target and you
have to target the key itself. You could also go and check the mobiles backpack and find the key that way.

Well I said this, since there are multiple ways to go and fill it by a command, you never say anything of how it should work. So yes
it is barely any info.

And I even gave you an example of how you could go for it, but oh well. Here have some ..
 
Ofc, ofc, surely it has to do with being liberal...
Pyro sent you everything you need to get it to work, do your part.
Good luck with the rest.
 
I simply asked a question and gave the method that I wanted to call from a command and get jumped. I knew that would probably happen, but if you don't want me to reply like a smart ass don't jump all over me for asking a fucking question. Could have just asked me to clarify instead of going full on elitist.
 
I know you back from RunUO, I have my reasons to not appreciate you, surely i am not the only one.
Rest assured, I don't have any ill intentions towards you, i would have helped you if you didn't make a politics related remark and spit on his help.

Let me explain how i've seen this conversation :
  1. You asked for help, it wasn't clear to me as i've never worked with the master storage before.
  2. You only provided a general idea of what you wanted to accomplish "I want X to reference Y", i've then noticed you just placed variables with precise names in the code, it seemed like the result of 5 minutes of tinkering around.
  3. You get scolded for not providing enough info about what you want to do or what you tried.
  4. You complain that you get scolded, and get in a sulking phase, refusing any help (despite having the help already).


I can't explain why Pyro replied like this, i'm not in his mind and i'm not interested to know. However, keep in mind that Pyro gains nothing from helping you, i can only interpret it as a "may as well throw him in the right direction". Seeing your replies, i doubt you would get help in the future if you keep that attitude, Pyro went out of his way to provide help and yet he did that, apparently, for nothing.
If you get insulted, please don't make a scene and sulk in a corner, talk it out correctly without pointing fingers like you did above.
Escaping a situation like this can only cause more conflict down the road, and more conflict leads to even more conflicts.

So, here are my final questions before i probably stop posting:
* Do you want to enhance your appreciation of the community?
* Do you want to improve your coding skill?
* Do you want help or not?
 
Once again, I tried to ask a question and got jumped and now I'm getting a history lesson on my past. You can rest assured I'll not ask for any help again. That is 100% sure. I didn't come here to get yelled at and any past of mine drug out to teach me a lesson.
 
I'm not yelling at you.
I'm not digging your past out.
Yes, i'm trying to teach you a lesson so you can be a bit more expressive instead of simply fleeing conflictual situations.

I guess i will stop if you don't want to get any help.
 
Idk, I see nothing wrong with what I wrote.
I am not from a country where you sugar coat every single word, and an attempt that should be nothing more than an attempt at an attempt idk.

I didnt insult nor anything. What I told him is the truth. His whole "help me pls" thread lacks any concrete info of what and how he wants it, yet he got an example and whines. So since he was whining, why not give a tissue? I am not his babysitter.

Apparently he is over 40 years old? And well his avatar says he is an veteran? Dont make me laugh.
And anyway I put him on the ignore, cant see his posts, soo its whatever. Let him whine, let him badmouth me or whatever idk.
 
The master keys already have a context menu for Fill. My interpretation is that TheDoc is looking for a command equivalent to call that method, presumably so people can macro it with a "say" macro.

I've also noticed that any time someone asks for coding advice people tend to go into poo-flinging mode. It's like email lists from the 90s when people didn't read the FAQs first. There's always somebody ready to scream at the perpetrator. If you don't want to answer someone, just don't post. That'll show 'em.

I'm far from a great programmer but I've blundered my way into some pretty decent results over the years. I'm stuck on the same part he is -- how to reference the specific master keys you want to target. You do want to do a Find because you know some players will try the command without having master keys or they'll have more than one.

Here's what I've mashed out in ~ 30 mins:

Code:
using System;
using Server;
using System.Collections;
using System.Collections.Generic;
using Server.Items;
using Server.Mobiles;
using Server.Targets;
using Server.Network;
using Server.Targeting;
using Server.Commands;
using Solaris.ItemStore;

namespace Server.Scripts.Commands
{
    public class Fill
    {
        public static void Initialize()
        {
            Register( "Fill", AccessLevel.GameMaster, new CommandEventHandler( FillCommand ) );
        }
        public static void Register( string command, AccessLevel access, CommandEventHandler handler )
        {
            CommandSystem.Register( command, access, handler );
        }

        [Usage( "Fill" )]
        [Description( "Fills master keys from command" )]
        public static void FillCommand ( CommandEventArgs e )
        {
    Mobile from = e.Mobile;

    Item masterkeys = from.Backpack.FindItemByType(typeof(MasterItemStoreKey)); 

    if (masterkeys != null )
        {
        masterkeys.Fill(from);
        }    
        }

    }
}

This doesn't work yet. It yields:
Code:
CS1061: Line 41: 'item' does not contain a definition for 'Fill' and no extension method 'Fill' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

It boils down to the right way to call the Fill command for the found item (or object; I tried that too). I'm not experienced enough for it to come to mind just yet but I could figure it out with another few dozen attempts. I know one thing for sure -- I would definitely keep taking a stab at it before asking for help with this kind of reception committee!
 
Still not seeing where I went on him, befor he brought out his tears?

Anyway, your way is almost there, what you are missing in the code is the cast so that it knows that the masterkeys Item is an MasterItemStoreKey

So like this:
C#:
public static void FillCommand ( CommandEventArgs e )
{
    Mobile from = e.Mobile;

    Item masterkeys = from.Backpack.FindItemByType(typeof(MasterItemStoreKey));

    if (masterkeys != null )
    {
        ((MasterItemStoreKey)masterkeys).Fill(from);
    }
}
 
Thank you Falkor. I had tried to figure it out on my own. I appreciate the help and not resorting to the crap these two continue to. Thanks again. You're right, I should have kept on trying on my own instead of asking here and it definitely will be the last time I ever ask.
Post automatically merged:

And yeah Pyro I am a veteran. That somehow means I can't get upset at a fucking dick like you and Pookie?
 
Stay on topic please. Also this forum is not the avenue to talk about or bring up American politics or policy. While the US makes up a lot of traffic to ServUO it is still less than 20% of the total traffic, this site does not have the audience for American or any countries politics.
 
Well, since we're so insignificant and asking a question leads to shit talking, I'll donate the $30 a month I was here somewhere where they will appreciate it. Feel free to delete this account.
 
I was trying to keep your thread on topic so you could get the help you are looking for. You canceled your donations already days ago so not sure why you are mentioning it now? Thanks again for the donation it was appreciated but we will still be here without it :)

ServUO is not for discussion around any countries politics or policy, there are more appropriate mediums out there for that. If you want to take that as thinking your country is insignificant then that is your prerogative but that is not the case. At all.

Closing this thread now as it is veered way off course. If you want to continue with the conversation please feel free to PM me.
 
Status
Not open for further replies.
Back