Home   Help Search Login Register  

Author Topic: Taser Mod Script Help  (Read 17135 times)

0 Members and 1 Guest are viewing this topic.

Offline bluevein

  • Members
  • *
Taser Mod Script Help
« on: 25 Aug 2008, 15:05:54 »
Hi all,

Ok the City Life team are working on a Taser Mod but are stuck on getting it to work  :blink:

Here is the script:

Code: [Select]
_target_bullet = objNull;
_target = objNull;
_deadfirst = false;
_gunner = ( ( _this select 0 ) select 0 );
_type = ( ( _this select 0 ) select 4 );
while {isNull _target_bullet} do
{
  _lista = _gunner nearObjects [ _type, 100 ];
  if ( count _lista > 0 ) then
        {
            _target_bullet = _lista select 0;
        };
      Sleep 0.0001;
};
while {isNull _target} do
{
  if ( ! isnull _target_bullet ) then{
              _listb = _target_bullet nearObjects [ "man", 1.2 ];
              if ( count _listb > 0 ) then
              {
                  _target = _listb select 0;
              };
          };
  Sleep 0.001;
};
if ( alive _target ) then
  {
      _deadfirst = false;
  }else
  {
      _deadfirst = true;
  };
sleep 0.05;
if ( _deadfirst ) exitwith
  {
      hint "Please don't tazer dead people, it's not nice";
  };
if ( !_deadfirst ) then
  {
      _target playmove "AdthPercMstpSnonWnonDnon_3";
      _target setmimic "surprised";
  };
if ( player == _target ) then
  {
      hint format [ "You just got tasered by %1", ( name _gunner ) ];
  };
if ( player == _gunner ) then
  {
      hint format [ "You have sucessfully tasered %1", ( name _target ) ];
  };
if ( ( _target == _gunner ) && ( player == _gunner ) ) then
  {
      hint format [ "Well done %1, you tasered yourself :(", ( name _gunner ) ];
  };
_i = 0;
_i2 = 0;
while {( _gunner distance _target ) > 5 || _i <= 40}do
{
  if ( _i2 < 25 && ( player == _target ) ) then
      {
          titleText [ " ", "WHITE IN" ];
      };
      _target setdir ( getdir _target + 1 );
      sleep 0.04;
      if ( _i2 < 25 && ( player == _target ) ) then
          {
              titleText [ " ", "BLACK OUT" ];
          };
          _target setdir ( getdir _target - 1 );
          _i = _i + 1;
          _i2 = _i2 + 1;
          sleep 0.025;
};
_i = 0;
_i2 = 0;
_num = ( random 3 ) + 3;
sleep _num;
if ( player == _target ) then
  {
      titleText [ " ", "BLACK IN" ];
  };
_target switchmove "AidlPpneMstpSrasWrflDnon02";
_target setdammage ( getdammage _target + 0.15 );
sleep 1;
if ( alive _target ) then
  {
      _deadfirst = false;
  }else
  {
      _deadfirst = true;
  };
if ( !alive _target ) then
  {
      hint format [ "You killed %1 with your taser. It is meant to be used as a non lethal weapon only", name _target ];
  };
if ( _deadfirst ) then
  {
      hint "Please don't tazer dead people, it's not nice";
  };

However it dosen't seem to taser any one, what I think we need is a script to run a server side loop that checks this script to make the player carry out these animations?

Any help will be appreciated! Thanks in advanced  :good:

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Taser Mod Script Help
« Reply #1 on: 25 Aug 2008, 15:26:21 »
playMove , setdammage and setMimic are local commands, like particle effects. You need to tell the tazed player's machine to taze him, rather than trying to do this all on the local machine, which will have no effect on remote player objects.

e.g. (all code untested)

