Jump to content

Dogfight script


L39Tom

Recommended Posts

I need your help again.

I want to build a dogfight trainings mission (gunsonly, maybe heaters later).

2 clients, both immortal. Every shell-hit gives you points.

 

I thought I could do this with checking the EVENT-HIT, but it only works fine on the "joining" client.

It seems there are some problems with the EVENT-management for the "hosting" client.

No EVENT when the HOST gets hit.

 

With the following code I checked the events:

 

local Event_Handler = {}

 

function Event_Handler:onEvent(event)

if event.id == world.event.S_EVENT_HIT and event.initiator then

env.info("Something has been hit")

 

if event.target:getPlayerName() then targetPlayer = event.target:getPlayerName() else targetPlayer = " NO targetPlayer" end

if event.target:getName() then target = event.target:getName() else target = " NO target" end

if event.weapon:getTypeName() then weapon = event.weapon:getTypeName() else weapon = " NO weapon" end

if event.initiator:getName() then shooter = event.initiator:getName() else shooter = " NO shooter" end

if event.initiator:getPlayerName() then shooterPlayer = event.initiator:getPlayerName() else shooterPlayer = " NO shooterPlayer" end

 

trigger.action.outText(" targetPlayer = ".. targetPlayer, 30)

trigger.action.outText(" target = ".. target, 30)

trigger.action.outText(" weapon = ".. weapon, 30)

trigger.action.outText(" shooterPlayer = ".. shooterPlayer, 30)

trigger.action.outText(" shooter = ".. shooter, 30)

trigger.action.outText(" ______________________________", 30)

 

 

end

end

world.addEventHandler(Event_Handler)

Does someone has an idea how to solve the problem?

May be my code is trash, may be there is an other way to come further (missiles can be tracked and you can check the distance to the target, but shell....)

 

Very thankful for some help

 

 

Tom

Link to comment
Share on other sites

I don't have a solution for you, just some suggestions.

 

 

I'd start simple, making sure that the foundations of the script work unequivocally, before introducing additional checks + methods + global variable overwrites.

Streamlining will come at the end, when all the issues have been identified and solved.

 

For instance, I'd start testing with something like this:

 

 

local Event_Handler = {}

 

function Event_Handler:onEvent(event)

 

if event.id == 2 then

 

env.info("HIT event detected!")

trigger.action.outText("HIT event detected!", 30)

 

if event.initiator:getName() then

 

local shooter = event.initiator:getName()

 

trigger.action.outText("Shooter = "..shooter, 30)

 

elseif event.initiator:getName() == nil then -- Might be redundant, but I find it helpful, since it provides an unequivocal diagnosis

 

trigger.action.outText("Shooter can't be found!\nevent.initiator:getName() returns nil!", 30)

 

end

 

 

if event.target:getName() then

 

local target = event.target:getName()

 

trigger.action.outText("Target = "..target, 30)

 

elseif event.target:getName() == nil then --Might be redundant, but I find it helpful, since it provides an unequivocal diagnosis

 

trigger.action.outText("Target can't be found!\nevent.target:getName() returns nil!", 30)

 

end

end

end

 

world.addEventHandler(Event_Handler)

 

 

 

If the initiator and target objects aren't properly captured by this simple script, forget about the rest of functions. There's probably a more fundamental issue going on.

 

 

 

Also, I seem to recall that DCS has a message quantity cap, so it's better to include all the info in a single message, rather than dividing it in separate messages like you did (although I guess you probably did that for troubleshooting purposes)

 

 

trigger.action.outText(" targetPlayer = ".. targetPlayer.."\ntarget = ".. target.."\nweapon = ".. weapon.."\nshooterPlayer = ".. shooterPlayer.."\nshooter = "..shooter.."\n______________________________", 30)

 


Edited by Hardcard
Link to comment
Share on other sites

Are they going to be in the same aircraft? If not, how will you balance the points system for weapons with different firing and damage rates?

Same aircraft, both F18.

 

@hardcard

Thanks so far. The script and the event manager works fine for joining client(s) when shooting on each other.For the hosting client no event fires for some reason.

Client shoots host shot event doesnt work

Host shoot client shot event works

Client gets hit hit event works

Host gets hit hit event doesnt work

Link to comment
Share on other sites

Host gets hit, hit event doesnt work

 

Ok, so you aren't even getting these, right?

 

env.info("HIT event detected!")
trigger.action.outText("HIT event detected!", 30)

 

If that's the case, the host doesn't seem to be reachable, for whatever reason.

 

I have no multiplayer scripting experience, so I'm afraid I can't be of help.

 

You could try doing this with MOOSE or MIST, see if it works then.

 

Also, you could ask the folks on the Hoggit Discord channel (#scripting section).

Link to comment
Share on other sites

@Delta99 Unfortunately events on host still doesn't work even when entering spectator slot before. Now I will try to code with MIST and MOOSE. Perhaps this will work.

 

 

@Hardcard

Ok, so you aren't even getting these, right?
Yes, sadly

 

 

But somehow it must work, because DCS noticed hits on hosting clients.

:book:

Link to comment
Share on other sites

But somehow it must work, because DCS noticed hits on hosting clients.

 

Weird...

 

Ok, let's assume the problem is located in the initial event.id check

 

Have you tried using the numerical id enumerator?

[color="Blue"]-- Instead of this:[/color]
if event.id == world.event.S_EVENT_HIT then

[color="blue"]--Try this?[/color]
if event.id == 2 then

 

If it still doesn't work, then I guess the event handler itself can't reach the host, for whatever reason.

 

Could you post your mission file here?

Link to comment
Share on other sites

@Hardcard

 

Here is that mission file.

Event tester.miz

 

 

I will give it a try with using the numerical id enumerator, but I didn't have luck even with this code

local Event_Handler = {}

 

function Event_Handler:onEvent(event)

trigger.action.outText("Something happend! ID=".. event.id, 5)

end

world.addEventHandler(Event_Handler)

So I think the event doesn't get the host for some reason.

Maybe you find a way....

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...