Home   Help Search Login Register  

Author Topic: Support-script [help]  (Read 2695 times)

0 Members and 1 Guest are viewing this topic.

Offline ACE5th

  • Members
  • *
Support-script [help]
« on: 27 Nov 2007, 16:51:08 »
Hi @ all

I try to script a onmapsingleclick MP support ( Artillery, Airstrike etc.) "it is my first onmapsingleclick mission"
but i've got some problems on a dedi-server.
local it works fine but on a server it wount work.


I have one trigger on the map xyz =0; condition=fireW; OnAct=["FirepointW",15,15] exec "Bomb1.sqs"; fireW = false; publicVariable "fireW";
1x soldierWB; name=Westplayer1
1x soldierWB; name=Westplayer2

in the init.sqs
Code: [Select]
?(Player == Westplayer1): Player addaction ["Light Artillary", "AriLMenue.sqs"]
?(Player == Westplayer2): Player addaction ["Light Artillary", "AriLMenue.sqs"]

fireW=false

AriLMenue.sqs
Code: [Select]
_owner = _this select 0
_doer = _this select 1
_id = _this select 2

? _doer != _owner : exit

? (playerSide == west) : _owner removeAction _id; goto "WEST"
? (playerSide == east) : _owner removeAction _id; goto "EAST"

#WEST
titletext ["Your side is west side","plain down"]
~5
onMapSingleClick '[_pos] exec "LAri.sqs"; true';titletext ["Click on the map to set your firedirection","plain down"]
exit

#East
exit

LAri.sqs
Code: [Select]
_origpos = _this select 0


onMapSingleClick ""

forceMap false

hint "Your positions have been received."
~1

_smoke = "SmokeShellGreen" createvehicle [(_origpos select 0),(_origpos select 1),0]

~0.1
"FirepointW" setMarkerPos getPos _smoke
~2
hint "fireW = true."
fireW = true
Publicvariable "fireW"
exit


bomb1.sqs
Code: [Select]
? ! (IsServer): exit
_Centre = _this select 0
_area = _this select 1
_shots= _this select 2


_CentrePos = GetMarkerPos _Centre
_xco = _CentrePos select 0
_yco = _CentrePos select 1
_zco = _CentrePos select 2

_areaX2 = _area * 2

_shots = 10

#start
~0.2
_bomb1 = "GrenadeHand" Createvehicle [_xco + Random(_areaX2) - _area,_yco + Random(_areaX2) - _area,_zco + 1]
~0.2
_shots = _shots -1
? _shots > 1: goto "Start"

Exit

The marker change the pos to the mapclick pos.
The created smoke works too,
but the Bomb1.sqs is still the old Makerpos :-(

greez
ACE5th
« Last Edit: 27 Nov 2007, 16:59:42 by ACE5th »

Offline Loyalguard

  • Former Staff
  • ****
Re: Support-script [help]
« Reply #1 on: 28 Nov 2007, 11:29:43 »
I have been pondering this since yesterday and no solution yet but I may be able to identify some areas to explore further...I have zero experience working with onMapSingleClick but I don't think that is where the problem is directly.  From the problem you describe, the disconnect must be somewhere with or between these snippets of code:

LAri.sqs:
Code: [Select]
"FirepointW" setMarkerPos getPos _smokeMoves the marker named "FirepointW" to the position of the smokeshell you just created.

Trigger On Act.:
Code: [Select]
["FirepointW",15,15] exec "Bomb1.sqs";Passes the string "FirepointW" as _this select 0 to bomb1.sqs.

bomb1.sqs:
Code: [Select]
_Centre = _this select 0Sets the value of _Centre to the string "FirepointW".

Code: [Select]
_CentrePos = GetMarkerPos _CentreSets _CentrePos as a position array with the coordinates of _Centre (which should be the coords of the marker "FirepointW").

If the above synopsis is correct (let me know if it is not) then perhaps one of the areas to explore further below might help identify the exact problem:

1) In LAri.sqs when you use the SetMarkerPos command to move "FirepointW" that should be broadcasted globally according to the Biki, so the server should have the correct coordinates for "FirepointW".  But from what you describe it does not.  How was "FirepointW" created?  Was it in the editor or in other code that we don't see here?  If in the editor, perhaps you should try creating it in a script instead?

2) One of the methods I have seen other people use for onMapSingleClick support is to use createVehicle to place a game logic or invisible heli pad to use as a target.  So perhaps after you create the smoke,use createVehicle to place a game logic at the same cooridinates and use that to find the position for bomb1.sqs.

