Page 1 of 1

Custom Js command "WHAT" not registering

Posted: Mon Nov 21, 2016 8:05 am
by Humility
I have been looking up and down the forums, I realize this is not the most active forum now but in the hopes someone still looks once in awhile.

I just wanted to say 'what and click an item and have it remind me of what it's ID is.

Code: Select all

function CommandRegistration()
{
	RegisterCommand( "what", 1, true );
}

function command_WHAT( socket )
{
	var targMsg = "Select a target to display id.";
	socket.CustomTarget( 0, targMsg );
}

function onCallback0( socket, ourObj )
{
	if (ourObj != null)
	{
		var idTempHex = ourObj.id.toString(16);
		var idTempDec = ourObj.id.toString(10);
		socket.SysMessage( "Target is, Hex 0x" + idTempHex.toUpperCase() );
		socket.SysMessage( "Target is, Dec   " + idTempDec );
		return;
	}
	else
	{
		socket.SysMessage( "Selected target is null. (likely terrain)" )
	}
}

No matter how many times I reload things or where in the js directory I put the file what.js the server keeps telling me "unrecognized command"
*edit*
Fixed thx to Xuri.
I updated the code comment with my finished product in case anyone later is interested in it.

This version displays the hexadecimal and decimal ID values with error checking for miss-clicks.

Here is a more featured version of WHAT that takes a property argument as well and gives back more than just the ID without having to navigate like tweak.

Code: Select all

// ****Command Map****
// | register command
// | On Command Called
// | On Callback
// ---|Parse command string
// ---|Select subfunction
// ________________________
// |fn UI constructor





function CommandRegistration()
{
	RegisterCommand( "what", 2, true );
}

function command_WHAT( objSocket, strCommand )
{
    objSocket.xText = strCommand; // preserve the command text for callback
    var targMsg = "Select a target to get information about.";
	objSocket.CustomTarget( 0, targMsg ); //get target
}

