Jump to content

Recommended Posts

Posted

Hi,

just tested if i can block players from joining a side with the a HOOK script using the Dynamic slots.

The function "function sideCall.onPlayerTryChangeSlot(playerId, side, slotId)" does not seam to trigger if you select a dynamic slot, but does if i use regular slots.

 

Is this a known issue and is it going to be fixed soon ?

 

This hinders any PVE server from using the new slot system as is.

 

 

 

 

  • Like 1
Posted (edited)

Here is a temporary partial solution to the problem.

it will not stop players from joining a team, but will send the player back to spectate if joining a slot on the team you want to block.

 

env.info('-- Loading reslot red to spectate script!')

reslot = {}

-- Select what side to reslot to spectator: 1 = Red, 2 = Blue
reslot.sidetospectate = 1

reslot.active = true


reslot.tickTime = 1 -- second


function reslot.check(arg, time)

	if reslot.active == true then

		local _playerslist = net.get_player_list()
		for _playerIdx, _playerId in pairs( _playerslist ) do


			local _playerInfo = net.get_player_info( _playerId )
			
			if _playerInfo ~=nil and _playerInfo.side == reslot.sidetospectate  then
				net.send_chat('Player is on wrong side! Forcing player back to spectate - Player: ' .. _playerInfo.name  , true)
				net.force_player_slot(_playerId, 0, '')
			end
									
		end -- of for _playerIdx, _playerId in pairs( _playerslist ) do
		
		return time + reslot.tickTime
		
	else
 
		env.info('-- Schedule reslot.check has been canceled!')
		return nil
		
	end


end -- of function reslot.check()


timer.scheduleFunction(reslot.check, 9999, timer.getTime() + reslot.tickTime) -- Run schedule

 

Edited by Kanelbolle
  • Like 1
  • 6 months later...
Posted (edited)

Hi, Kanelbolle!

Can you help? I tested this function. I sat on some slot, but the message "TEST" was never sent to the chat. What's wrong?

local myCall = {}

function myCall.onPlayerTryChangeSlot(id, side, slotId)
     net.send_chat("TEST")

     end

DCS.setUserCallbacks(myCall)

 

Edited by Mikeyfry
Posted (edited)
12 hours ago, Mikeyfry said:

Hi, Kanelbolle!

Can you help? I tested this function. I sat on some slot, but the message "TEST" was never sent to the chat. What's wrong?

local myCall = {}

function myCall.onPlayerTryChangeSlot(id, side, slotId)
     net.send_chat("TEST")

     end

DCS.setUserCallbacks(myCall)

 

Are you running this as a HOOK script ? "onPlayerTryChangeSlot" only works in a hook script.

As far as u can tell without testing it, you might need TRUE as a parameter in send_chat.

local myCall = {}

function myCall.onPlayerTryChangeSlot(id, side, slotId)
     
  net.send_chat("TEST", true)

end

DCS.setUserCallbacks(myCall)

But will say that the easy way to avoid people on a server from joining a side you don't want them to, is to just set a password on the server for the side.

Blue and red side can have a password on servers.

 

Edited by Kanelbolle
  • Like 1
Posted
1 час назад, Kanelbolle сказал:

Are you running this as a HOOK script ? "onPlayerTryChangeSlot" only works in a hook script.

Yes, i placed this code in the serverhook.lua, in the server scripts folder.

1 час назад, Kanelbolle сказал:

As far as u can tell without testing it, you might need TRUE as a parameter in send_chat.

Thanks, I'll try adding this

 

1 час назад, Kanelbolle сказал:

But will say that the easy way to avoid people on a server from joining a side

I need another goal. Give a message to the player who tries to get to the slot of the helipad, which has no resources. It will become active after a certain time.
Players are thrown into the spectators and they do not understand what is going on))

Posted
1 hour ago, Mikeyfry said:

Yes, i placed this code in the serverhook.lua, in the server scripts folder.

Thanks, I'll try adding this

 

I need another goal. Give a message to the player who tries to get to the slot of the helipad, which has no resources. It will become active after a certain time.
Players are thrown into the spectators and they do not understand what is going on))

serverhook.lua ?

Never seen this file, might work but Hook scripts should be in your own script file under :

%USERPROFILE%\Saved Games\DCS\Scripts\Hooks\

 

  • Like 1
Posted
51 минуту назад, Kanelbolle сказал:

Never seen this file, might work but Hook scripts should be in your own script file under :

Maybe I'm wrong. I'll check when I have time.

Posted (edited)
4 часа назад, Kanelbolle сказал:

serverhook.lua ?

Never seen this file, might work but Hook scripts should be in your own script file under :

%USERPROFILE%\Saved Games\DCS\Scripts\Hooks\

 

I have a dedicated server, the file with scripts is in: %USERPROFILE%\Saved Games\DCS.dcs_serverrelease\Scripts\Hooks
I named him serverhook.lua (Any name possible?)
I tried adding "true" in net.send_chat. But nothing has changed.
Other functions in this file work fine...

Edited by Mikeyfry
Posted
1 hour ago, Mikeyfry said:

I have a dedicated server, the file with scripts is in: %USERPROFILE%\Saved Games\DCS.dcs_serverrelease\Scripts\Hooks
I named him serverhook.lua (Any name possible?)
I tried adding "true" in net.send_chat. But nothing has changed.
Other functions in this file work fine...

