Home   Help Search Login Register  

Author Topic: SetVelocity in multiplayer  (Read 1401 times)

0 Members and 1 Guest are viewing this topic.

Offline Artak

  • The old beanbag shaker
  • Former Staff
  • ****
  • You want to talk about it, yes?
    • OFP Team Finlanders
SetVelocity in multiplayer
« on: 12 Oct 2004, 21:51:57 »
Instead of the boring setdammage 1 or grenade explosion effects in border zone triggers, camp killers, spawn protectors, ... I want to have something different.

So I build a script which should throw the unit entering a trigger area to a direction. SetPos being so "unrealistic" I wanted to use SetVelocity, but then my troubles started.

Here's the script how it currently is:
Quote
_unit = _this select 0

#start
~0.2
?(vehicle _unit in list zone1trig) || (vehicle _unit in list zone2trig) || (vehicle _unit in list zone3trig) || (vehicle _unit in list zone4trig): goto "THROW"
goto "start"

#THROW
?_unit != (vehicle _unit): goto "THROWVEHICLE"
_unit say "boom1"
?(local _unit): hint format ["%1, you're not allowed to enter the Eastern parts of Nogova.", name _unit]
_xi = 0
_yi = 0
_zi = 0
?(speed (vehicle _unit) < 0): _dircor = 1
?(speed (vehicle _unit) > 0): _dircor = 0
#calc
(vehicle _unit) setPos [(getPos _unit select 0) - _xi * (sin(getDir _unit)),(getPos _unit select 1) - _yi * (cos(getDir _unit)),_zi]
~0.001

?_dircor == 0: _xi = _xi + 2
?_dircor == 0: _yi = _yi + 2

_zi = _zi + 8

?_dircor == 1: _xi = _xi - 2
?_dircor == 1: _yi = _yi - 2

? (getPos _unit select 2) < 150 : goto "calc"
_chute = "Parachutewest" createVehicle [getPos _unit select 0,getPos _unit select 1,getpos _unit select 2]
_chute setPos [getpos _unit select 0,getpos _unit select 1,getpos _unit select 2]
_unit moveindriver _chute
~20
goto "start"

#THROWVEHICLE
_unit say "boom1"
(vehicle _unit) setvelocity [-80-(random 50),-80+(random 160),100+(random 100)]
?(local _unit): hint format ["%1, you're not allowed to enter the Eastern parts of Nogova", name _unit]
~20
goto "start"

I know that SetVelocity doesn't work for player units directly, so as you see the script detects if the unit is in a vehicle. If he is in a vehicle then SetVelocity will be used, but if not the script will use SetPos.

Now, when testing this in MP with me being the server and MI_Fred the client we found that the server worked fine, but the SetVelocity part didn't work on the client. I could hear the "boom1" sound, but nothing happened - it's like the command had no effect on the unit.

My question is simple. Why?  :beat:


edit
I was just reading some old topic in the official forums and it says that if I setpos the unit above the ground I could then use SetVelocity on him straight, without him being in a vehicle. But that's not the point. The point is that why doesn't the SetVelocity work for the client even if he's in a vehicle.  :P


edit
Again I was reading some old posts in the official forums. One of them says that
Quote
A VEHICLE is always LOCAL to its DRIVER.
. Now I'm so confused that what's left of my brain doesn't apear to function that well.. Would that quote have anything to do with why my script doesn't work on the client?


edit
Oh, and also the part where the parachute is created, doesn't work on the client. I (server) can see an empty parachute falling from the sky after the client player dropped at 200km/h to solid ground (ouch). So maybe there's something fishy in the entire script or just the MoveInDriver command not working on the client? An earlier version created a bike and the client wasn't 'MovedInDriver' in that either.
The script is executed from init.sqs with [unitname] exec "script.sqs"
« Last Edit: 12 Oct 2004, 22:15:30 by Artak »
Not all is lost.

Offline Zayfod

  • ECP Team
  • *
  • Llama, softest natural fibre in the world.
Re:SetVelocity in multiplayer
« Reply #1 on: 22 Oct 2004, 02:33:28 »
May I suggest trying this,
havent tested tho.

Code: [Select]
? isnull player:exit
?!(local _unit):exit
#start
~5
?(vehicle _unit in list zone1trig) || (vehicle _unit in list zone2trig) || (vehicle _unit in list zone3trig) || (vehicle _unit in list zone4trig): goto "THROW"
goto "start"

