Jump to content
Sign in to follow this  
D.murphy man

2 zombie related proplems

Recommended Posts

Hey peeps!

I have to proplems witch im trying to solve.

Proplem 1

I've been trying to get my 'Zombies' to target the closes non-zombie OR get them to target the closes person in my group.

Here is what the zombie.sqs witch controls the zombies movement and attacking looks like:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_zombie=_this select 0;

_target = nearestobject [_zombie,"OfficerWnight"]

; Wait a while before "activate" the zombie. This to lighten the load while spawning a lot of

; zombies, since each one executes this script on creation.

~(5 + random 5)

[_zombie] join grpNull;

_zombie addweapon {strokefist};

_zombie setbehaviour {careless};

_zombie setunitpos {up};

_zombie setdammage 0.80;

[_zombie] exec "toughunit.sqs";

?debug:info globalChat format ["%1 active and searching",name _zombie]

#main

; Zombie dead or deleteVehicle:d?

? !(alive _zombie) or (isNull _zombie):exit

;_zombie domove (getpos _target)

? _zombie distance _target > 5 : _zombie doMove getPos _target

? _zombie distance _target <= 1 : _zombie addMagazine "StrokeFist"; goto "attack"

? _zombie distance _target > 1 && _zombie distance _target <= 5 : goto "engage"

~1

goto "main"

#engage

_nX = getPos _target select 0

_nY = getPos _target select 1

_zombie setPos [_nX, _nY]

goto "main"

#attack

_target globalchat "arrrgghh get it off me!! Heeeelllpp!!"

_zombie fire "StrokeFist"

_x = random 2

? _x <= 1 : _target setDammage (getDammage _target + 0.1)

~1

_zombie removeMagazines "StrokeFist"

goto "main"

#dead

exit

As you can see i have had a go at the nearestobject command,and this works fine intill i place more then 2 west officers down,then the zombies seem to get confused and do a strange be histrical dance rock.gif

What i need is for one of you nice people in the great OFP editing comunity biggrin_o.gif to teach me how to creat a list of the people in my group,get the zombie to read the list and look for closest person to him,go and eat the closes person to him.Or somthing similer

Proplem 2

I have a edited Toughunit.sqs (makes units harder to kill) orginaly made by SnYpir,and edited for the skye virus by my good mate Pablo. But it dose not seem to work on all computers in mutliplayer on host computer. So i ask you,how can i solve this proplem?

Heres the toughunit.sqs:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">;by snYpir

;morpj97@hn.ozemail.com.au

;edited (very little) by pablo for Skye Virus

;pablo_m123@yahoo.com

;original script can be found at:

;http://www.ofpec.com/editors/resource_view.php?id=239

;or if that isn't working just search on www.ofpec.com

_pause = 0.1

_dude = _this select 0

_damageFactor = ((random 2) + 5)

; if this equals true the soldier will die as soon as damage equals 1

; (rather than being brought back to life several times before death)

; default is false

_noResurrection = false

_damage = getdammage _dude

#loop1

; this will simulate one shot, one kill if damage is made greater

; than one for some reason (big explosion, head shot)

? NOT(alive _dude) AND _noResurrection : goto "end"

?(_damage >= .9) : goto "end"

? _damage != (GetDammage _dude) : goto "takedamage"

?!(alive _dude) : goto "end"

#damagedone

~_pause

goto "loop1"

#takedamage

_damagetotake = (GetDammage _dude) - _damage

_damagetotake = _damagetotake / _damageFactor

_dude setdammage ( _damage + _damagetotake )

_damage = GetDammage _dude

;uncomment if u want to know the damage of the dude after being shot

;hint format ["%1",GetDammage _dude]

goto "damagedone"

#end

_dude addrating 99999

exit

Share this post


Link to post
Share on other sites

1. Try this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_zombie= _this select 0

_group = _this select 1

; --- Find the closted unit in the players group-------------

_distance = []

_list = units _group

