Home   Help Search Login Register  

Author Topic: Disable players.  (Read 2669 times)

0 Members and 1 Guest are viewing this topic.

Robinhansen

  • Guest
Disable players.
« on: 15 Feb 2005, 01:03:43 »
I've created a MPgame with a lot of platoons, the commanders are the only players. My question is simple, is it possible to disable the whole platoon and not only the player in order to prevent lag?

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re:Disable players.
« Reply #1 on: 15 Feb 2005, 16:26:40 »
Hmmm...

What do you want exactly...

If you mean that when there is no player as a leader of a certain squad, you want to get rid of the whole squad so it won't be on the map when game starts?

You could run a 'deletevehicle' command on the server for that squad by first checking if their leader is a player on any client that is in the game and then deletevehicling them or not.

There might be other possibilities for the job too but this method should work.
« Last Edit: 15 Feb 2005, 16:27:30 by Baddo »

Robinhansen

  • Guest
Re:Disable players.
« Reply #2 on: 16 Feb 2005, 11:12:25 »
Thats excatly what I whant. "Deletevehicle command" U say?. Sounds interesting...please explain me more :P :P

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re:Disable players.
« Reply #3 on: 16 Feb 2005, 16:10:32 »
I made a quick solution. Not tested in MP, but it should work. This method deletes groups that don't have a player as leader and doesn't care if 'Disable AI' option is on or not.

1. If you don't have a game logic named 'Server' on the map yet, put one there now.

2. Give every group a name if not done yet. Write:

Code: [Select]
gw1 = group this
to group member's initialization field. Do not write it to group leader's init field because this won't work if you enable 'Disable AI' option. Use a non-playable and non-player unit for naming the group.

Do this for every group where you have set the leader as playable.

3. Put the following to the end of init.sqs file:

Code: [Select]
?!(local Server) : exit

_groups = [gw1,gw2,gw3]
_i = 0
_k = count _groups

#Loop

_tmp = leader (_groups select _i)

deletevehicle _tmp

~0.2

?!alive _tmp : {deletevehicle _x} foreach units (_groups select _i)

_i = _i + 1

?(_i == _k) : exit

goto "Loop"

As you might have already noticed there is a local array variable _groups. Put every group name (those you gave with the 'gw1 = group this' thing) to that array.

This code tries to delete the leader of every group defined in _groups, and then checks if the leader actually disappeared. If leader got deleted, then it just deletes the whole group. It works because player units can't be deleted with the deletevehicle command.

4. Test it in a multiplayer game and report back how it works.

There might be a better way to do this but I think this will work just fine. If you find a better solution please tell it in this thread.
« Last Edit: 16 Feb 2005, 16:20:56 by Baddo »

Robinhansen

  • Guest
Re:Disable players.
« Reply #4 on: 21 Feb 2005, 23:50:36 »
It works fantastic!! :D Is there a way to expand the script so it also delets empty vehicles and markers belonging to the platoons+
 8) 8)

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re:Disable players.
« Reply #5 on: 23 Feb 2005, 23:23:52 »
OK let's modify the script a little:

Code: [Select]
?!(local Server) : exit

_groups = [[gw1,[truck1,truck2]],[gw2,[tank1,tank2]],[gw3,[heli1,heli2]]]

_i = 0
_k = count _groups

#Loop

_tmp = leader ((_groups select _i) select 0)

deletevehicle _tmp
~0.2

? alive _tmp : goto "NoDelete"

{deletevehicle _x} foreach units ((_groups select _i) select 0)
~0.1

? (count (_groups select _i) > 1) : {deletevehicle _x} foreach ((_groups select _i) select 1)
~0.1

#NoDelete

_i = _i + 1

?(_i == _k) : exit

goto "Loop"

Now the _groups variable contains also the vehicles of each group. In this example group gw1 would have vehicles named truck1 and truck2 and so on, you get the idea.

If some group (in this example gw1) doesn't have any vehicles, write like this:

Code: [Select]
_groups = [[gw1],[gw2,[tank1,tank2]],[gw3,[heli1,heli2]]]
If there are soldiers inside vehicles:

1. If the vehicle is not grouped with the group and there are soldiers inside the vehicle, the vehicle will be deleted but the soldiers will not be deleted.

2. But if the vehicle is grouped with the group, the soldiers inside the vehicle will also be deleted.

So this means: don't put soldiers inside ungrouped vehicles if you want to get rid of them.

EDIT #1:

This version only takes care of soldiers and vehicles. I am working on a solution for the markers.

  :)

EDIT #2:

