Page 1 of 1

Function/Method Examples - API

Posted: Fri Feb 18, 2022 9:35 pm
by Humility
Prototype:
object.SoundEffect(hex,bol);
object.SoundEffect(SoundID, Single player/everyone as a boolean);

srcNPC.SoundEffect(0x170,true); // Plays ettin sound effect for every player in range.
pUser.SoundEffect(0x170,true); // Plays ettin sound effect for every player in range.
iUsed.SoundEffect(0x170,true); // Plays ettin sound effect for every player in range.

srcNPC.SoundEffect(0x170,false); // Plays ettin sound effect for player interacting with NPC
pUser.SoundEffect(0x170,false); // Plays ettin sound effect for this player.
iUsed.SoundEffect(0x170,false); // Plays ettin sound effect for player interacting with this item.

Re: Function/Method Examples - API

Posted: Fri Feb 18, 2022 9:43 pm
by Humility
Prototype:
pUser.DoAction(dec); // Performs a predefined action from the player animations such as casting or bowing.

if ( ! pUser.isMounted) { pUser.DoAction(17); }
if not true that Player.ismounted then Player.DoAction #17

Re: Function/Method Examples - API

Posted: Fri Feb 18, 2022 10:05 pm
by Humility
Prototype:
object.Teleport(dec,dec,dec,dec,dec)
Moves this object to the destination world coordinates if not in a container.
Use:
object.container = null; to remove item from the container to teleport contained objects on the world map.

Example A:
Moving people and livestock.
// Teleport player's pets - lifted from moongate.js
for (var i = 0; i < petList.length; i++) {
      var tempPet = petList[i];
      if (ValidateObject(tempPet) && tempPet.InRange(objTraveller, 12) && tempPet.mounted == false)
      {
      tempPet.Teleport(targX, targY, targZ, targM, tarInstanceID);
      tempPet.Follow(objTraveller);
      }
}
 pUser.Teleport(targX, targY, targZ, targMap, targInstanceID);
Say the preceding code teleports the player to the city of Britain.
This is where we can use example B.

Example B:
Exacting vengeance. >.>
        if (objPlayer.criminal || objPlayer.murderer) {
            var packContents = new Array();
            // What have I done with my life? *empties pack on the ground and stares bleakly at the contents*
            objTraveller.frozen = true;
            objTraveller.TextMessage("*empties pack on the ground and stares bleakly at the contents*")
            for (mItem = objTraveller.pack.FirstItem(); !objTraveller.pack.FinishedItems(); mItem = objTraveller.pack.NextItem()) {
                rndX = RandomNumber(-3, 3);
                rndY = RandomNumber(-3, 3);
                itemZ = objPlayer.z

                if ((ValidateObject(mItem)) && (pUser.CanSee(objPlayer.x + rndX, objPlayer.y + rndY, itemZ))) {
                    mItem.container = null;
                    mItem.Teleport(objPlayer.x + rndX, objPlayer.y + rndY, objPlayer.z, objPlayer.worldnumber);
                }

            }
            objPlayer.frozen = false;
            objPlayer.TextMessage("Guards!!! I wish to turn myself in.")
        }
    }

Re: Function/Method Examples - API

Posted: Fri Feb 18, 2022 10:17 pm
by Humility
Self defining objects and chicanery!
Object.id = hex
if ((iUsed.id == "0x097e") && !(iUsed.id == "0x0976")) { // if cheese and not already bacon
        //So it's, ...  a wheel of cheese?
        //* such magics, much sparkle *
        //nope.
        iUsed.id = "0x0976";
        iUsed.name = "Brackus's Radioactive Peanut Bacon";
        iUsed.dir = 29; //Make it glow like a street lamp
        iUsed.container = pUser.pack; //put it in users pack
        iUsed.moveable = 1; // Make sure it's moveable so they can not die of radiation poisoning.
        [ ... radiation damage code ]

        // oooooooo, ... That IS evil.
        return false;
}

Re: Function/Method Examples - API

Posted: Sat Feb 19, 2022 9:56 am
by Humility
Based on Xuri's fight suppression code.
This is meant to go on the banker.js so you can make them vulnerable regular players but also cut down on 'accidents' by blocking initial melee combat.
//Protect vendors from accidental dblclick attacks but you can still start some $h!7 with spells if you really want to.
function onCombatStart(pAttacker, pDefender){return EndCombat(pAttacker, pDefender);}
function EndCombat( pAttacker, pDefender) {
pDefender.target = null;
pDefender.atWar = 0;
pDefender.attacker = null;
pAttacker.target = null;
pAttacker.atWar = 0;
pAttacker.attacker = null;
pAttacker.criminal=false;
pDefender.criminal=false;
return false;
}

Re: Function/Method Examples - API

Posted: Tue Feb 22, 2022 3:13 am
by Humility
Logic and syntax:

A word of warning:
!pChar.id == 0x0191 is totally different than !(pChar.id == 0x0191)

!pChar.id == 0x0191 does not compare .id and 0x0191 it justs checks that pChar.id exists then compares the true or false to a hex value, ultimately returning the not of that comparison as a boolean;

!(pChar.id == 0x0191) compares .id to the value 0x0191 and then inverts it with a logical not, the ! symbol.

so if in fact the id IS 0x0191 then the answer is false; but if you are anything BUT a female human (0x0191) , you'd get a true; "I'm not a girl!" response.
if (pChar.id == 0x191){  pChar.TextMessage("Yay! I'm a girl!"); }
if (pChar.id == 0x190){  pChar.TextMessage("Yay! I'm a boy!"); }
if (!pChar.id == 0x190){  pChar.TextMessage("Yay! I'll never be able to run this code because true will never equal false"); }
if (   !(pChar.id == 0x191)   ){   pChar.TextMessage("Yay! I'm not a girl! I'm a dude, or , ... a potion, or a troll, or something but I'm not a girl!");}