_unitnum = count _list

_i = 0

#loop

_distance = _distance + [(_zombie distance (_list select _i))]

_i = _i + 1

?_i < _unitnum: goto "loop"

_i = 0

_ii = 1

_distancenum = (count _distance) - 1

#loop2

_largetest = _distance select _i

_next = _distance select _ii

? _i >= _distancenum || _ii >= _distancenum: goto "next"

? _largetest > _next: _i = _i + 1;goto "loop2"

_ii = _ii + 1

goto "loop2"

#next

?_largetest >= _next: _nearest = _next

?_largetest < _next: _nearest = _largetest

_i = 0

#unit

? _distance select _i == _nearest : goto "found"

? _i >= (count _distance): hint "error": exit

_i = _i + 1

goto "unit"

#found

_nearestunit = _list select _i

; -------------found unit ----------------

_target = _nearestunit

; Wait a while before "activate" the zombie. This to lighten the load while spawning a lot of

; zombies, since each one executes this script on creation.

~(5 + random 5)

[_zombie] join grpNull;

_zombie addweapon {strokefist};

_zombie setbehaviour {careless};

_zombie setunitpos {up};

_zombie setdammage 0.80;

[_zombie] exec "toughunit.sqs";

?debug:info globalChat format ["%1 active and searching",name _zombie]

#main

; Zombie dead or deleteVehicle:d?

? !(alive _zombie) or (isNull _zombie):exit

;_zombie domove (getpos _target)

? _zombie distance _target > 5 : _zombie doMove getPos _target

? _zombie distance _target <= 1 : _zombie addMagazine "StrokeFist"; goto "attack"

? _zombie distance _target > 1 && _zombie distance _target <= 5 : goto "engage"

~1

goto "main"

#engage

_nX = getPos _target select 0

_nY = getPos _target select 1

_zombie setPos [_nX, _nY]

goto "main"

#attack

_target globalchat "arrrgghh get it off me!! Heeeelllpp!!"

_zombie fire "StrokeFist"

_x = random 2

? _x <= 1 : _target setDammage (getDammage _target + 0.1)

~1

_zombie removeMagazines "StrokeFist"

goto "main"

#dead

exit

I don't know if that will work, I just wrote it so it has not been tested (it could do with some cleaning up, you may want to do that if you have sometime) You need to activate it with: [zombie, name of players group]

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

;by snYpir

;morpj97@hn.ozemail.com.au

;edited (very little) by pablo for Skye Virus

;pablo_m123@yahoo.com

;original script can be found at:

;http://www.ofpec.com/editors/resource_view.php?id=239

;or if that isn't working just search on www.ofpec.com

?!(local server): exit

_pause = 0.1

_dude = _this select 0

_damageFactor = ((random 2) + 5)

; if this equals true the soldier will die as soon as damage equals 1

; (rather than being brought back to life several times before death)

; default is false

_noResurrection = false

_damage = getdammage _dude

#loop1

; this will simulate one shot, one kill if damage is made greater

; than one for some reason (big explosion, head shot)

? NOT(alive _dude) AND _noResurrection : goto "end"

?(_damage >= .9) : goto "end"

? _damage != (GetDammage _dude) : goto "takedamage"

?!(alive _dude) : goto "end"

#damagedone

~_pause

goto "loop1"

#takedamage

_damagetotake = (GetDammage _dude) - _damage

_damagetotake = _damagetotake / _damageFactor

_dude setdammage ( _damage + _damagetotake )

_damage = GetDammage _dude

;uncomment if u want to know the damage of the dude after being shot

;hint format ["%1",GetDammage _dude]

goto "damagedone"

#end

_dude addrating 99999

exit

I have not tested this either, make sure there is a gamelogic on the map named server.

RED

Share this post


Link to post
Share on other sites

Thnx for your help RED as allways smile_o.gif but the zombie.sqs is a no go.

Nuthing happens,no warning message or any thing.