Code: (init.sqf) [Select]
// We want to know when someone has been tazed on every machine.
"taze" addPublicVariableEventHandler
{
    _params = _this select 1;
    _shooter = _params select 0;
    _target = _params select 1;
   
    // Ignore event if the player wasn't the one targeted.
    if (_target == player) then
    {
        // <-- Tell player that he was tazed by the shooter.
        // <-- Apply taze effects on player.
        [] spawn // Must spawn, since you can't sleep/waitUntil inside an event handler.
        {
             // <-- Wait until tazing stops, then remove paralysis.
        };
    };
};

Code: (when your script wants to perform tazing effect in MP) [Select]
taze = [player, _target];
publicVariable "taze";

Remember that using addPublicVariableEventHandler will stop the code working on local AI (presumably what you used to get the script working in the first place), since the handler is only called on machines other than the one that performed the publicVariable.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline bluevein

  • Members
  • *
Re: Taser Mod Script Help
« Reply #2 on: 25 Aug 2008, 16:06:38 »
Nice one thanks spooner for the advice  :yes:

I'll put the working example up here as soon as we complete it  :good:

Offline JasonO

  • OFPEC Patron
  • ****
  • Oh no...
    • The New Life RPG
Re: Taser Mod Script Help
« Reply #3 on: 31 Aug 2008, 02:07:25 »
I started work on a taser gun itself a few months ago (video here - 2mb wmv.

It worked as I wanted.. but in MP the problem was having it work on other machines other than just set players. Should come quite handy.

Offline ModestNovice

  • Members
  • *
Re: Taser Mod Script Help
« Reply #4 on: 10 Sep 2008, 01:09:32 »
well here my newest attempt?

How it looks Spooner??


init.sqf
Code: [Select]
player addEventHandler ["fired", {_this execVM "tase.sqf"}];


tase.sqf
Code: [Select]
bullet = "stuncharge";
a_bullet = nearestObject [player, bullet];
stun_array = [];
p_to_hit = objNull;

while {!isNull a_bullet} do
{
     target = nearestObjects [a_bullet, ["Man"], 1.8];
     the_target = target select 0;
     stun_array = [the_target];
};

stun_target = stun_array select 0;
call compile format ["p_to_hit = %1 switchmove ""TestSurrender""", stun_target];
publicVariable "p_to_hit";
« Last Edit: 10 Sep 2008, 01:11:19 by DaChevs »
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Taser Mod Script Help
« Reply #5 on: 10 Sep 2008, 18:28:42 »
Your should reread this and this before proceding.
 
Code: [Select]
player addEventHandler ["Fired", {[_this, "StunCharge"] call trackTaser}];
Code: [Select]
"taserData" addPublicVariableEventHandler {(_this select 1) spawn taserEffects};
Code: [Select]
[] call compile preprocessFileLineNumbers "initTaser.sqf";
initTaser.sqf
Code: [Select]
trackTaser =
{
    private ["_source", "_ammoFired", "_ammoType"];
    _source = (_this select 0) select 0;
    _ammoFired = (_this select 0) select 4;
    _ammoType = _this select 1;
    if (_ammoFired == _ammoType) then
    {
        [_source, nearestObject [_source, _ammoFired]] spawn
        {
            private ["_source", "_bullet", "_pos", "_targetArray", "_target"];
            _source = _this select 0;
            _bullet = _this select 1;     
            while {!isNull _bullet} do
            {
                _pos =   getPos _bullet;
            };
            _targetArray = nearestObjects [_pos, ["Man"], 1.8];
// Put your code here to sort through targets if you get more than one.
// I doubt nearestObjects sorts according to position, so you might want
// to check that you have the right target. Use Mando Angles
// and/or distance to _pos and/or distance from _source. I'll assume you have done
// this and assigned it to the variable _target.
            taserData = [_source, _target];
            publicVariable "taserData";
//call taser effects routine locally since PV will not work for the shooter.
            taserData spawn taserEffects;
        };
    };
};

taserEffects = 
{
    private ["_source", "_target"];
    _source = _this select 0;
    _target = _this select 1;
    // Put all effect related stuff here i.e drop commands, sounds etc, global messages.
    //
    if (local _target) then
    {
        //If setdamage target then do it here.
        //Display messages for target only in here.
     };
    if (local _source) then
    {
        //Display messages for shooter only here.
     };
};


And if the player hits a corpse, why not make the corpe twitch a little? Would be fun!  >:D

p.s. make sure you got the last edit of this!
« Last Edit: 10 Sep 2008, 18:48:49 by Mr.Peanut »
urp!

Offline ModestNovice

  • Members
  • *
Re: Taser Mod Script Help
« Reply #6 on: 11 Sep 2008, 01:19:41 »
Wow thanks Mr.Peanut :)
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Taser Mod Script Help
« Reply #7 on: 11 Sep 2008, 16:05:05 »
Don't thank me yet. That code is untested.  You'll have to let me know if it works. :P
urp!

