Home   Help Search Login Register  

Author Topic: guess what? a createunit problem...  (Read 2103 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 »

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:guess what? a createunit problem...
« Reply #15 on: 17 Jan 2004, 17:45:37 »
This forum welcomes questions based on all versions  of OFP.   It's just that the lower the version, the more jocular abuse you have to put up with.  ::)  ;D
Plenty of reviewed ArmA missions for you to play

Offline myke13021

  • Contributing Member
  • **
  • Myke
Re:guess what? a createunit problem...
« Reply #16 on: 17 Jan 2004, 17:48:24 »
i agree that resi is easier to handle, looks way better and all this...it's just....i use 1.46 for the reasons i told before....

so if someone could help or at least tell me "theres no way to do what you try to do" ....i would be glad

deaddog

  • Guest
Re:guess what? a createunit problem...
« Reply #17 on: 17 Jan 2004, 23:27:13 »
Quote
i guess i have to accept there's no way to delete the dead bodies.
Don't give up so easily.  This next version worked (I actually tested it with 1.46).

Get rid of the soldiers=[] from your init.sqs.  We don't need it now.

Place a game logic and name it "server"

Place a very large trigger (5000X5000) or large enough to cover the area you are playing.  Make it :
activation: anybody, repeatedly
name: deletetrigger
condition:this


Execute this script at the beginning of your mission (via init.sqs)

[] exec "deletebodies.sqs:


Code: [Select]
;deletebodies.sqs

?!local server:exit


#loop
_temp=+(list deletetrigger)

~10

_s=+(list deletetrigger)

?count _s == count _temp:goto "loop"


_i=0

#l1
_u=_temp select _i

?!alive _u:deletevehicle _u

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


goto "loop"

This worked for soldiers created by "createunit" but didn't delete players when killed.
« Last Edit: 17 Jan 2004, 23:28:28 by deaddog »