i need help with a mission code


Starbase:sendCommsMessage(Player, [[Wolf,
Captian there is an unknowen object approaching Human space.
You are to intercept this object in sector Z13 and identify it.
Good Luck Captian.]])
mission_state=oNe
end


function update(Delta)
if distance(Player, Intruder) < 30000 then
Starbase:sendCommsMessage(Player, [[Wolf,
We are now recieving sensor data now, Proceed with caution!]])
end
if distance(Player, Intruder) <5000 then
Intruder:setFaction("kraylor"):orderRoaming()
end

end
I'm new to empty epsilon and working on a mission i have run into a error with this piece of code the message pops up at < 30000 when it is susposed to but when you click close it generates another hail with the same message and continues to repeat. if some one could point out the error and how to fix it i would be greatfull.
thanks

Comments

  • edited February 2
    if distance(Player, Intruder) < 30000 then

    So the message shows up whenever the distance is less then 30000 game units (30U ingame iirc)
    So, if you close the message, and you are still in range, the condition "distance(Player, Intruder) < 30000" is still true, so you will still be hailed.

    To avoid that, you have to let the game recognize if the message was already sent.
    1) set some flag when you send this message, so add another line after the message.
    scanmessage_received = true
    2) let the game recognize this flag by including it in your if-statement
    if distance(Player, Intruder) < 30000 and not scanmessage_received then

    Disclaimer: I have almost no experience in lua, so I am not sure if the syntax of my examples is 100% correct, but I guess it may be enough to get an idea how to solve the problem. I'm also not entirely sure how lua handles undefined variables, so to be on the safe side, define scanmessage_received=falsein the init function
  • Yes, "update" is ran about 60 times per second. (depending on the frame rate of the server)

    So you need to keep track of state somehow. One solution is the "flag" as suggested.

    Another solution is to track mission state. The tutorial on emptyepsilon.org uses a state variable.
    function init()
    Starbase:sendCommsMessage(Player, [[Wolf,
    Captian there is an unknowen object approaching Human space.
    You are to intercept this object in sector Z13 and identify it.
    Good Luck Captian.]])
    mission_state = 1
    end


    function update(Delta)
    if mission_state == 1 then
    if distance(Player, Intruder) < 30000 then
    Starbase:sendCommsMessage(Player, [[Wolf,
    We are now recieving sensor data now, Proceed with caution!]])
    mission_state = 2
    end
    end
    if mission_state == 2 then
    if distance(Player, Intruder) <5000 then
    Intruder:setFaction("kraylor"):orderRoaming()
    mission_state = 3
    end
    end
    if mission_state == 3 then
    --TODO: if not Intruder:isValid() then .. end
    end
    end
    Or, you can also track the current mission state as a function. This is what the "Atlantis" mission script does. And it works better for larger missions:
    function init()
    Starbase:sendCommsMessage(Player, [[Wolf,
    Captian there is an unknowen object approaching Human space.
    You are to intercept this object in sector Z13 and identify it.
    Good Luck Captian.]])
    mission_state = waitTillPlayerCloseToIntruder
    end


    function update(Delta)
    mission_state()
    end

    function waitTillPlayerCloseToIntruderForMessage()
    if distance(Player, Intruder) < 30000 then
    Starbase:sendCommsMessage(Player, [[Wolf,
    We are now recieving sensor data now, Proceed with caution!]])
    mission_state = waitTillPlayerCloseToIntruderForAttack
    end
    end

    function waitTillPlayerCloseToIntruderForAttack()
    if distance(Player, Intruder) <5000 then
    Intruder:setFaction("kraylor"):orderRoaming()
    mission_state = waitTillIntruderDestroyed
    end
    end

    function waitTillIntruderDestroyed()
    --TODO: if not Intruder:isValid() then .. end
    end
    Which allows you to split up the different stages of your mission better and clearer in the file. Which is my personal favorite way to do it.

    The atlantis mission still checks defeat conditions at all times from the update function, as well as some other trigger conditions that will always happen. While the rest is done from mission state functions.
  • thank you i did find that helpful
  • I am looking for a way to use the player x or y as a if then.
    for example
    if x<250000 then

    any help would be most appreciated

    thanks

  • local x, y = player:getPosition()
    if x < 250000 then
    But, using the distance() function from utils is generally better idea. Which can also be used like:

    if distance(player, 250000, 25000) < 2000 then
  • i'm sorry for asking so many questions but i am getting there with missions but again i am stuck with comms messageing i can use :sendCommsMessage(player,.... but i trying to be able to setCommsMessage() but it is not working..... i tried to decipher the atlantis comms but not sure what i am missing

    if mission_state==0 then

    comms_source=(starbase)
    comms_target=(player)
    setCommsMessage("Starbase 001 here what can we do for you Captian")
    addCommsReply("Ready to Depart", function()

    setCommsMessage([["Wolf you are cleared to undock....Maintine 50% impulse until you clear Starbase by 30000 Meters and good luck.]])
    end)
    mission_state=1
    addCommsReply("Ready for Chaseing Comets", function()
    setCommsMessage ([["We recieved data on a comet that passes by Sector ???? every 17.5 minutes investigate and let us know what you find"]])
    end)
    mission_state=2
    return
    end
    thank you for any help
  • What you are missing/doing wrong is that the setCommsMessage and addCommsReply functions should only be used in special "comms" functions. "comms_source" and "comms_target" also don't need to be set manually.

    The Atlantis mission script is quite complex in this regard. Maybe this example will help:
    function init()
    player = PlayerSpaceship():setFaction("Human Navy"):setTemplate("Atlantis"):setRotation(200)

    sb1 = SpaceStation():setPosition(1000, 1000):setTemplate('Small Station'):setFaction("Human Navy"):setRotation(random(0, 360))
    sb1:setCommsFunction(starBase1Comms)
    --Enable if you want to hail the player from the station at the start:
    --sb1:openCommsTo(player)
    end


    function starBase1Comms()
    if mission_state==0 then
    setCommsMessage("Starbase 001 here what can we do for you Captian")
    addCommsReply("Ready to Depart", function()
    setCommsMessage([["Wolf you are cleared to undock....Maintine 50% impulse until you clear Starbase by 30000 Meters and good luck.]])
    mission_state=1
    end)
    addCommsReply("Ready for Chaseing Comets", function()
    setCommsMessage ([["We recieved data on a comet that passes by Sector ???? every 17.5 minutes investigate and let us know what you find"]])
    mission_state=2
    end)
    else
    setCommsMessage("...")
    end
    end
  • Thank you very much it think it will work nicely
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!