3) Does the code in bomb1.sqs after #start really need to run on the server only.  If you just run it as a continuation of LAri.sqs (using the position of "FirePointW"), wouldn't still work as intended?  Since the script is only being run locally on the client that executed the single click, you shouldn't have unnececssary duplication of shots (only created on the client not on every client) yet anything in the impact area will still be damaged/hit/killed I think.  So maybe that is a viable approach.

I hope this helps a little, sorry I can't be more concrete.  Good luck!

Offline ACE5th

  • Members
  • *
Re: Support-script [help]
« Reply #2 on: 28 Nov 2007, 11:59:54 »
Hi Loyalguard

thx for your fast reaction

1) Yes the "FirepointW" Marker is seted with the editor.

2) About the Gamelogic, I think thats a good idea, because the logic is global right ?

3) I used this script in all my missions since OFP ;-) . its a basic bomb.sqs for me.

Im going to give you the results after the test.

thx
greez
ACE5th


Offline ACE5th

  • Members
  • *
Re: Support-script [help]
« Reply #3 on: 30 Nov 2007, 00:01:04 »
ok Loyalguard

it works fine ;-) thx !!!!!

but now i have a nuw problem.

i use a score funktion like ScoreW = ScoreW -10;

But i'd like to send this command from a local script used by a player to the score of the Side
here is the script
AirMenue.sqs started by player addaction

Code: [Select]
_owner = _this select 0
_doer = _this select 1


? _doer != _owner : exit

player removeAction AriL
player removeAction AriH
player removeAction Air
player removeAction Repair
player removeAction Ammo
player removeAction Mash

? (playerSide == west) : goto "WEST"
? (playerSide == east) : goto "EAST"


#WEST
? ScoreW < 50 : onMapSingleClick "";titletext ["Your side has not enough points","plain down"];Player addaction ["Support Menue", "Support\supportmenue.sqs"]; exit
~1
ScoreW = ScoreW - 50   <---------------------------- this
onMapSingleClick '[_pos] exec "Support\AirW.sqs"; true';titletext ["Click on the map to set your firedirection","plain down"]
~1
exit


#East
? ScoreE < 50 : onMapSingleClick "";titletext ["Your side has not enough points","plain down"];Player addaction ["Support Menue", "Support\supportmenue.sqs"]; exit
~1
ScoreE = ScoreE - 50 <---------------------------- here the same
onMapSingleClick '[_pos] exec "Support\AirE.sqs"; true';titletext ["Click on the map to set your firedirection","plain down"]
exit
« Last Edit: 30 Nov 2007, 00:02:56 by ACE5th »

Offline Loyalguard

  • Former Staff
  • ****
Re: Support-script [help]
« Reply #4 on: 30 Nov 2007, 02:38:00 »
Great!  What exactly fixed the problem?

For your scoring issue, you will need to make ScoreW (and ScoreE) a public variable with the publicVariable commandpublicVariable broadcasts the variable to all clients so everyone has the correct current value.

Here is a suggestion on how to do this (untested).  I'll try to do this in SQS but I only really know SQF so pardon any errors.  This method should be MP compatible but maybe not JIP compatible.

Initialize the variable just like you would any global variable in the init.sqs

init.sqs:
Code: [Select]
ScoreW = 0 ; Initializes the starting value as a global variable (to later be made public).
This way everybody starts with the same value.  You haven't said how the team earns points.  It is not important for this example, but, however you do it, you have to make sure you use the publicVariable command whenever the point value changes.  So, if the team does something to earn 10 points then it needs look something like this:

Code: [Select]
ScoreW = ScoreW + 10 ; Yeah!  The team earned 10 points!
publicVariable "ScoreW" ; broadcast the new value of ScoreW so all teammates know the current score after earning points.

Then when we get to AirMenue.sqs, whichever client is executing it will know the current correct value (and know if they have enough points to make the mapSingleClick request).  Also make sure to use publicVariable again to broadcast the new value of ScoreW after the script determines the team has enough points for the onMapSingleClick request:

AirMenue.sqs:
Code: [Select]
...#WEST
? ScoreW < 50 : onMapSingleClick "";titletext ["Your side has not enough points","plain down"];Player addaction ["Support Menue", "Support\supportmenue.sqs"]; exit
~1
ScoreW = ScoreW - 50
publicVariable "ScoreW" ; broadcast the new value of ScoreW so all teammates know the current score after deducting points.
onMapSingleClick '[_pos] exec "Support\AirW.sqs"; true';titletext ["Click on the map to set your firedirection","plain down"]
~1
exit
...

Ideally you would only track scores on the server in order to make sure everyone is only working from a single value, but I don't think it is necessary in your case as long as you always broadcast the new value as soon as it changes.

