Prime - Amber Tweaks and Scripting API

Forum for alternative clients, mods & discussions on the same.

Re: Prime - Amber tweaks and Scripting API

Postby lacucaracha » Wed Dec 21, 2016 3:45 am

Paradoxs wrote:Events
Prime will still have events in the next release, but I am debating removing them entirely, feedback would be helpful in the making of this decision.

By events you mean "onCurioFind()", for example? If so, why would you do it?
User avatar
lacucaracha
 
Posts: 171
Joined: Thu Dec 05, 2013 4:50 pm

Re: Prime - Amber tweaks and Scripting API

Postby Paradoxs » Wed Dec 21, 2016 3:58 am

lacucaracha wrote:
Paradoxs wrote:Events
Prime will still have events in the next release, but I am debating removing them entirely, feedback would be helpful in the making of this decision.

By events you mean "onCurioFind()", for example? If so, why would you do it?


Because it forces a task to be made and checked. You usually have one or the other.Instead of OnCurioFound(); (Which only fires once per object I believe, still looking into that) You would have scanForCurios(); which would return a list of map objects that are curiosities. with their location on the map.

I havent decided on removing it yet, and if people really want me to keep it I'll make Prime check the script for what events your looking for and only firing those events.
User avatar
Paradoxs
 
Posts: 294
Joined: Tue Aug 25, 2015 7:16 am

Re: Prime - Amber tweaks and Scripting API

Postby lacucaracha » Wed Dec 21, 2016 4:02 am

Paradoxs wrote:
lacucaracha wrote:
Paradoxs wrote:Events
Prime will still have events in the next release, but I am debating removing them entirely, feedback would be helpful in the making of this decision.

By events you mean "onCurioFind()", for example? If so, why would you do it?


Because it forces a task to be made and checked. You usually have one or the other.Instead of OnCurioFound(); (Which only fires once per object I believe, still looking into that) You would have scanForCurios(); which would return a list of map objects that are curiosities. with their location on the map.

I havent decided on removing it yet, and if people really want me to keep it I'll make Prime check the script for what events your looking for and only firing those events.


Hmm, i see. But that would cause some problems, cause we would have to always call scanForPlayers() to check if there are new players on the screen, and not a single method doing it.
The code would look much worse, and maybe even less eficient.
User avatar
lacucaracha
 
Posts: 171
Joined: Thu Dec 05, 2013 4:50 pm

Re: Prime - Amber tweaks and Scripting API

Postby Paradoxs » Wed Dec 21, 2016 4:16 am

lacucaracha wrote:
Hmm, i see. But that would cause some problems, cause we would have to always call scanForPlayers() to check if there are new players on the screen, and not a single method doing it.
The code would look much worse, and maybe even less eficient.