Offline bluevein

  • Members
  • *
Re: Taser Mod Script Help
« Reply #8 on: 11 Sep 2008, 23:20:02 »
Just trying now "Fingers X'd"

Offline ModestNovice

  • Members
  • *
Re: Taser Mod Script Help
« Reply #9 on: 12 Sep 2008, 01:40:39 »
OMG!!!!


IT WORKS!!!!

Mr.Peanut...I have no words to express my love rofl :P

jk

but thanks a bunch.  ;)



*EDIT*

OKAY!

ROFL

New question...


I use the drop command, so it puts their weapons on the ground, but it seems to be funky, cuz, although they can pick it up, its doesnt delete the weapon off the ground, only in MP that is...


Any ideas?
« Last Edit: 12 Sep 2008, 04:59:49 by DaChevs »
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Taser Mod Script Help
« Reply #10 on: 12 Sep 2008, 13:55:54 »
LOL, I meant "drop" as in particle effects, not drop weapon. In the area I marked for global effects I thought you would include:

1) some flashy spark-like particles
2) a "zzztt" sound and maybe the target screaming
3) a switchMove or playMove to make the target unit fall to the ground

I don't do particles since OFP so you'll need to get help elsewhere with those. To make the "zzzt" sound, createVehicleLocal a game-logic at the target position, have it say the "zzzzzt" sound, and then delete it. Use say command to make the target scream something. I am not sure what "switchMove" or "playMove" would be appropriate. Ask JasonO since his Taser movie seemed to do that well. edit: Choosing the right animation might not be so easy, since it depends or what the target was doing when he was tased.
« Last Edit: 12 Sep 2008, 14:15:47 by Mr.Peanut »
urp!

Offline ModestNovice

  • Members
  • *
Re: Taser Mod Script Help
« Reply #11 on: 13 Sep 2008, 00:43:16 »
no thats not what I meant. I meant that I use dropWeapon and put their weapons on the ground, but it doesnt delete the weapon when they pick it up...
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Taser Mod Script Help
« Reply #12 on: 13 Sep 2008, 17:50:16 »
You mean "DropWeapon" using the action command? Are you calling that command in the area I indicated for global effects? And are you doing this so that the other player can pick it up? Are all taser targets players in your mod?
urp!

Offline ModestNovice

  • Members
  • *
Re: Taser Mod Script Help
« Reply #13 on: 13 Sep 2008, 18:29:07 »
yeh I did it in the area for global.

ArMaTeC said I must do like:
Code: [Select]
if (!isServer) exitWith {};
_target action ["DropWeapon", blabla, bla];
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Taser Mod Script Help
« Reply #14 on: 13 Sep 2008, 19:24:45 »
Why do people never answer all of my questions? I asked four and you answered but one. How I can I help if you do that? If you are doing this simply for effect, I would use an animation, but I am guessing(since you didn't answer) that you want to be able to steal the target's weapon after tasing him.

I revisited the Biki page on action.  You should put the "DropWeapon" action in the if (local _target) section. Action acts on local units with global effects.
« Last Edit: 13 Sep 2008, 19:27:24 by Mr.Peanut »
urp!