Good luck!

Offline ACE5th

  • Members
  • *
Re: Support-script [help]
« Reply #5 on: 30 Nov 2007, 11:10:01 »
WoW fast reacton ;-)

Thx.
Great!  What exactly fixed the problem?
I used the logic and removed in the Bomb1.sqs the first line.

greez
ACE5th

Offline ACE5th

  • Members
  • *
Re: Support-script [help]
« Reply #6 on: 13 Dec 2007, 11:49:00 »
Hi Loyalguard

Sorry i was away for one week but I've tested and it works fine. THX !!!

Now I've the next problem with the JIP

I have in the Init.sqs

Code: [Select]
?(local server):onplayerconnected "[_name,_id] exec ""jip.sqs"""
jip.sqs

Code: [Select]
_owner = _this select 0
_id = _this select 1

_owner addEventHandler ["killed", {_this exec "playerkilled.sqs"}]
_owner addaction ["Support menue", "Support\Supportmenue.sqs"]

? (playerSide == west) : menue = _owner addaction ["Respawn menue","WRespawn.sqs"]; exit
? (playerSide == east) : menue = _owner addaction ["Respawn menue","ERespawn.sqs"]; exit

but it wount work.
can u tell me what is going wrong ?

greez
ACE5th

Offline Loyalguard

  • Former Staff
  • ****
Re: Support-script [help]
« Reply #7 on: 13 Dec 2007, 12:49:53 »
Is there a particular reason you want to add the event handler and the addAction using a onPlayerConnected executed JIP script?  The reason I ask is it would seem simpler to me is to simply do this in the init.sqs like you did in your original post.  Example:

within init.sqs (untested/needs syntax and variable identifier confirmation)
Code: [Select]
?(local server): exit

_event = player addEventHandler ["killed", {_this exec "playerkilled.sqs"}]
_action = player addaction ["Support menue", "Support\Supportmenue.sqs"]

? (playerSide == west) : menue = player addaction ["Respawn menue","WRespawn.sqs"]; exit
? (playerSide == east) : menue = player addaction ["Respawn menue","ERespawn.sqs"]; exit

The init.sqs will automatically run whenever a player loads a mission, so, I don't see a reason to have to use a onPlayerConnected executed JIP update since the script would be run anyway when the player starts a mission (either at the very beginning or JIP).  If you don't want to actually put it in the init.sqs, just have the init.sqs call a playerinit.sqs or something similar.

So, I recommend the above approach unless there is another reason why you want this to be done via a JIP update.

If you have a reason for wanting to use and onPlayerConnected executed JIP update, there are still a couple of potential problems.  First, I am pretty sure you do not need to use ?(local server) for onPlayerConnected because it is always only run on the server (accordng to the Biki) - this is a minor issue I though I think.  Second, I believe both addEventHandler and addAction are local comnnads so that the effects of either command have to be local to the client.  If the commands are only being run on the server via onPlayerConnected then the commands never make it to the client.

I hope this helps..good luck!

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Support-script [help]
« Reply #8 on: 13 Dec 2007, 13:42:56 »
What Loyalguard is saying is quite true, but there is another issue in JIP, since the player variable will be objNull for a little while after the player has connected. Incidentally, the use of a logic called "server" to work out whether code is being run on the server has been obsolete since the isServer command was added (And making your users add a logic to be able to use your script is an unnecessary hassle). You will find testing easier if you only stop processing on the dedicated server ( isServer and (isNull player) ), since in SP or non-dedicated servers, one player is on the same machine as the server.

Code: (within init.sqs (untested)) [Select]
? isServer and (isNull player) : exit

@ not (isNull player)

_event = player addEventHandler ["killed", {_this exec "playerkilled.sqs"}]
_action = player addaction ["Support menue", "Support\Supportmenue.sqs"]

? (playerSide == west) : menue = player addaction ["Respawn menue","WRespawn.sqs"]; exit
? (playerSide == east) : menue = player addaction ["Respawn menue","ERespawn.sqs"]; exit
« Last Edit: 13 Dec 2007, 13:46:51 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline ACE5th

  • Members
  • *
Re: Support-script [help]
« Reply #9 on: 13 Dec 2007, 18:00:18 »
Hi again

it works !!!!   :clap: :good:

thx
« Last Edit: 13 Dec 2007, 18:35:12 by ACE5th »

Offline Loyalguard

  • Former Staff
  • ****
Re: Support-script [help]
« Reply #10 on: 13 Dec 2007, 19:09:46 »
Great news!  Also thanks to Spooner for addressing the isServer command.  I neglected to mention it.