Using broadcast events

marceloSRmarceloSR REGISTERED Posts: 47 Seed
edited November 2015 in Mods
I'm trying to use the event NKBroadcastEventToClassInRadius for my mod but it is not triggering anything.

My goal is to make the server running the mod broadcast an event to all clients using my mod script. The event will be called every time an object is destroyed in order to detect which player was near that object and assign the harvesting act to him.
This is not the perfect approach since two players can be near the object while it is destroyed. However, I could not find any other better approach using other functions.

Anyway, going back to the main point. I'm trying to broadcast the event every time the function PlaceableObject.OnDestroy is called. The function is being overwritten correctly as all the other things are happening, the only thing that do not work is the broadcast event.
PlaceableObject.OnDestroy = function (self)

	Eternus.EventSystem:NKBroadcastEventToClassInRadius("ServerCall_ObjectDestroyed", "VakariModMain", self:NKGetWorldPosition(), 200.0, self)
	Eternus.EventSystem:NKBroadcastEventToClassInRadius("GoToMenu", "LocalPlayer", self:NKGetWorldPosition(), 200.0)


	PlaceableObject_OnDestroy (self)
I've tried broadcasting to a class that is not my mod (GoToMenu in LocalPlayer) but this does not seem to work as well. I made sure to check that the object World Position is correct based on the player current position.

Does anyone has any ideas on how to use the broadcast events properly?

Thank you,


  • RawrRawr REGISTERED, Tester Posts: 511 Seed
    edited November 2015
    If you don't mind sharing what your end goal is, I might be able to advise a better approach.

    From what I can gather though, it sounds like you'd like to index player's and on detecting particular interactions increase some values. I would say look into the localplayer.lua or networkplayer.lua as well as the equipable.lua scripts. From there, you could create some mixin's to add in the logic to increase the index's values. I would steer clear of Broadcasting Events, unless of course your end goal has a good reason to do so.
    Programmer, designer, artist.
  • marceloSRmarceloSR REGISTERED Posts: 47 Seed
    My end goal is to detect when a player destroys one object (tree, rocks, etc..) and them call an event to save what item was destroyed and what player did it (name, position).
    This is again for the mod I'm currently working on to gather player data for my thesis.

    These are some functions I already looked into but they won't completely solve my problem.

    LocalPlayer:SwingEquippedItem( ), this function is called only if the primary action engaged and it was not picking up an object. It happens on the client. If the item equipped is instance of equipable call the swing animation. However it does not return the object it collided with. I believe all collisions are handled in the server side only.

    TUGGameModeUIView:TargetAcquired, this function calls the progress bar when the player sees something that can be interact with.
    TUGGameModeUIView:ChangeTargetHitPoints( targetObject ), this function updates the bar hit points and receives the object as information so it can know the % of the bar to display. Called every time an object bar is displayed.
    Both these functions do not work because they only ray cast to the player view and get what is there. There is no way to differentiate when the player actually destroyed an object or if it just stopped looking at one.

    function HitPoints:ModifyHitPoints( modify ), this function is called on the server to update one object HP. However, it does not receive the player that hit it as a parameter, just the hp value to subtract.
    function PlaceableObject:OnDestroy(), this function is called in the server by any placeable item when it is destroyed. The problem here is again that I don't have any information on the player that did the action.

    function Equipable:AffectObject( args ), this function is the best solution right now. I can get when the player is hitting objects and what object it is. However, this only works for equipable items. So if the player destroys anything using their hands or even a crude hoe, this functions is not triggered.

    What I might try to do is find the function that calls affect hit points for the hands and any other object that allows players to destroy objects and are not considered a equipable. (the same as the Equipable:AffectObject( args ) does)
  • marceloSRmarceloSR REGISTERED Posts: 47 Seed
    I managed to get the destroying things events for the hand action, equipable objects and the hoe.
    I used the function AffectObject from the Equipable class, the Hoe class and the BasePlayer class.
Sign In or Register to comment.