%USERPROFILE%\Saved Games\DCS.dcs_serverrelease\Scripts\Hooks

seams correct, it is where DCS.dcs_serverrelease is what ever you call the profile in the dedicated server shortcut parameter -w
Example starting the dedicated server with : DCS_server.exe -w MyDedicatedDCSServer

MyDedicatedDCSServer will be the profile for that instance of the DCS Dedicated server.

 

Script works just fine on my local game server:

 

image.png

  • Like 1
Posted
2 часа назад, Kanelbolle сказал:

Script works just fine on my local game server:

Oh my god. I had to create a new file in the server's hooks folder. And put my code there. For some reason the code didn't work with other functions!

Looks like my idea failed. My helipad is activated by the "HP" flag when its value is 2. I thought that the hook has access to flags from the mission file.
 

function myCall.onPlayerTryChangeSlot(id, side, slotId)
    if (slotId == '1106') and (trigger.misc.getUserFlag('HP')) == 1 then
        net.send_chat_to("Helipad is not active yet!", id)
    end
end 

 

Posted (edited)
6 hours ago, Mikeyfry said:

Oh my god. I had to create a new file in the server's hooks folder. And put my code there. For some reason the code didn't work with other functions!

Looks like my idea failed. My helipad is activated by the "HP" flag when its value is 2. I thought that the hook has access to flags from the mission file.
 

function myCall.onPlayerTryChangeSlot(id, side, slotId)
    if (slotId == '1106') and (trigger.misc.getUserFlag('HP')) == 1 then
        net.send_chat_to("Helipad is not active yet!", id)
    end
end 

 

nice that you got it working 🙂

 

There is a way to get the flags from the mission environment, just look at SSB

Here are the functions it uses:

function ssb.getFlagValue(_flag)

  local _status,_error  = net.dostring_in('server', " return trigger.misc.getUserFlag(\"".._flag.."\"); ")

  if not _status and _error then
    net.log("SSB - error getting flag: ".._error)
    return tonumber(ssb.enabledFlagValue)
  else

    --disabled
    return tonumber(_status)
  end
end


function ssb.setFlagValue(_flag, _number) -- Added by FlightControl

  local _status,_error  = net.dostring_in('server', " return trigger.action.setUserFlag(\"".._flag.."\", " .. _number .. "); ")

  if not _status and _error then
    net.log("SSB - error setting flag: ".._error)
    return false
  end
  return true
 end

 

You can find the whole script here:

 

Edited by Kanelbolle
  • Thanks 1
Posted (edited)
10 hours ago, Mikeyfry said:

Looks like my idea failed. My helipad is activated by the "HP" flag when its value is 2.

This appears to be similar to the seminal "simple slot block" idea ("SSB"), of which there is a good implementation available. It's your idea generalized - which is a good thing because your script changes the semantics of all missions running on your server when it comes to players and the flag named "HP" in missions.

10 hours ago, Mikeyfry said:

I thought that the hook has access to flags from the mission file.

Scripts in Hooks can indeed execute trigger.misc.getUserFlag() in another context and retrieve the value (and set it is well, but nothing more) using net.doString(). @Kanelbolle was already kind enough to quote the relevant passages from SSB, here's the line to focus on:

local _status,_error  = net.dostring_in('server', " return trigger.misc.getUserFlag(\"".._flag.."\"); ")

The 'server' bit is non-discoverable, you simply must know that it has to be 'server'. Three cheers for DCS's documentation team.

Also, remember that after changing a server script, you must fully, entirely restart DCS for any changes to occur (server scripts are only read when the app starts up)

Edited by cfrag
  • Thanks 1
Posted
5 часов назад, cfrag сказал:

here's the line to focus on:

I guess that's how it should work?

local myCall = {}

function myCall.onPlayerTryChangeSlot(id, side, slotId)
  local Flag  = net.dostring_in('server', " return trigger.misc.getUserFlag(\""HP"\"); ")
  if (slotId == '1106') and (tonumber(Flag) == 1) then
    net.send_chat_to("Helipad is not active yet!", id)
  end
end

DCS.setUserCallbacks(myCall)

 

Posted
2 hours ago, Mikeyfry said:
local Flag  = net.dostring_in('server', " return trigger.misc.getUserFlag(\""HP"\"); ")

Looks wonky to me...

If above doesn't work, try 

local Flag  = net.dostring_in('server', " return trigger.misc.getUserFlag(\"HP\"); ")

 

  • Like 1
Posted

Recently, I needed to use net.force_player_slot(id, 0, '') - send player to spectators. I added this next to the message that the helipad is not active.

Does this still work? Because I easily took the slot and even spawned.

Posted
On 2/13/2025 at 6:26 AM, Mikeyfry said:

Recently, I needed to use net.force_player_slot(id, 0, '') - send player to spectators. I added this next to the message that the helipad is not active.

Does this still work? Because I easily took the slot and even spawned.

 

Seams to be broken yes. Noting new for ED to brake stuff unfortunately.

 

Seam to not do anything under "onPlayerTryChangeSlot"

And seam to crash the server under "onPlayerChangeSlot" (runs in a loop forever)

  • Recently Browsing   0 members

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