onPlayerGameObjectHitEvent / onPlayerHitItemEvent / onPlayerObjectInteractionEvent not working for me?

  • Rising World: Version 0.7.0.3 Preview (202402211)

    Environment: Linux

    Singleplayer


    Hello, I'm new to writing rising world plugins so I'd assume I'm doing something wrong, maybe you can give me a hint.

    I did manage to create a plugin and it is loaded by the game now I'd like to do some actions whenever a player picks up e.g. a stone or plant or if a tree is hit.


    For what I do understand in order to catch those events the events onPlayerGameObjectHitEvent / onPlayerHitItemEvent / onPlayerObjectInteractionEvent should be listened to.


    I did add a functions to my code

    Code
    @EventMethod
    public void onPlayerGameObjectHitEvent(PlayerGameObjectHitEvent event)
    {
    System.out.println(this.getName() + ": onPlayerGameObjectHitEvent");
    }

    I didn't change anything else to the basic plugin example, yet I never see the message which should be sent here.


    When I add following code:

    Code
    @EventMethod
    public void onPlayerPickupItemEvent(PlayerPickupItemEvent event)
    {
    System.out.println(this.getName() + ": onPlayerPickupItemEvent");
    }

    I do see the message in log a soon as I pickup a trunk.


    Does anyone have a hint towards what I'm doing wrong?


    Thanks

  • Ich habe es nicht getestet, aber es sollte funktionieren.
    I haven't tested it, but it should work.

    Code
    @EventMethod
    public void onPlayerGameObjectHitEvent(PlayerGameObjectHitEvent event)
    {
    Player player = event.getPlayer();
    GameObject oGO = event.getGameObject();
    Vector3f fVec = event.getHitPosition();
    int iObjectID = oGO.getID();
    player.sendTextMessage("Player "+player.getName()+" hit " + iObjectID);
    }



    see also:

    JavaDoc: PlayerGameObjectHitEvent

    JavaDoc: GameObject

    Wiki: Eclipse_Entwicklungsumgebung

    Es wird alles gut :) früher oder später :D meistens später :nerd: ... ich wandle Kaffee in Quelltext um.

    Und besucht die Rising World Wiki

  • I tried your code but don't receive any message either.

    I just realized I didn't tell about me running rising world on linux in singleplayer. Not sure if it makes a difference. I added that information to the upper post too.

  • There might be some confusion regarding the PlayerGameObjectHitEvent: it's only triggered if a player hits a GameObject, i.e. a custom element spawned via the API. Unfortunately this doesn't apply to built-in game elemnts like plants or objects. To get the hit events for them, you can check out the events in the net.risingworld.api.events.player.world package: https://javadoc.rising-world.n…orld/package-summary.html


    When it comes to static world elements, the game distinguishes between vegetation (plants, trees, but for technical reasons also naturally spawned boulders, tree trunks etc), objects (furniture, doors, workbenches) and construction elements (blocks, windows etc).


    For example, the PlayerHitVegetationEvent is triggered when the player hits a plant or a tree with a tool or weapon, the PlayerHitObjectEvent is triggered when the player hits an object element (e.g. furniture, workbenches, doors etc), the PlayerHitConstructionEvent is triggered when the player hits a construction element (e.g. a block) and the PlayerHitTerrainEvent is triggered when the player hits the ground/terrain ;)


    When it comes to interactions (i.e. the player presses the interaction key [F] while looking at an element), you can only listen for Npcs (PlayerNpcInteractionEvent), objects (PlayerObjectInteractionEvent) and players (PlayerPlayerInteractionEvent) for now.


    Picking up elements is handled a bit different: There is a PlayerPickupItemEvent (called when the player picks up an item lying on the ground, e.g. a pickaxe, weapon, food, resources etc, basically everything that goes to the inventory). But if the player picks up a static world element (e.g. a plant) or dismantles furniture or blocks, there are some additional events which are called: PlayerRemoveVegetationEvent (when the player harvests or picks up a plant), PlayerRemoveObjectEvent (when the player deconstructs an object, either with the sledgehammer or by holding F) and PlayerRemoveConstructionEvent (when the player deconstructs a block with the sledgehammer) ^^

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!