Right now as it stands though if I have a script that wont complete the main function until it reaches the Docks for example or a mining spot, it wont check for new players at all. They will have been added to a task and that task will be ran just before the main call. Giving functions in my eyes gives you complete control over your script, you could replace sleep with:
Code: Select all
function wait(Miliseconds){
if(ScanForPlayers())
   FoundPlayerFunctionYouMade();
if(ScanForAnimals())
   FoundAnimalFunctionYouMade();
sleep(MiliSeconds);


But like i said, I won't remove them completely unless no one seems to mind, I will be adding generic Scanning Functions that do the job the events do normally. I'll just have prime do a quick scan for OnCurio() and what not so that they can be ignored if you want and used if you want.
User avatar
Paradoxs
 
Posts: 294
Joined: Tue Aug 25, 2015 7:16 am

Re: Prime - Amber tweaks and Scripting API

Postby LostJustice » Wed Dec 21, 2016 6:13 am

Paradoxs wrote:
lacucaracha wrote:
Hmm, i see. But that would cause some problems, cause we would have to always call scanForPlayers() to check if there are new players on the screen, and not a single method doing it.
The code would look much worse, and maybe even less eficient.


Right now as it stands though if I have a script that wont complete the main function until it reaches the Docks for example or a mining spot, it wont check for new players at all. They will have been added to a task and that task will be ran just before the main call. Giving functions in my eyes gives you complete control over your script, you could replace sleep with:
Code: Select all
function wait(Miliseconds){
if(ScanForPlayers())
   FoundPlayerFunctionYouMade();
if(ScanForAnimals())
   FoundAnimalFunctionYouMade();
sleep(MiliSeconds);

But like i said, I won't remove them completely unless no one seems to mind, I will be adding generic Scanning Functions that do the job the events do normally. I'll just have prime do a quick scan for OnCurio() and what not so that they can be ignored if you want and used if you want.

I currently get all map objects and iterate through them, do said action, and then remove the list. Then rinse and repeat. I do not even use the event system because it does occur once per object. I wouldn't mind a scan implementation because that is basically what I use right now and seems to be highly efficient. Also if you need a programming perspective, the game window is consistently updating causing changes which need to be accounted for. Events only fire if a condition has happened but not twice and not if the condition is still a threat (aka a hostile creature or player). I am all for the scan method only if you have a way to get a list of objects by name though or id or w/e.
Image
User avatar
LostJustice
 
Posts: 677
Joined: Sun Mar 25, 2012 3:57 am

Re: Prime - Amber tweaks and Scripting API

Postby Paradoxs » Wed Dec 21, 2016 6:29 am

LostJustice wrote:
Paradoxs wrote:
lacucaracha wrote:
Hmm, i see. But that would cause some problems, cause we would have to always call scanForPlayers() to check if there are new players on the screen, and not a single method doing it.
The code would look much worse, and maybe even less eficient.


Right now as it stands though if I have a script that wont complete the main function until it reaches the Docks for example or a mining spot, it wont check for new players at all. They will have been added to a task and that task will be ran just before the main call. Giving functions in my eyes gives you complete control over your script, you could replace sleep with:
Code: Select all
function wait(Miliseconds){
if(ScanForPlayers())
   FoundPlayerFunctionYouMade();
if(ScanForAnimals())
   FoundAnimalFunctionYouMade();
sleep(MiliSeconds);

But like i said, I won't remove them completely unless no one seems to mind, I will be adding generic Scanning Functions that do the job the events do normally. I'll just have prime do a quick scan for OnCurio() and what not so that they can be ignored if you want and used if you want.

I currently get all map objects and iterate through them, do said action, and then remove the list. Then rinse and repeat. I do not even use the event system because it does occur once per object. I wouldn't mind a scan implementation because that is basically what I use right now and seems to be highly efficient. Also if you need a programming perspective, the game window is consistently updating causing changes which need to be accounted for. Events only fire if a condition has happened but not twice and not if the condition is still a threat (aka a hostile creature or player). I am all for the scan method only if you have a way to get a list of objects by name though or id or w/e.



Don't worry that is certainly a feature. the new implementation of how Prime handles itself should also make things a bit easier. The next update changes quite a bit concerning functions but will set the staple for how functions will be running from here on out. Namely functions now return javascript objects, and "all" will now return false instead of systems where -1 = false and junk like we have now. (All in quotes because I'm sure I missed a one or two)

The scan function and the state of events wont be decided for a little bit, but you are right, the fact that seeing say, an enemy player one makes you go blind to them forever is exactly the problem I have with the event system in the first place, and I dont think there is an easy way to fix it.
User avatar
Paradoxs
 
Posts: 294
Joined: Tue Aug 25, 2015 7:16 am

Re: Prime - Amber tweaks and Scripting API

Postby LostJustice » Wed Dec 21, 2016 8:51 pm

Paradoxs wrote:
LostJustice wrote:
Paradoxs wrote: ~Snip.

I currently get all map objects and iterate through them, do said action, and then remove the list. Then rinse and repeat. I do not even use the event system because it does occur once per object. I wouldn't mind a scan implementation because that is basically what I use right now and seems to be highly efficient. Also if you need a programming perspective, the game window is consistently updating causing changes which need to be accounted for. Events only fire if a condition has happened but not twice and not if the condition is still a threat (aka a hostile creature or player). I am all for the scan method only if you have a way to get a list of objects by name though or id or w/e.



Don't worry that is certainly a feature. the new implementation of how Prime handles itself should also make things a bit easier. The next update changes quite a bit concerning functions but will set the staple for how functions will be running from here on out. Namely functions now return javascript objects, and "all" will now return false instead of systems where -1 = false and junk like we have now. (All in quotes because I'm sure I missed a one or two)

The scan function and the state of events wont be decided for a little bit, but you are right, the fact that seeing say, an enemy player one makes you go blind to them forever is exactly the problem I have with the event system in the first place, and I dont think there is an easy way to fix it.


Code: Select all
function findHostileCreatures()
{
   var mapObjects = Game.getAllMapObjects();
   for (i = 0; i < mapObjects.length; i++) {
      if(mapObjects[i].name == 'bear' || mapObjects[i].name == 'lynx' || mapObjects[i].name == 'badger' || mapObjects[i].name == 'boar' || mapObjects[i].name == 'palisadeseg')
      {
         java.lang.System.out.print("Found a hostile creature!!\n");
         java.lang.System.out.print("Adding it to the list of creatures!\n");
         creatureList.push(mapObjects[i]);
         java.lang.System.out.print("Creature List Length is now: "+creatureList.length+"\n");

      }
   }
}


My simple solution. :)
Image
User avatar
LostJustice
 
