Jump to content
Sign in to follow this  
Drongo69

Rearm scripts in MP

Recommended Posts

I am trying to make a script that rearms all units in one squad in MP. The initial call is from a radio trigger which calls this script:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

; client side rearm call

client_code = 5

~0.1

publicvariable "client_code"

#end

~0.2

client_code = 0

exit

This is picked up and interpreted by the server_loop.sqs which calls SERVER\rearm.sqs.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

client_code = 0

~0.1

{if (alive _x) then {[_x] exec "friendly\rearm.sqs"}} ForEach units player_group

exit

Friendly\rearm.sqs basically checks the unit's primary weapon and depending on the result deletes and adds magazines. It's a big script so I won't paste it all, but it the key part of it is:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

; hd clips

_troop = _this select 0

~0.2

; wait to reduce CPU load

~(random 2)

#rearm

; rearm the troop if he is within

_d1 = _troop distance armoury

~0.2

_d2 = _troop distance resupply

~0.2

? (_d1 < 99) OR (_d2 < 99) : goto "go"

exit

#go

~0.2

_troop removemagazines "handgrenade"

_troop removemagazines "Flare"

_troop removemagazines "Flaregreen"

_troop removemagazines "Flarered"

_troop removemagazines "Flareyellow"

_troop removemagazines "Flareyellow"

_troop removemagazines "smokeshell"

_troop removemagazines "smokeshellgreen"

_troop removemagazines "smokeshellred"

~0.1

_troop removemagazines "sebm16a1mag"

_troop removemagazines "sebm14mag"

_troop removemagazines "sebcar15mag"

_troop removemagazines "sebm79HEammobag"

_troop removemagazines "sebm60mag"

_troop removemagazines "sebm1911mag"

_troop removemagazines "sebm79he"

_troop removemagazines "sebm79buck"

_troop removemagazines "seblawrocket"

_weapon = primaryweapon _troop

? (_weapon == "sebm16a1") : goto "m16a1"

? (_weapon == "sebm60") : goto "m60"

? (_weapon == "sebm60s") : goto "m60"

? (_weapon == "sebm79") : goto "m79"

#m16a1

_troop addmagazine "sebm16a1mag"

_troop addmagazine "sebm16a1mag"

_troop addmagazine "sebm16a1mag"

_troop addmagazine "sebm16a1mag"

_troop addmagazine "sebm16a1mag"

_troop addmagazine "sebm16a1mag"

_troop addmagazine "sebm16a1mag"

_troop addmagazine "sebm16a1mag"

_troop addmagazine "handgrenade"

_troop addmagazine "handgrenade"

goto "end"

I want this script to run on every AI and human player in the player_group group. However, I am not sure about how locality will affect this.

My questions are as follows:

1) Since this script is run ONLY on the server (through server_loop), will it rearm all human players?

2) Will it work on AI units if the squad leader is not also the server?

Share this post


Link to post
Share on other sites

If you're running a script meant to equip units on a dedicated server, then it has to run locally on each client in order to work. The same goes for if you're adding weapons to an ammo crate, you've got to have a script run on each client so each client will have weapons to choose from.

AI in your group are local to you, and AI in another player's group are local to him. Players in your group are remote to you. AI not in any player's group are local to the server.

A Radio trigger is global, i.e. it exec's on all clients. I would suggest you run your script straight from the radio command because then it'll run on all clients and you can filter out those you don't wish to be rearmed from your script.

If you wish to run the command from an action, then remember that all added actions are local to the unit that uses them. In that case, exec your rearm script from init.sqs and have it wait on a public variable. When you click the action, have it call that global var and then public var it.

Oddly enough, even though ammo crates are local when loaded with weapons, they also have a global pool. I have a weapons purchase script for RTS3, where you purchase weapons and they are put into the ammo crate for you to take. If you and another player purchase the same weapons, even though the weapons are loaded locally to each client and you can't see what's in the ammo crate for the other player, if he takes the same weapon from the crate that you also put there, then it globally reduces the count of that weapon/ammo from the crate, so yours would be taken.

OFP MP scripting is loads of fun to figure out at times. I think I'd almost wish to have all commands global and then you could filter out everyone you didn't want from the script. Ah well.

Hope this helps.

Share this post


Link to post
Share on other sites

That is very helpful info, thank you very much. smile_o.gif I have another question.

Quote[/b] ]AI in your group are local to you, and AI in another player's group are local to him. Players in your group are remote to you. AI not in any player's group are local to the server.

If an AI in the player's group is killed and I want to delete it (simulating a medevac), where should I run the script? Is the dead loon still local to the squad leader?

Share this post


Link to post
Share on other sites

If you use a "killed" eventhandler, then when the AI dies, it will run the script local to the killed unit and the killer of the unit.  You can have the script use

DeleteVehicle _unit

for example.  Deletevehicle can be run locally or remotely, it doesn't matter, it's always a global public command.

A killed eventhandler is probably the best way to go, but you could also put in the init of the AI something like

[this] exec "deathmonitor.sqs"

And deathmonitor would do this:

Quote[/b] ]

;;Begin Deathmonitor

_unit = _this select 0

;;runs only local to the unit

?!Local _unit : Exit

#Monitor

~1

?Alive _unit : goto "Monitor"

;;length of pause before deletion

~60

Deletevehicle _unit

;;end Deathmonitor

Now, the downside of this is that it's a loop which is constantly checking the status of the unit.  I'm not sure if eventhandlers are much the same, i.e. they're constantly checking for a certain state to be true, but I prefer to use eventhandlers for unit deletion.

To use the Killed eventhandler, simply put this in the init of the unit in the mission editor:

Quote[/b] ]

this addEventHandler ["killed",{_this exec "removeDead.sqs"}]

And then the script for it would be like so:

Quote[/b] ]

;;Begin removeDead.sqs

_unit = _this select 0

_vcl = Vehicle _unit

;;this removes the unit from any vehicle it might be in

_unit Setpos Getpos _unit

;;whatever pause u wish

~15

deletevehicle _unit

exit

;;end  removedead.sqs

If you have a lot of units on a map and you don't want to have to go thru each one's init to put that, simply create a trigger that is triggered by East, west or whatever side it is and name it WestList, then in init.sqs put this:

Quote[/b] ]

~1

@Count list WestList > 0

"_x addEventHandler [{killed},{_this exec {removeDead.sqs}}]" foreach list WestList

Then it'll add the eventhandlers to all units that trigger that trigger list.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×