DeDave98 Posted March 9 Posted March 9 (edited) Hello there, im trying to write a script to spawn a new plane in front of the one player that selects that F10 option in multiplayer. But I get this error which I can´t quite understand: Spoiler SCRIPTING (Main): [string "l10n/DEFAULT/PlaneSpawnsV2.lua"]:38: attempt to call method 'getUnit' (a nil value) stack traceback: [C]: in function 'getUnit' [string "l10n/DEFAULT/PlaneSpawnsV2.lua"]:38: in function <[string "l10n/DEFAULT/PlaneSpawnsV2.lua"]:37> Now this is the function I use to identify the player and generate the F10 options: Spoiler local function addF10ForGroup(group) if group and group:isExist() then local groupId = group:getID() local groupNames = group:getName() for _, groupNameList in ipairs(fightGroupsFox2) do missionCommands.addCommandForGroup(groupId, groupNameList, menuFight2, Dogfight, {groupNames,groupNameList}) end for _, groupNameList in ipairs(fightGroupsGuns) do missionCommands.addCommandForGroup(groupId, groupNameList, menuFightG, Dogfight, {groupNames,groupNameList}) end end end The parameter "group" for it is passed via an eventHandler that calls this function and that part works great. Now, this is the function I get the error in: Spoiler local function Dogfight(groupNames, groupNameList) local unit = Group.getByName(groupNames):getUnit(1) local pos = unit:getPoint() local tgtpos = { x = pos.x + 100 * pos.x.x, y = pos.y, z = pos.z + 100 * pos.x.x } local tgtGrp = {} tgtGrp.groupName = groupNameList tgtGrp.point = tgtpos tgtGrp.action = "clone" tgtGrp.newGroupName = "activeGroup" mist.teleportToPoint(tgtGrp) trigger.action.activateGroup("activeGroup") end As you can see, groupNames is passed to the function from getName so it should be a string. My feeling is that groupNames is either not a string or isn´t passed to "Dogfight" correctly. But I´m at a loss here. Maybe someone here can point me in the right direction. I´ll also attach the complete script in this post in case you guys need some more info. There are some other functions in this script, please ignore those. And please ignore my messy coding. I know it´s not pretty but it´s what I have. Edited March 9 by DeDave98
Solution DeDave98 Posted March 9 Author Solution Posted March 9 Never mind, figured it out. For anyone finding this thread sometime in the future, this was the fix to me: Spoiler local function addF10ForGroup(group) if group and group:isExist() then local groupId = group:getID() local groupNames = group:getName() for _, groupNameList in ipairs(fightGroupsFox2) do missionCommands.addCommandForGroup(groupId, groupNameList, menuFight2, function(arg) Dogfight(arg[1], arg[2]) end, {groupNames, groupNameList} ) end for _, groupNameList in ipairs(fightGroupsGuns) do missionCommands.addCommandForGroup(groupId, groupNameList, menuFightG, function(arg2) Dogfight(arg2[1], arg2[2]) end, {groupNames, groupNameList} ) end end end 1
Mistermann Posted March 10 Posted March 10 Thanks for posting the answer! Never know when others need this information. 1 System Specs: Spoiler Callsign:Kandy Processor:13th Gen Intel(R) Core(TM) i9-13900K - RAM: 64GB - Video Card: NVIDIA RTX 4090 - Display: Pimax 8kx VR Headset - Accessories: VKB Gunfighter III MCG Ultimate, VKB STECS Standard, Thrustmaster TPR Pedals, Simshaker JetPad, Predator HOTAS Mounts, 3D Printed Flight Button Box Video Capture Software: Open Broadcaster Software (OBS), Video Editing Software: PowerDirector 35 Into The Jungle (MP Mission) F18: Scorpion's Sting Apache Campaign - Griffins Kiowa Campaign - Assassins
Recommended Posts