Posts: 677
Joined: Sun Mar 25, 2012 3:57 am

Prime - Version 0.2 Release Notes

Postby Paradoxs » Wed Dec 21, 2016 11:08 pm

The latest release has fixes the MapObjects issue and any other issue

to Compare arrays of mapObjects or Items use:
Code: Select all
var List = getMapObjects();
var list2 = getMapObjects();

if(list.equals(list2))
    print("We are equal!");


Version 0.2 Notes
Notice: 0.2 Changes a lot about the API, from function names, and Prime interfaces. I suggest you read these notes or re-view the Readme

New Features

    loadLib(FileName)
    loadLib(FileName) has been added. Scripts will load the contents of a lib file when ran into its own source file.
    Code: Select all
    loadLib("test.js");
    loadLib("Examples/TestLib.js");


Changes to script Requirements

    LoadGame()
    LoadGame has been removed. Scripts no longer require you call it


Changes to reserved Variables and Functions

    Game,_scplayx, _scplayx
    Have been removed. You can now freely give variables these names.

    Channel
    A reserved interface for specifying Chat Channels (see SendChat)

    MouseButton
    A reserved interface for specifying Mouse Buttons (see pfClick)

All Prime functions are now reserved, due to removing the Game object they are now directly usable and conflict-causing functions


New Prime Interfaces

These are objects that prime will return and how you can use them
    Item
    Item has three properties Name, FullName and Coords (Currently Broken)
    Code: Select all
    print(getItem()[0].FullName);


    MapObject
    MapObject has three properties Name, Fullname, Id, Coords
    Code: Select all
    print(getMapObject()[0].Name);


    AttentionInfo
    AttentionInfo stores attention details grabbed with getAttention, it has two properties Total, and Used
    Code: Select all
    print(getAttention().Total);


    HealthInfo
    AttentionInfo stores attention details grabbed with getHealth, it has two properties SHP, and HHP
    Code: Select all
    print(getHealth().HHP);



