Jump to content
Sign in to follow this  
Nightmare01

Createunit command

Recommended Posts

Hello.

"SoldierWB" createUnit [getpos Spawn1, group1]

Spawn1 is an invisible H

Why does this easy command dont work ?

I get no error msg or anything. It happens just nothing.

thanks for your help

unclesam.gif

Share this post


Link to post
Share on other sites

Your group is probably not defined properly. What is group1? Normally you would grab a group by placing this in a unit's init: group1=group this

Share this post


Link to post
Share on other sites

In addition to bn880 answer , if you dont want the unit used just to define the group as " group1 " to continue to exist , you can put this in its init line

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

This way the group named group1 is defined , but the soldier you put in your mission for this is deleted just after that group definition.

Can be usefull if you have no use of this soldier.

Share this post


Link to post
Share on other sites

Thanks people, it works now  wink_o.gif

The group name (group1 in my case) has to be exist when the command is executed.

So first you have to place a soldier into the mission with the init: group1=group this

If you delete or keep the soldier after mission start doesnt matter.

Would be very usefull if BIS add a comment about that into his comref.

Share this post


Link to post
Share on other sites

another trick that might be this:

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

_soldier = "SoldierWB" createVehicle getPos _respawn

group1 = group _soldier

deleteVehicle _soldier

group1 can now be accessed.

Share this post


Link to post
Share on other sites
another trick that might be this:

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

_soldier = "SoldierWB" createVehicle getPos _respawn

group1 = group _soldier

deleteVehicle _soldier

group1 can now be accessed.

That trick not working. Did you tested it? The group name only "valid" if you define it in soldiers init field.

Share this post


Link to post
Share on other sites

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

noooo! if you delete the guy, and if you spawn alot of guys on group1, it'll screw up. Take out the deletevehicle this part.

Just put this in the spawned unit

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

"soldierwb" createunit [getpos H,Group1,"Man = this",0.5,"PRIVATE"]

[man] join grpnull

Share this post


Link to post
Share on other sites

Sanctuary got it right, you can only create a valid group from within the editor.

After that you can use the script commands to make additional groups based on what you setup in the editor.

Share this post


Link to post
Share on other sites

I have a question, how the hell do you access the created unit? smile_o.gif I want to make a generic script where a soldier respawns and then when he dies I want to add +1 to casualty counter.

My initial assumption was something like this:

_man = "SoldierWB" createUnit [_spawn,group1,"",0.5,"CORPORAL"]

@(NOT alive _man)

bodyCount = bodyCount + 1

Looks fine in theory, but the stupid createUnit does not return anything. sad_o.gif It even says so in comref. So how do I find out when that particular soldier dies? Is there a simple way to do it or do I have to name the soldier in the init ("soldier1 = this") and then use @(NOT alive soldier1)?

If anyone knows a simple solution it would make my life much easier. smile_o.gif

Share this post


Link to post
Share on other sites

This is simple. Use an eventhandler. Edit your createunit line like so:

"SoldierWB" createUnit [_spawn,group1,"this addeventhandler [{killed},{_this exec {bodycount.sqs}}]",0.5,"CORPORAL"]

Next make a new text file and name it bodycount.sqs. Put it in the folder that has your mission name.

contents of bodycount.sqs:

;--------------------------------------

_unit = _this select 0

_unit removealleventhandlers "killed"

bodycount = bodycount + 1

;--------------------------------------

Now in your init.sqs, or in the players ini put: bodycount = 0

Each created unit that dies will add 1 to your bodycount.

Don't put a "_man =" at the front of the createunit line. If you want to name him use the ini section of the line like so:

"SoldierWB" createUnit [_spawn,group1,"man1=this; this addeventhandler [{killed},{_this exec {bodycount.sqs}}]",0.5,"CORPORAL"]

Now if you want to get fancy, you can delete the created units, if you want to keep too many from piling up. Just edit the script like so:

;--------------------------------------

_unit = _this select 0

_unit removealleventhandlers "killed"

bodycount = bodycount + 1

~15 + (random 10)

deletevehicle _unit

;--------------------------------------

Share this post


Link to post
Share on other sites

Wow! wow_o.gif Thanks! I'll test it today! I used event handlers before but always got an error message - probably because of "quote marks". I never realised you can use {} instead of quote marks. Thanks again! smile_o.gif

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  

×