function onCallback0(objSocket, objTarget) {
    if (objSocket.GetWord(1)) {
        objSocket.SysMessage("'What': Invalid target");
        return;
    }

    var strSplit = objSocket.xText.split(" ", 2);
    var uKey = strSplit[0].toUpperCase();
    switch (uKey) {
//_______________________________________________________________________________________________________
// Identity Properties
        case "NAME":
            objSocket.SysMessage("Target Name is, " + objTarget.name);
            break;

        case "NAME2":
        case "TITLE":
            var strPropertyContents;
            if (objTarget.isItem == true) {
                strPropertyContents = objTarget.name2;
                if (strPropertyContents == "") { strPropertyContents = "[Empty]"; } else { strPropertyContents = "' " + strPropertyContents + " '"; }
                objSocket.SysMessage("Target Name2 is, " + strPropertyContents);
                break;
            }
            else if (objTarget.isChar == true) {
                strPropertyContents = objTarget.title;
                if (strPropertyContents == "") { strPropertyContents = "[Empty]"; } else { strPropertyContents = "' " + strPropertyContents + " '"; }
                objSocket.SysMessage("Target Title is, " + strPropertyContents);
                break;
            }
            objSocket.SysMessage("Target <type unknown>, attempting to get data.");
            if (objTarget.name2 != null) {
                strPropertyContents = objTarget.name2;
                if (strPropertyContents == "") { strPropertyContents = "[Empty]"; } else { strPropertyContents = "' " + strPropertyContents + " '";}
                objSocket.SysMessage("Name2 property present, value =" + objTarget.name2);
            }
            if (objTarget.title != null) {
                strPropertyContents = objTarget.title;
                if (strPropertyContents == "") { strPropertyContents = "[Empty]"; } else { strPropertyContents = "' " + strPropertyContents + " '"; }
                objSocket.SysMessage("Title property present, value =" + objTarget.title);
            }

            break;

        case "COLOR":
        case "COLOUR":
            var strTempHex = objTarget.colour.toString(16);
            var strTempDec = objTarget.colour.toString(10);
            objSocket.SysMessage("Target Color is, Hex:  " + strTempHex);
            objSocket.SysMessage("Target Color is, Dec:  " + strTempDec);
            break;

        case "ID":
            var idTempHex = objTarget.id.toString(16);
            var idTempDec = objTarget.id.toString(10);
            objSocket.SysMessage("Target is, Hex 0x" + idTempHex.toUpperCase());
            objSocket.SysMessage("Target is, Dec   " + idTempDec);
            break;

        case "KARMA":
            objSocket.SysMessage("Target Karma is, " + objTarget.karma);
            break;

        case "KILLS":
            objSocket.SysMessage("Target Murdercount is, " + objTarget.murdercount);
            break;


        case "OWNER":
            objSocket.SysMessage("Target Owner is, " + objTarget.owner);
            break;
        //_______________________________________________________________________
        // Location subcommand
        case "LOCATION":
        case "X":
        case "Y":
        case "Z":
        case "MAP":
        case "WORLD":
        case "WORLDNUMBER":
        case "WHERE":
            objSocket.SysMessage("Target location (x,y,z,worldnumber) is, " + objTarget.x + "," + objTarget.y + "," + objTarget.z + "," + objTarget.worldnumber);
            break;

        case "CONTAINER":
            // Make a noise as the gump opens 
            objSocket.currentChar.SoundEffect(0x58, false);
            fnDisplayUI(objSocket, objSocket.currentChar, objTarget);

            objSocket.SysMessage("Target Container is, " + objTarget.container.id);
            break;


        //_______________________________________________________________________________________________________
        // Amount property
        case "AMOUNT":
            if (objTarget.isItem == true) { objSocket.SysMessage("Target Amount is, " + objTarget.amount); }
            if (objTarget.isChar == true) { objSocket.SysMessage("Target is a character, Amount is undefined."); }
            break;


        //_______________________________________________________________________________________________________
        // Stats
        case "STR":
        case "STRENGTH":
            objSocket.SysMessage("Target Strength is, " + objTarget.strength);
            break;

        case "DEX":
        case "DEXTERITY":
            objSocket.SysMessage("Target Dexterity is, " + objTarget.dexterity);
            break;

        case "INT":
        case "INTELLIGENCE":
            objSocket.SysMessage("Target Intelligence is, " + objTarget.intelligence);
            break;

        case "FAME":
            objSocket.SysMessage("Target Fame is, " + objTarget.fame);
            break;

        case "HP":
        case "HEALTH":
            objSocket.SysMessage("Target Health is, " + objTarget.health);
            break;

            //_______________________________________________________________________________________________________
            // TEMP STATS properties
        case "TEMPSTR":
        case "TEMPSTRENGTH":
            objSocket.SysMessage("Target.tempstr is, " + objTarget.tempstr);
            break;

        case "TEMPINT":
        case "TEMPINTELLIGENCE":
            objSocket.SysMessage("Target.tempint is, " + objTarget.tempint);
            break;

        case "TEMPDEX":
        case "TEMPDEXTERITY":
            objSocket.SysMessage("Target.tempdex is, " + objTarget.tempdex);
            break;

        //_______________________________________________________________________________________________________
        // Serial property
        case "SERIAL":
            var strTempHex = objTarget.serial.toString(16);
            var strTempDec = objTarget.serial.toString(10);
            objSocket.SysMessage("Target Serial is, Hex:  " + strTempHex);
            objSocket.SysMessage("Target Serial is, Dec:  " + strTempDec);
            break;

        //_______________________________________________________________________________________________________
        // Script trigger property
        case "SCP":
        case "SCRIPT":
        case "SCPTRG":
        case "SCPTRIG":
        case "SCPTRIGID":
        case "SCPTRIGGER":
        case "TRIGGER":
        case "SCRIPTTRIGGER":
            objSocket.SysMessage("Target Scriptid is,  " + objTarget.scripttrigger);
            break;

            //_______________________________________________________________________________________________________
// WIPEABLE property
        case "WIPABLE":
        case "WIPEABLE":
            objSocket.SysMessage("Target.wipable status is, " + objTarget.wipable);
            break;
//_______________________________________________________________________________________________________
// VISIBLE property

        case "VISIBLE":
        case "HIDING":
        case "HIDDEN":
            objSocket.SysMessage("Target.hidden value is, " + objTarget.visible);
            if (objTarget.visible == 0) { objSocket.SysMessage("Target is visible"); }
            if (objTarget.visible == 1) { objSocket.SysMessage("Target is stealthed"); }
            if (objTarget.visible == 2) { objSocket.SysMessage("Target is invisible"); }
            if (objTarget.visible == 3) { objSocket.SysMessage("Target is GM hidden"); }
            break;
        //_______________________________________________________________________________________________________
        // Type property
        case "TYPE":
            objSocket.SysMessage("Target Type is, " + objTarget.amount);
            break;
        //_______________________________________________________________________________________________________
        // More property
        case "MORE":
            objSocket.SysMessage("Target More is, " + objTarget.amount);
            break;
        //_______________________________________________________________________________________________________
        // Morex property
        case "MOREX":
            objSocket.SysMessage("Target Morex is, " + objTarget.amount);
            break;
        //_______________________________________________________________________________________________________
        // Morey property
        case "MOREY":
            objSocket.SysMessage("Target Morey is, " + objTarget.amount);
            break;
        //_______________________________________________________________________________________________________
        // Morez property
        case "MOREZ":
            objSocket.SysMessage("Target Morez is, " + objTarget.amount);
            break;

        case "MOVABLE":
        case "MOVEABLE":
            objSocket.SysMessage("Target.movable value is, " + objTarget.movable);
            if (objTarget.visible == 0) { objSocket.SysMessage("Target is moveable"); }
            if (objTarget.visible == 1) { objSocket.SysMessage("Target is stealable"); }
            if (objTarget.visible == 2) { objSocket.SysMessage("Target is locked down"); }
            if (objTarget.visible == 3) { objSocket.SysMessage("Target is on GM lockdown"); }
            break;
            //_______________________________________________________________________________________________________
        // property
        case " ":
            if (objTarget.isItem == true) { objSocket.SysMessage("Target   is, " + objTarget.amount); }
            if (objTarget.isChar == true) { objSocket.SysMessage("Target is a character,   is undefined."); }
            break;



        default:
            objSocket.SysMessage("Requested information not handled.");
            break;
    }
}