I added more delays to the script, take a look. The delays are guessed values so they are maybe not optimal but I think they are good enough. If you encounter problems without any error messages in a multiplayer game, you could try and put some more delay.
« Last Edit: 24 Feb 2005, 17:47:42 by Baddo »

Robinhansen

  • Guest
Re:Disable players.
« Reply #6 on: 24 Feb 2005, 16:33:09 »
OMG!!! :o
This is sooooo sweet!!!
Can't wait to the whole script is finished...
You should publish this script and take full credit for it...

 :P

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re:Disable players.
« Reply #7 on: 24 Feb 2005, 20:23:49 »
This one hides markers:

Code: [Select]
_groups = [[gw1,[truck1,truck2],["gw1marker1","gw1marker2"]],[gw2,[tank1,tank2],["gw2marker1","gw2marker2"]]]

_i = 0
_k = count _groups

#Loop

_tmp = leader ((_groups select _i) select 0)

deletevehicle _tmp
~0.04

? alive _tmp : goto "NoDelete"

{deletevehicle _x} foreach units ((_groups select _i) select 0)
~0.02

? (count (_groups select _i) > 1) : {deletevehicle _x} foreach ((_groups select _i) select 1)
~0.02

? (count (_groups select _i) > 2) : {_x setmarkertype "empty"} foreach ((_groups select _i) select 2)
~0.02

#NoDelete

_i = _i + 1

?(_i == _k) : exit

goto "Loop"

As you can see I added marker names to the _groups variable.

This script runs on the server and on all clients and thus should hide the markers correctly on every client. The deletevehicle command could be run only in the server but that would make things a little bit more complicated when we have to deal with the markers too.

If some group (in this example gw1) has vehicles but doesn't have markers, write like this:

Code: [Select]
_groups = [[gw1,[truck1,truck2]],[gw2,[tank1,tank2],["gw2marker1","gw2marker2"]]]If some group (in this example gw1) doesn't have any vehicles but does have markers, write like this:

Code: [Select]
_groups = [[gw1,[],["gw1marker1","gw1marker2"]],[gw2,[tank1,tank2],["gw2marker1","gw2marker2"]]]If some group (in this example gw1) doesn't have any vehicles and doesn't have any markers, write like this:

Code: [Select]
_groups = [[gw1],[gw2,[tank1,tank2],["gw2marker1","gw2marker2"]]]I tuned the delays down because the script runs on all machines and a possible communication problem between the server and the clients probably won't affect the deleting process at all.

Test it in a multiplayer game and report back how it works.

EDIT #1:

I have some thoughts that this might not work properly everytime for the markers. Hmm...

EDIT #2:

No, it should work.  :)

On some clients it will probably try to delete units that are already deleted but it doesn't matter, the script will just continue and hide the markers.
« Last Edit: 25 Feb 2005, 18:47:06 by Baddo »

Robinhansen

  • Guest
Re:Disable players.
« Reply #8 on: 27 Feb 2005, 13:39:37 »
It works perfectly fine when I play in multiplayer on my own computer. There's a problem  when I creat my dedicated server, then  it's impossible for me to load the game. Nothing simply happens when I push the button, even though the size of the game only is 406 kb'' ???

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re:Disable players.
« Reply #9 on: 27 Feb 2005, 14:09:58 »
Hmm.

You are saying 'impossible for me to load the game'... you mean the mission, right?

Did you get other missions to work on your dedicated server?

I don't know what the reason could be, I have no experience in running a dedi server.

But sounds weird if it works when you host the game but not when on a dedi server... or what did you mean with 'impossible for me to load the game'???

Robinhansen

  • Guest
Re:Disable players.
« Reply #10 on: 27 Feb 2005, 15:34:54 »
I mean the mission. It's tho only one that won't load. Everybody else works fine ???

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re:Disable players.
« Reply #11 on: 27 Feb 2005, 16:47:31 »
Do this:

Take my script away and try it again. If it works then we can blaim my script. If it still doesn't work, then there is something else wrong.

If you get it working without my script in it, you have to try one more time with my script and see if it works now. You might have something wrong with the PBO file.

If it doesn't work because of my script, I really don't know why it happens. You could try and make it a separate script file and call it from somewhere else than the init.sqs. Try calling it from a unit's init field or from a trigger.

« Last Edit: 27 Feb 2005, 16:53:09 by Baddo »

Robinhansen

  • Guest
Re:Disable players.
« Reply #12 on: 28 Feb 2005, 08:12:12 »
Same s***, with or without the script. So it can't be blamed on that! So I consider this case as solved! ;D
Tnx m8!! 8)