Home   Help Search Login Register  

Author Topic: guess what? a createunit problem...  (Read 2104 times)

0 Members and 1 Guest are viewing this topic.

Offline myke13021

  • Contributing Member
  • **
  • Myke
guess what? a createunit problem...
« on: 17 Jan 2004, 03:15:44 »
hay folks, me again....got now a little more familiar with the createunit command...but one thing still doesnt work for me and i didn't found any topic in this forum that could help me out...ok, here it comes:

i have the following line in my script which works fine:
"SoldierESniper" CreateUnit [GetMarkerPos _pos, _group, "", 0.9, "CAPTAIN"]

no prob to this point...but now i would like to put some in the init field of this unit and imo this should look like this:
"SoldierESniper" CreateUnit [GetMarkerPos _pos, _group, "this addeventhandler ["killed", {_this exec "dead.sqs"}]", 0.9, "CAPTAIN"]

for some reasons it wont work...is the syntax for init field diff for a createunit created soldier?...didn't found an answer...all other things i saw in this forum just used the position and group function...

would be nice if someone could check what i did wrong..

m21man

  • Guest
Re:guess what? a createunit problem...
« Reply #1 on: 17 Jan 2004, 03:27:42 »
I don't know, you might have to do it with brackets:
Code: [Select]
"SoldierESniper" CreateUnit [GetMarkerPos _pos, _group, "this addeventhandler [{killed}, {_this exec {dead.sqs}}]", 0.9, "CAPTAIN"]
That's my (bad) guess.
« Last Edit: 17 Jan 2004, 03:29:03 by m21man »

Offline myke13021

  • Contributing Member
  • **
  • Myke
Re:guess what? a createunit problem...
« Reply #2 on: 17 Jan 2004, 03:35:39 »
hmm....a little step further...before it didn't created the unit at all...not it creates it but i get the error message "Error unknown Operator Eventhandler"

any ideas?

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:guess what? a createunit problem...
« Reply #3 on: 17 Jan 2004, 03:55:33 »
Probably a syntax error in the code.    Check it again, and if you get the error message look for the #.    That will indicate where in the code the error has occurred.

It's possible it's a " "  { } problem.   Try messing around with quotes as opposed to curly brackets:  they are supposed to be equivalent but they aren't.
Plenty of reviewed ArmA missions for you to play

Offline myke13021

  • Contributing Member
  • **
  • Myke
Re:guess what? a createunit problem...
« Reply #4 on: 17 Jan 2004, 04:02:13 »
rgr...checked this and got the error at the #"dead.sqs"..changed it to {dead.sqs} and then this part worked....but then i got another error:
#addeventhandler: Error unknown Operator addeventhandler

there are no "" i could change to {}

btw....the dead.sqs is a delete dead bodies script....if someone got an idea how i can get around to set a init, this would also help

deaddog

  • Guest
Re:guess what? a createunit problem...
« Reply #5 on: 17 Jan 2004, 04:25:28 »
Try adding the event handler after the unit is created.

place a unit in the editor and put this in the init line:
tempgroup= group this;deletevehicle this

now,  in your script create the unit to the tempgroup:

Code: [Select]
.
.
.
"SoldierESniper" CreateUnit [GetMarkerPos _pos, tempgroup, "", 0.9, "CAPTAIN"]

_u=(units tempgroup) select 0
_u addeventhandler ["killed", {_this exec "dead.sqs"}]
[_u] join _group
.
.
.

or another way (I just thought of it)

forget about the tempgroup.  After your entire group is created then add this line:

{_x addeventhandler ["killed", {_this exec "dead.sqs"}]} foreach units _group
« Last Edit: 17 Jan 2004, 04:29:25 by deaddog »

Offline myke13021

  • Contributing Member
  • **
  • Myke
Re:guess what? a createunit problem...
« Reply #6 on: 17 Jan 2004, 04:34:26 »
hmmm...still got the same error about unknown operator addeventhandler....is this thought for just 1 single unit or should it work for more units in the same group?