function fnDisplayUI(objSocket, objPlayer, objTarget)
{
    var myGump = new Gump;
    myGump.AddPage(1);
    myGump.AddGump(0, 0, 0x899);
    // Page fits 20x14 characters x,y
    myGump.AddText(31, 10, 0, "   Container Info   ");
    myGump.AddText(31, 31, 0, "Name"); myGump.AddText(101, 31, 0, objTarget.container.name); 
    var strTempHex = objTarget.id.toString(16);
    myGump.AddText(31, 42, 0, "ID"); myGump.AddText(101, 42, 0, "0x"+strTempHex);
    myGump.AddText(31, 53, 0, "X" ); myGump.AddText(101, 53, 0, objTarget.container.x);
    myGump.AddText(31, 64, 0, "Y"); myGump.AddText(101, 64, 0, objTarget.container.y);
    myGump.AddText(31, 75, 0, "Z "); myGump.AddText(101, 75, 0, objTarget.container.z);
    myGump.AddText(31, 86, 0, "World"); myGump.AddText(101,86, 0, objTarget.container.worldnumber);
    myGump.AddText(31, 97, 0, "Type"); myGump.AddText(101,97, 0, objTarget.container.type);
    myGump.AddText(31, 108, 0, "Weight"); myGump.AddText(101, 108, 0, objTarget.container.weight);
    myGump.AddText(31, 119, 0, "MaxWgt"); myGump.AddText(101,119, 0, objTarget.container.weightMax);
    myGump.AddText(31, 131, 0, "BaseWgt"); myGump.AddText(101, 131, 0, objTarget.container.baseWeight);
    myGump.AddText(31, 142, 0, "Owner"); myGump.AddText(101, 142, 0, objTarget.container.owner);
    var strTempHex = objTarget.colour.toString(16);
    myGump.AddText(31, 153, 0, "Color"); myGump.AddText(101, 153, 0,"0x" + strTempHex);
 
    myGump.Send(objSocket); //send to player

}

