Jump to content

Mist script question


flo57100

Recommended Posts

Hello there,

I started to try things with mist, and I want to have this: if hélicopters or planes from blue coalition enter trigger zone, those air assets become immortal in this zone only.

I tried this:

 

if mist.flagFunc.units_in_zones {

units = {'[blue][plane]', '[blue][helicopter]'}

zones = {'invincible'}

flag = 100,

stopflag = 200} then

 

SetImmortal = {

id = {'[blue][plane]', '[blue][helicopter]'}

params = {

value = true

}

}

end

 

But it doesn't work, can anyone help me please ?

Link to comment
Share on other sites

You are mixing a couple of different concepts together that don't really work how you think it does.

 

The flagFuncs don't actually return anything, they act more like the triggers in game by setting specified flags to true whenever the conditions are met. What you need is more of a scripting function setup to periodically check those units and set them to be invincible once they enter the zone...

 

local units = mist.makeUnitTable({'[blue][plane]', '[blue][helicopter]'}) -- make list of all blue planes and helicopters
local zone = trigger.misc.getZone('invincible') -- get the trigger zone
local inZone = {} -- table of units inside the zone

local function check()
   for i = 1, #units do -- iterate units
       if Unit.getByName(units[i]) then -- if returned
           local u = Unit.getByName(units[i])
           if u:getLife() > 0 then -- if it is alive
               if mist.utils.get2DDist(u:getPosition().p, zone.point) < zone.radius then -- if it is in the zone
                   if not inZone[u:getName()] then -- if it wasn't there before
                       u:getController():setCommand({id = 'SetImmortal', params = {value = true}}) -- set immortal to true
                       inZone[u:getName()] == true -- add it to zone list
                   end
               else -- if not in zone
                   if inZone[u:getName()] then  -- if was previously in zone
                       u:getController():setCommand({id = 'SetImmortal', params = {value = false}}) -- set immortal to false
                       inZone[u:getName()] = nil -- clear from list
                   end
               end
           end
       end
   end
end

mist.scheduleFunction(check, {}, timer.getTime(), 5)

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

Hello Grimes and thank you for your script, it's really far far away from what I initially intended :thumbup:

 

I just tried it, but I don't know what's going on I have this error message that pops on screen after the mission, when the script is expected to load

 

[string "local.units = mist.makeUnitTable({'[blue][plane]','[blue][heli..."]:13: '=' expected near '=='

 

What does it mean ?

Link to comment
Share on other sites

There is a typo on line 13. I accidentally used == instead of =

 

In lua == means "equals" while a = assigns a value. They have different syntax for when they are used. For example:

 

if whatever == 'hello' then

whatEverElse = 'world'

end

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

  • 3 years later...

How can I extract client nicknames and their position from mission with MIST?

I trying this way, starting to enumerate units name.

But when I try to print name I have this error

 

local units = mist.makeUnitTable({'[all]'}, {'static','ship','vehicle'})

for i=1,#units do
		if Unit.getByName(units[i]) then -- if returned
			local u = Unit.getByName(units[i]).unitName
			
			--local testNAME = u.unitName
			--trigger.action.outText(u, 100)
		end
end

 

image.png


Edited by BR55Sevas
Link to comment
Share on other sites

There are a few things wrong there. 

 

The units table is a list of unit names. So you already have that information. 

 

units[i] is a specific unit name from that table. 

 

Unit.getByName(units[i]).unitName is a nil value. That entry simply doesn't exist since Unit.getByName returns a unit object. The equivalent would be Unit.getByName(units[i]):getName(). However that is kind of pointless since you already have the name. 

 

If the "u" value was the unit object its not something that can be directly output via outText since its not a string or number. It looks like a table but its a little more complicated than that. 

 

I'm guessing you want something more like

 

    

 local u = Unit.getByName(units[i]):getPlayerName()

 

  • Like 1

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

Yes, all I want is just to get info (nickname and postion vector) about live units controlled by human only - clients.

I have tried your advice

Now my code looks like this, I`ve changed u to nickname for better code readability

local units = mist.makeUnitTable({'all'})
	
	for i=1,#units do
		
			local nickname = Unit.getByName(units[i]):getPlayerName()-- this is 35th line where error is
			trigger.action.outText(nickname, 100)
	end

 

But same as before I have error.

image.png

 

I suppose I need to check if unit is selected by human, because now if unit exist in list, but if it`s not controlled then playerName is nil value. But what proper way to check if unit under client control?

Debug #unit count return 1 even if in mission only server and plane not choosen


Edited by BR55Sevas
Link to comment
Share on other sites

I don't know mist well, but make sure that 

  • the units returned in the table from makeUnitTable are really units, not a table that contains the unit and additional data
  • the  table itself is an array, not a dictionary

Grimes will probably resolve that in a second, but until then I recommend that instead of a for i loop, you use for key, value in pairs() instead.

 


Edited by cfrag
Link to comment
Share on other sites

If you want to check for clients you can just use the built in DB table for them.

for uName, uData in pairs(mist.DBs.humansByName) do
    if Unit.getByName(uName) then -- unit is alive and exists
    	local nickname = Unit.getByName(uName):getPlayerName()
		trigger.action.outText(nickname, 100)
    end 
end

if Unit.getByName(whatever) is required because both the humansByName table and makeUnitsTable function just contain a static table of what the unit names within a given mission and don't keep track if anything is alive. Think of it as a list of units that fit the parameters. humansByName being something that is created by mist with a bunch of other data in there as well like coalition, country, unit type, etc. On the other hand what gets returned by mist.makeUnitsTable is just that, a list of unit names indexed numerically. 

 

From your code the  " local nickname = Unit.getByName(units[i]):getPlayerName()-- this is 35th line where error is " can fail because Unit.getByName(units[i]) can return a nil value if that unit isn't alive which in turn causes an error because it is effectively nil:getPlayerName(). 

  • Like 1

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

Link to comment
Share on other sites

  • 8 months later...
On 12/22/2017 at 9:13 AM, Grimes said:

There is a typo on line 13. I accidentally used == instead of =

 

In lua == means "equals" while a = assigns a value. They have different syntax for when they are used. For example:

 

if whatever == 'hello' then

whatEverElse = 'world'

end

 

I tested with the correction, but players aren't immortal. Any idea what can go wrong ? 
( trigger.action.outText's work fine though)

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

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