Jump to content
Madin

Question about existing spy scripts

Recommended Posts

In scripted event there is this:

<ScriptedEvent Name="ExampleSpyMoving" /> <!-- SpyMoving(self, spySelf, parameters...) spySelf is the object self is spying on, parameters is the spied event paramters, may be nil. -->

Does anyone know how this is used? I could not find any examples of its usage. "Parameters is the spied event parameters" (?).

A list of native LUA game script functions has an 'ObjectSpy' function, that has no information at all. Again I could not find any examples of this being used, does anyone have any ideas?

Share this post


Link to post

BFME2 has this LUA function, but I cant think if any case where it is used:

function SpyMoving(self, other)
	print(ObjectDescription(self).." spying movement of "..ObjectDescription(other));
end

 

  • Upvote 1

Share this post


Link to post

Basically a ScriptedEvent is the only event type that can be triggered directly within lua code, hence the name. You can trigger a scripted event with these commands:

ObjectBroadcastEventToEnemies(object,eventname,radius)
ObjectBroadcastEventToAllies(object,eventname,radius)
ObjectBroadcastEventToUnits(object,eventname,radius)
ObjectBroadcastEventToCivilians(object,eventname,radius)
ObjectDispatchEvent(object,eventname,radius)
HordeBroadcastEventToMembers(?)

So if you call for example ObjectBroadcastEventToEnemies(self,"ExampleSpyMoving",1000) you trigger the functions of all units that have this event in their eventlist. Like this:

    <EventList Name="SpyFunctions" Inherit="BaseScriptFunctions">
        <EventHandler EventName="ExampleSpyMoving" ScriptFunctionName="OnExampleSpyMoving" DebugSingleStep="false"/>
    </EventList>

It calls the function OnExampleSpyMoving(self, other, string) ...

If you match the radius parameter with the view radius of the unit it actually makes sense. So the spy could trigger the broadcast when he has the ModelConditionEvent +Moving for example and by that inform all units surounding him about his intention.

I also have no idea about ObjectSpy(). Maybe it trigger OnGenericEvent ? We need to test...

Edited by Mjjstral

Share this post


Link to post
1 hour ago, Stygs said:

BFME2 has this LUA function, but I cant think if any case where it is used:


function SpyMoving(self, other)
	print(ObjectDescription(self).." spying movement of "..ObjectDescription(other));
end

 

Well that is at least something, thanks.

1 hour ago, Mjjstral said:

It calls the function OnExampleSpyMoving(self, other, string) ...

The 'ExampleSpyMoving' is  (self, spySelf, parameters...) according to the xml.

Share this post


Link to post
16 minutes ago, Madin said:

Well that is at least something, thanks.

The 'ExampleSpyMoving' is  (self, spySelf, parameters...) according to the xml.

The name of the parameters doesn't matter, what matters is the actual data type that lies behind them. That means you can rename self to whatever you like. Self is a lua table type, spySelf must also be a lua table, as all ScriptEvents given object arguments are. Everything that follows is very likely a string. You can test what lies behind these parameters when you display arg[3] and arg[4] ... To test the type just display type(arg[3]).

You can also define the whole function header with three dots like that: function OnExampleSpyMoving(...)

That doesn't limit the number of arguments if you don't know how many you get, but then you are limited to access them only with arg[NumberOfArgument]. Hope that helps.

  • Upvote 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×