Re: Custom Js command "WHAT" not registering

Posted: Mon Nov 21, 2016 11:43 am
by Xuri
Hey, I still read from time to time :)

Did you add the .js file containing your custom command to the jse_fileassociations.scp file? There's a [COMMAND_SCRIPTS] section in that file, just add a new entry for your .js file with a unique ID.

Example:
[COMMAND_SCRIPTS]
{ // 1000-1499
1000=commands/custom/travel.js
1001=commands/custom/repeatingcmds.js
1002=commands/custom/misc-cmd.js
1003=commands/reload.js
1004=commands/resend.js
... snip ...
1100=commands/custom/mycustomfile.js
}

Re: Custom Js command "WHAT" not registering

Posted: Mon Nov 21, 2016 3:20 pm
by Humility
HE LIVES! Thank you so much for the response!

I kind of squirreled out I guess and missed that. It's so great that you still support this project.

On a side note, would you perchance be able to help with the includes? I am having missing file errors with
the source code in Visual Studio, I have been dying to tear into this for a long time and can never seem to get my IDE to cooperate since one random version of .77

Re: Custom Js command "WHAT" not registering

Posted: Tue Nov 22, 2016 2:17 pm
by Xuri
What version of Visual Studio are you using? I haven't really setup UOX3 with any newer version than 2005, so I'm not sure if the instructions in the second post here are still valid for newer versions...

Re: Custom Js command "WHAT" not registering

Posted: Tue Nov 22, 2016 11:43 pm
by Humility
I Have tried VS 2005 201 2013 and 2015 community this is the current error log for UOX3.CPP
I managed to get everything from the CVS but there seems to be something amiss inside my cstdio a stdio files.
  • Severity Code Description Project File Line Suppression State
    Error (active) expected a ';' UOX3_Official c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cstdio 53
    Error (active) #error directive: Macro definition of snprintf conflicts with Standard Library function declaration UOX3_Official c:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\stdio.h 1927
    Error (active) the modifier "__inline" is not allowed on this declaration UOX3_Official c:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\stdio.h 1932
    Error C1189 #error: Macro definition of snprintf conflicts with Standard Library function declaration UOX3_Official c:\program files (x86)\windows kits\10\include\10.0.10240.0\ucrt\stdio.h 1927

Re: Custom Js command "WHAT" not registering

Posted: Wed Nov 23, 2016 4:17 am
by Xuri
There might be other errors that will need fixing in a modern version of Visual Studio, but one thing you can do is open platform.h and change the following code...

Code: Select all

#		define snprintf _snprintf
...to this...

Code: Select all

#		if _MSC_VER < 1900
#			define snprintf _snprintf
#		endif
#		if _MSC_VER >= 1900
#		  define STDC99
#		endif
Since snprintf is officially defined/supported since Visual Studio 14, it should no longer be redefined as _snprintf. Or something. Source: VS 2015 compiling cocos2d-x 3.3 error “fatal error C1189: #error: Macro definition of snprintf conflicts with Standard Library function declaration”

Re: Custom Js command "WHAT" not registering

Posted: Thu Nov 24, 2016 1:54 am
by Humility
big thanks for that and yeah, more errors it's not defining the types now.
I was considering dedicating an old laptop to be a dev machine for this. perhaps I'll put XP and 2005 on it or somthing