Removed Functions

    WaitTillStopped
    Became waitToFinish

    studyCurio
    Became study

    dropItemFromHandToWindow
    Became dropTo

    getInvItems
    Became getItems, functions very differently, see new functions below or view Readme

    getPlayerCoords
    Became getCoords

    Pick
    Became pickItem

    travelToHearthFire
    Became hearth

    mapRightClick
    Functionality replaced, see pfClick

    getMapObjects
    Functionality changed to be more dyanmic see readme or new functions below

    getAllMapObjects
    getMapObjects covers this

    getMapObjectsByFullName
    getMapObjects covers this

    getCharAttentionInfo
    Became getAttention

    getHP
    Became getHealth

    sendAreaChatMessage
    sendChat covers this

    sendPartyChatMessage
    sendChat covers this

    sendVillageChatMessage
    sendChat covers this

    sendPrivateChatMessage
    sendChat covers this

    useMenuAction
    Became useActionMenu

    chooseFlowerMenuOption
    Became chooseOption


New Functions
    isStudying(CuriosityName)
    Returns true if player is studying item, otherwise returns false.

    hasItem(ItemName)
    Returns true if playerhas item, otherwise returns false.

    getItem(Item)
    Takes a Item name and returns a Item object from inside player inventory that match returns empty array otherwise.

    getItems(Item)
    Take a Item name and returns a list of Item objects from inside player inventory that match. If not item is passed returns a list of all inventory items. returns empty array otherwise

    drink(Container)
    Takes a item name and drinks from that object specifically

    setSpeed(Speed)
    Takes a number from 0 to 3, 0 being crawl and 3 being sprint. returns true if speed is set, returns false otherwise.

    sendChat(Message, Channels, Who)
    sendChat is dynamic, requires Message, others can be left out. If Message is passed Channel defaults to Channel.Area
    Code: Select all
    sendChat("Hey bessie");

    You can choose to pass a Channel, these are
    • Channel.Area
    • Channel.Party
    • Channel.Village
    • Channel.Private

    if channel is Channel.Private you must then pass a Who for the name of the kin you wish to message, if no who is passed it will return false

    getMapObjects(Name, Fullname)
    getMapObjects doesn't require any of its parameters to be passed, if left empty it will return a list of MapObjects containing all map objects
    Code: Select all
    var Map = getMapObjects();

    if you pass name, you can pinpoint the name of an object such as "rowboat"
    passing any value to Fullname (true, "faf" 56 ecr) will cause the map to interpret Name as a FullName returning a list

    returns an array, empty if none are found

    pfClick(Object, Button, Shift)
    Only Object has to be specified.
    if Button is not passed it will left click the MapObject

    MouseButtons
    • MouseButton.Left
    • MouseButton.Right

if you pass anything to Shift pfClick will shift click the object.
User avatar
Paradoxs
 
Posts: 294
Joined: Tue Aug 25, 2015 7:16 am

Re: Prime - Amber tweaks and Scripting API

Postby LostJustice » Thu Dec 22, 2016 6:19 am

I like the update. Definitely a thumbs up for it. Updated my script and things are working a lot better now.
Image
User avatar
LostJustice
 
Posts: 677
Joined: Sun Mar 25, 2012 3:57 am

Re: Prime - Amber tweaks and Scripting API

Postby Paradoxs » Thu Dec 22, 2016 9:54 am

LostJustice wrote:I like the update. Definitely a thumbs up for it. Updated my script and things are working a lot better now.


I'm glad to hear it! I'm currently working on a number of things to improve it as I go. It still doesn't do everything I personally would like it but I think we have a good start. Keep me updated with requests and suggestions. Theres still a ton of work to do before we hit Version 1.0 on both the scripting API side and the general client tweaks and changes

I should also have noted all objects have a special print function.

So if you say do
Code: Select all
print(getAttention());


instead of being greeted with
[object object]


you'll see a print-out that will give you actual information, making debugging and reporting easier
User avatar
Paradoxs
 
Posts: 294
Joined: Tue Aug 25, 2015 7:16 am

PreviousNext

Return to The Wizards' Tower

Who is online

Users browsing this forum: Ahrefs [Bot], Claude [Bot] and 379 guests