deaddog

  • Guest
Re:guess what? a createunit problem...
« Reply #7 on: 17 Jan 2004, 04:35:46 »
What version of OFP do you have?

Offline myke13021

  • Contributing Member
  • **
  • Myke
Re:guess what? a createunit problem...
« Reply #8 on: 17 Jan 2004, 04:37:31 »
i have 1.46

deaddog

  • Guest
Re:guess what? a createunit problem...
« Reply #9 on: 17 Jan 2004, 04:39:23 »
Aha!! :)  

Addeventhandler is for 1.85 and up.

Your method would work if you had the resistance upgrade.  Right idea, wrong version  ;D

Offline myke13021

  • Contributing Member
  • **
  • Myke
Re:guess what? a createunit problem...
« Reply #10 on: 17 Jan 2004, 04:41:35 »
oh sh**....i'm such a noob......any idea how can i delete such created units once they dead?...i want this to prevent lag as i'm a euro and play often with US/Canadian peeps....

deaddog

  • Guest
Re:guess what? a createunit problem...
« Reply #11 on: 17 Jan 2004, 04:53:42 »
In your init.sqs file create a global variable called soldiers:

soldiers=[]

Now, in your createunit script, add this after you create an entire group:

soldiers=soldiers + units _group

Now, create a new script called deletebodies.sqs (or whatever):

Code: [Select]
;deletebodies.sqs

#loop
~20

?count soldiers == 0:goto "loop"

_temp=[]

_i=0

#l1
_u=soldiers select _i

?!alive _u:_temp=_temp+[_u];deletevehicle _u

_i=_i+1
?_i<count soldiers:goto "l1"
 
soldiers=soldiers-_temp
goto "loop"

execute this script from your init.sqs file:

[] exec "deletebodies.sqs"

I haven't tested this so there is no guarantee, but give it shot. :)

Edit

Made a small change
« Last Edit: 17 Jan 2004, 04:57:57 by deaddog »

m21man

  • Guest
Re:guess what? a createunit problem...
« Reply #12 on: 17 Jan 2004, 05:09:01 »
Ack! Not another 1.46 user. Get Resistance, you'll consider it money well spent.

Offline DrStrangelove

  • Members
  • *
  • Mr.Creative
Re:guess what? a createunit problem...
« Reply #13 on: 17 Jan 2004, 10:45:08 »
Yup, definitely. Price of Resistance has dropped since it came out so it's absolutely rediculous to stay with original OpF (if u ask me).

Nice script btw. This way you don't need a dead script running for every soldier. That's my main problem when i work with spawns.  8)

Offline myke13021

  • Contributing Member
  • **
  • Myke
Re:guess what? a createunit problem...
« Reply #14 on: 17 Jan 2004, 17:06:34 »
i agree...resi is really good, thats why i have it :P

the problem is...i write maps for 1.46 because most of my friends plays 1.46.....i don't like the ingame browser and ASE...i miss the chat lobby as known from GSA...call me retarded if you want but i don't want just to play...i want to meet peeps with the same interests as i have (and one of these interests is OFP)....thats why i play mostly 1.46 on GSA.

Besides this i was getting tired to dl addons everytime someone made a new map....and also i had probs with some addons (resis didn't start nemore...but this i fixed)

And....i thought this is a general OFP Forum...didn't knew it is specialized to Resi....name me a 1.46 Forum and i'll try to get my answers there.

@DeadDog:
thx for the script....no error message but no workee too...i guess i have to accept there's no way to delete the dead bodies.

Anyway...thx to all peeps that tried to help me...you're cool guys (even m21man....jk bud)

Keep this Forum alive...and i hope the regular ofpec site will be up on a regular basis really soon....best editing site ever. 2 thumbs up...even a third if i had one...lol
« Last Edit: 17 Jan 2004, 17:10:57 by myke13021 »