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
«1

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
  • hey where might i upload a mission script for someone with more experience than i to look at it?
  • https://pastebin.com/ usually helps with sharing medium sized code things to ask help on.
  • can any help me to make this work please
    earth:setDescriptions("Class M Oxygen, Nitrogen, and Water....Earth like.",random(0, 600000000000)"Life signs")
  • Guess you want to append the random number to the "life signs" string?

    Attaching strings together is done with ..

    earth:setDescriptions("Class M Oxygen, Nitrogen, and Water....Earth like.", random(0, 600000000000) .. " Life signs")

  • You might want to find and read some basic Lua tutorials, like https://www.lua.org/pil/p1.html
  • i am looking for the variable for shield % front and back and for energy if someone could tell me what they are

  • edited March 10
    You can calculate the percentage from the current and the maximum shield level.
    You can read the current values with getShieldLevel(n) and the maximum value with getShieldMax(n).
    n can be different values (for 2-shield-ships it is 0:front and 1:rear)
  • if distance(player, anomaly3) < 5000 then
    player:getShieldLevel(0) - .001
    player:getShieldLevel(1) - .001
    player:getEnergy -.001
    end

    still having trouble making this work
  • I don't know what you're trying to do, and I am not familiar with empty epsilon's lua API, but I could take a guess...

    if distance(player, anomaly3) < 5000 then
    player:setShieldLevel(player:getShieldLevel(0) - 0.001);
    player:setShieldLevel(player:getShieldLevel(1) - 0.001);
    player:setEnergy(player:getEnergy() - 0.001);
    end
    At least it runs through luac without any errors (i.e. it is syntactically correct, a necessary but not sufficient condition.) I had to make some giant assumptions about the EE lua API and what you were trying to do though, so what I posted is not especially likely to be correct.

    A word of advice, when asking questions of this nature, try to describe what you're trying to do, and what you have tried, and in what way it's not working as you would expect, and any sort of diagnostic error messages you're getting.

    "Here's some code that doesn't work." is not exactly a question that can be answered without making an attempt to be a mind reader.

  • Thank you
    I will in the future add more
  • what i was looking for was a way to drain the shields and energy for use in a trap if distance is less than ??? drain shields then energy
    if distance(player, anomaly3) < 5000 then
    player:getShieldLevel(0) - .001
    player:getShieldLevel(1) - .001
    player:getEnergy -.001
    end
  • edited March 11
    player:getShieldLevel(0) - .001
    player:getShieldLevel(1) - .001
    player:getEnergy -.001
    those are just calculations, but you do not tell the script what should happen with the result. You get those values, subtract .001, and then? You have to tell the script where the result of that calculation should go to. So in your case you wanted them to be written back to the original values, as smcameron guessed correctly. Of course he could not know the correct function names (but was already correct for energy), so they are slightly different. There is a function setShields which can be used for it, but is mainly for initially setting values, so not sure how well this works.


    player:setShields(player:getShieldLevel(0) - 0.001,(player:getShieldLevel(1)) - 0.001);
    player:setEnergy(player:getEnergy() - 0.001);

    but anyway, this way you will get in serious trouble, as you do not have defined how fast the shields and energy will get drained. Right now it will be drained by 0.001 per cycle, so it will depend on the fps/speed of your server. So use the delta-parameter, which is the time between the current and the last script call in seconds. so if you want your shield drained by 1 (absolute value, not percent) per second, and your energy by 2 per second, do

    if distance(player, station_1) < 5000 then
    player:setShields(player:getShieldLevel(0) - 1*delta,(player:getShieldLevel(1)) - 1*delta);
    player:setEnergy(player:getEnergy() - 2*delta);
    end

    make sure this is in the update(delta) function

    There is also a function takedamage, that probably could be used to directly make damage at the shields (damage type emp)

    I would also recommend to have a look at the script_reference.html from time to time. It is autogenerated at compiletime, and can befound in the emptyepsilon folder. Also it helps to look into the other mission files to see how similar things were done.
  • edited March 12
    thank you very much.

  • if there a way to make a friendly target ie..Human navy transport able to be fire on by beam weapons without changeing it to a different faction?
  • i did try the
    player:isEnemy(bf1)

    bf1 = the other ship
  • Nope, not possible, factions are directly linked to the friend/enemy logic.

    isEnemy is used to check if something is an enemy compared to something else:

    if player:isEnemy(bf1) then bf1:destroy() end
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!