Jump to content
Sign in to follow this  
bigduke6

Addaction only for unit added to

Recommended Posts

Guys,

I'm writing a few scripts for co-op MP to get round the fact that you can't detonate or use each others satchel charges if one player dies, and also the fact that you have to detonate them all at the same time rather than being able to blow one at a time.

So, to cut a long story short as part of the process I have a script which does this

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">p1placecharge1 = p1 addAction ["Place explosive 1", "Placecharge1.sqs"]

where p1 is player1, etc, which works fine.

The problem is when another player walks close and looks at the player with this action, the action also appears in their action menu, like if I'd added the acton to an object which could be used by anybody. Then can then place the charge which is on the other player, essentially nicking it off them.

So, the question. How do I make the action only show up and therefore useable to the player I've actually added it to, rather than anyone who happens to be close enough and looking at them.

Thanks in advance.

Mart

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if (local p1) then {p1placecharge1 = p1 addAction ["Place explosive 1", "Placecharge1.sqs"]}; smile_o.gif

Share this post


Link to post
Share on other sites

Seems like, this script is run on all clients at the same time.

As far as I understood, you want to have this action only on the player that matches the content of variable "p1".

You can use this to exit the script on all clients, that don't match to the variable "p1". The pre-defined "player" variable is different on all clients.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if(p1 != player) exitWith{};

Or if you want to have the other commands executed in this script on other clients aswell, then just put a "if" around the addaction command:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if(p1 == player) then {p1placecharge1 = p1 addAction ["Place explosive 1", "Placecharge1.sqs"];};

If possible, move those checks one level higher. It's better to check the correct enviroment before executing the script. That keeps the script itself simple and good readable.

Multiplayer scripting is a bit tricky, i know. You have to pay attention to where you execute your scripts, i.e. on all clients, or just on a certain one.

Share this post


Link to post
Share on other sites
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if (local p1) then {p1placecharge1 = p1 addAction ["Place explosive 1", "Placecharge1.sqs"]};
smile_o.gif

probably need to add a jip check:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if (not isServer) then { waitUntil { player == player } }; if (local p1) then { p1placecharge1 = p1 addAction ["Place explosive 1", "Placecharge1.sqs"] }; smile_o.gif

Also instead of using p1. in this case "player" could be used.

Also for teamSwitch or respawn in AI, a check if the player object still represents the original object might and if not, remove action from other object and add action to this object, might be necessary aswell wink_o.gif

Share this post


Link to post
Share on other sites

Guys, thanks for the replies but maybe I didn't explain it enough as I think you've got the wrong idea.

I can successfully add the action ONLY to the required player ( there is a series of action menu commands which the team leader uses to keep an explosive or issue it to one of his team, and the person so issued with each explosive gets a corresponding 'Place explosive 1', etc in their menu).

The problem is if, say the team leader gives all the charges to soldier p1, and gives none to another soldier, say p2, when I teamswitch to soldier p2 while testing the mission, while he is away from soldier p1 everything is fine, there are no actions in his menu.

The problem is when I move p2 close to p1 and look at him, the 'Place explosive 1', 'Place explosive 2' and 'Place explosive 3' actions appear in p2's action menu, even though he has no explosves. As soon as p2 looks away or moves away from p1 the action gets removed from the action menu.

It's like if you add an action to an object, say a house, when you get close enough, I think 3m or 5m and look at it, the action appears in your action menu, and then gets removed if you look away or move too far away again.

I can nullify the action by checking in the script who activated the action and if it's not the person carrying the appropriate explosive I can make it exit, but I'd rather keep it tidy and not have the action appear at all.

Although, thinking about it now, if you can only do it while close enough to the other player and while looking at him, I suppose you could reason that you're getting the charge out of his backpack and setting it for him, while he's firing or something. Hmm, that's going to play havoc with my scripts though, having a different person setting a charge from the person carrying it....

But I'd still like to know if it's possible to stop added actions for one soldier appearing in another soldiers menu when he gets close.

Regards, Mart

Share this post


Link to post
Share on other sites

This is exactly what we both understood, im fairly certain.

You will have to use the if (local player) etc. etc. stuff to make sure the action doesnt appear on someone else's computer.

Share this post


Link to post
Share on other sites

Ah, apologies.

I thought that code would add the action to the local p1 soldier, still leaving me the same problem when other soldiers came close.

I was thinking of how to restrict it from other soldiers, when simply by restricting it from other computers you get the same effect. Hey presto.

Thanks.

Cheers, Mart

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  

×