Jump to content
Sign in to follow this  
kinismo

How to execute script only on server?

Recommended Posts

Yes i would like to know how can i get this script to execute only on server? Now it seems to execute on every client so artillery strikes multiplies as many times as there is players.

I call this script from cannon's init field:

[this] exec "art.sqs"

Quote[/b] ]

#loop

_arty = _this select 0

_posX = getMarkerPos "tgt" select 0

_posY = getMarkerPos "tgt" select 1

_arty doWatch [_posx, _posy, 6000]

~((random 2.5) + 3)

_arty fire "M119"

~8

_posX = _posX + ((random 1000) - 500)

_posY = _posy + ((random 1000) - 500)

"SH_105_HE" createVehicle [_posx, _posy, 0]

IMPACT = true;

if (local server) then {publicVariable "IMPACT"}

arty1 setVehicleAmmo 1; arty2 setVehicleAmmo 1;arty3 setVehicleAmmo 1;

if (alive arty1 and alive arty2 and alive arty3) then {goto "Loop"};

exit

Share this post


Link to post
Share on other sites

? = if, ! = not, isServer = is Server, : = then exit

So ?! (isServer): exit = If this is not the server then exit the script

Share this post


Link to post
Share on other sites

Most operators can be written in 2 ways: text or symbol

? if

! not

: then

&& and

it doesn't matter what you prefer, just for better readings i suggest you choose one way and keep this up smile_o.gif

Share this post


Link to post
Share on other sites
Quote[/b] ]? = if, ! = not, isServer = is Server, : = then exit

isServer returns a value of type boolean, which is either true or false. You probably implied that, SNK, just wanted to make the implication explicit for the untrained programmer. Moreover, the whole construct ( ?: ) is just an abbreviated way for simple if-control structures (if-then).

Edit: Markup, spelling

Share this post


Link to post
Share on other sites

One more question.

What if difference between:

?! (isServer): exit

and

?!(local server) : goto exit

?

Share this post


Link to post
Share on other sites

Before the isServer command was available, you could check by creating a game logic (in your question called server) on the map and check for its availability by <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">?!(local server)

So if the logic is available, it means it's the server.

The isServer command has made this construction redundant basically.

Share this post


Link to post
Share on other sites
Quote[/b] ]

?! (isServer): exit

Is one command directly.

Quote[/b] ]

?!(local server) : goto exit

Here only Local is the command server is one logical in the game that you need create and put the name server or one soldier is indiferent, here you ask to the game if the object named server is running in the local machine, because the local machine is the first in load the object.

wink_o.gif

Share this post


Link to post
Share on other sites

Well the Biki say:

Quote[/b] ]

; OFP example: all game logic objects are local to the server at all times,

; so by placing a reference game logic we get the equivalent of isServer

; this code is deprecated in ArmA

?(!local someGameLogic): exit

this code is deprecated in ArmA

Share this post


Link to post
Share on other sites
Well the Biki say:
Quote[/b] ]

; OFP example: all game logic objects are local to the server at all times,

; so by placing a reference game logic we get the equivalent of isServer

; this code is deprecated in ArmA

?(!local someGameLogic): exit

this code is deprecated in ArmA

So, its what, less efficient/uses up more resources than the newer examples given? Because this still works :

?!(local server) : whatever

Or are you referring to this not working at all ?(!local server)

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  

×