A 0.2 second loop waiting for an unlikely event is very resource hungry. I suggest 5 second loop.

Isnull player check stops deddy running it.

Setvel gotta be done locally.

Hope this helps

Zay
"I have come here to kick ass and chew bubble gum......an I'm all outta bubble gum!"

Offline Artak

  • The old beanbag shaker
  • Former Staff
  • ****
  • You want to talk about it, yes?
    • OFP Team Finlanders
Re:SetVelocity in multiplayer
« Reply #2 on: 25 Oct 2004, 16:58:05 »
Hey Zayfod,

Thanks for the effort, but sadly that didn't help. I've reworked the script quite a bit, but still no score. Server player works fine, but clients not.

This is the script now:
Code: [Select]
_unit = _this select 0
;_unit = call format["%1",_name]
?!local _unit: exit
?isnull player: exit

#start
;_unit = call format["%1",_name]
~2
?(driver vehicle _unit in list zone1trig) || (driver vehicle _unit in list zone2trig) || (driver vehicle _unit in list zone3trig) || (driver vehicle _unit in list zone4trig): goto "THROW"
?(_unit in list zone1trig) || (_unit in list zone2trig) || (_unit in list zone3trig) || (_unit in list zone4trig): goto "THROW"
hint "local loop clientilla"
goto "start"

#THROW
_unit say "boom1"
hint format ["%1, you're not allowed to enter the Eastern parts of Nogova.", name _unit]
_unit setpos [getpos _unit select 0, getpos _unit select 1, (getpos _unit select 2)+5]
~0.1
_unit setvelocity [-80-(random 50),-80+(random 160),100+(random 100)]
;?_unit != (vehicle _unit) || (driver _unit != _unit): (vehicle _unit) setvelocity [-80-(random 50),-80+(random 160),100+(random 100)]
~5
@getpos _unit select 2 < 100
_chute = "Parachutewest" createVehicle [getPos _unit select 0,getPos _unit select 1,getpos _unit select 2]
_chute setPos [getpos _unit select 0,getpos _unit select 1,getpos _unit select 2]
_unit moveindriver _chute
~20
goto "start"
Not all is lost.

Offline Artak

  • The old beanbag shaker
  • Former Staff
  • ****
  • You want to talk about it, yes?
    • OFP Team Finlanders
Re:SetVelocity in multiplayer
« Reply #3 on: 26 Oct 2004, 10:14:49 »
Thanks to TJ in the BIS forums, this topic is kind of solved. The problem was triggers - they just don't work that well with remote units. When doing a distance check to a GL instead of a trigger's list check, the script works with no problems.  :)

Cheers!
Not all is lost.

Offline Artak

  • The old beanbag shaker
  • Former Staff
  • ****
  • You want to talk about it, yes?
    • OFP Team Finlanders
Re:SetVelocity in multiplayer
« Reply #4 on: 26 Oct 2004, 17:29:45 »
Code: [Select]
_name = _this select 0
_unit = call format["%1",_name]
?!local _unit: exit

#start
_unit = call format["%1",_name]
~2
?(vehicle _unit) distance zone1 < 2000 || (vehicle _unit) distance zone2 < 2000: goto "THROW"
goto "start"

#THROW
hint "boom"
_unit say "boom1"
hint format ["%1, you're not allowed to enter the Eastern parts of Nogova.", name _unit]
?(vehicle _unit) == _unit: (vehicle _unit) setpos [getpos _unit select 0, getpos _unit select 1, (getpos _unit select 2)+5]
~0.1
(vehicle _unit) setvelocity [-80-(random 50),-80+(random 160),100+(random 100)]
?(vehicle _unit) == _unit: (vehicle _unit) switchmove "FXStandSur"
~5
@getpos _unit select 2 < 100
?(vehicle _unit) == _unit: _chute = "Parachutewest" createVehicle [getPos _unit select 0,getPos _unit select 1,getpos _unit select 2]
?(vehicle _unit) == _unit: _chute setPos [getpos _unit select 0,getpos _unit select 1,getpos _unit select 2]
?(vehicle _unit) == _unit: _unit moveindriver _chute
~20
goto "start"

This is the final version of the bouncer script. Cheers!  :D
Not all is lost.