and i havent tested the toughunit.sqs yet.

Share this post


Link to post
Share on other sites

Are you sure the units are in your group? I just tested it and it works if man2 and man3 are in the same group as the man1 (I may have an old version though, v3.03 I think).

You can modify the script very easily if you do not want the units to be grouped, change this part of the script:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

; --- Find the closted unit in the players group-------------

_distance = []

_list = units _group

_unitnum = count _list

_i = 0

To

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

; --- Find the closted unit in the players group-------------

_distance = []

_list = [man1, man2, man3, etc]

_unitnum = count _list

_i = 0

RED

Share this post


Link to post
Share on other sites

Yay i got it working now thnx RED. Only one slight proplem!

The zombies only go for the person closes to them when they spawn and now when i new target comes closer then the old one,allso they keeep going for the target even when its dead. But i solved this with adding simple deletvehicle command to the target when he dies.

So how do i make the zombie constantly aware of who closes? I tried fiddling with loops but i keep getting a "error zero divider" warning.

Share this post


Link to post
Share on other sites

Doing that would make it slightly more complicated, you would have to have 2 scripts running for each zombie (or maybe just one script running for each group of zombies) 1 script would control the movement of each unit, the other script would be constantly detecting which unit is closer to a player. The detection script would then transmit a publicvariable to all the other scripts that would alter their target.

I would also like to see the zombies target a new player after they have killed their first target.

Also if all the players are killed bar one, you must set the _target to that player as the detection script only works for 2 or more units. Make this change to the script:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_zombie= _this select 0

_group = _this select 1

; --- Find the closted unit in the players group-------------

_distance = []

_list = units _group

_unitnum = count _list

_i = 0

?_unitnum == 1: _target = (_list select 0); goto "skipd"

#loop

_distance = _distance + [(_zombie distance (_list select _i))]

_i = _i + 1

?_i < _unitnum: goto "loop"

_i = 0

_ii = 1

_distancenum = (count _distance) - 1

#loop2

_largetest = _distance select _i

_next = _distance select _ii

? _i >= _distancenum || _ii >= _distancenum: goto "next"

? _largetest > _next: _i = _i + 1;goto "loop2"

_ii = _ii + 1

goto "loop2"

#next

?_largetest >= _next: _nearest = _next

?_largetest < _next: _nearest = _largetest

_i = 0

#unit

? _distance select _i == _nearest : goto "found"

? _i >= (count _distance): hint "error": exit

_i = _i + 1

goto "unit"

#found

_nearestunit = _list select _i

; -------------found unit ----------------

#skipd

_target = _nearestunit

; Wait a while before "activate" the zombie. This to lighten the load while spawning a lot of

; zombies, since each one executes this script on creation.

~(5 + random 5)

[_zombie] join grpNull;

_zombie addweapon {strokefist};

_zombie setbehaviour {careless};

_zombie setunitpos {up};

_zombie setdammage 0.80;

[_zombie] exec "toughunit.sqs";

?debug:info globalChat format ["%1 active and searching",name _zombie]

#main

; Zombie dead or deleteVehicle:d?

? !(alive _zombie) or (isNull _zombie):exit

;_zombie domove (getpos _target)

? _zombie distance _target > 5 : _zombie doMove getPos _target

? _zombie distance _target <= 1 : _zombie addMagazine "StrokeFist"; goto "attack"

? _zombie distance _target > 1 && _zombie distance _target <= 5 : goto "engage"

~1

goto "main"

#engage

_nX = getPos _target select 0

_nY = getPos _target select 1

_zombie setPos [_nX, _nY]

goto "main"

#attack

_target globalchat "arrrgghh get it off me!! Heeeelllpp!!"

_zombie fire "StrokeFist"

_x = random 2

? _x <= 1 : _target setDammage (getDammage _target + 0.1)

~1

_zombie removeMagazines "StrokeFist"

goto "main"

#dead

exit

RED

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  

×