OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Robinhansen on 12 Feb 2005, 11:14:04

Title: Creating Fightposistion
Post by: Robinhansen on 12 Feb 2005, 11:14:04
I would like to allowed my engineres to build fightposistions at random places. For that I use this script:

[eng, "cover4"] exec "create_object.sqs".

_eng = _this select 0
_cover4 = _this select 1

_mydistance = 5

_180 = getdir _eng

_5 = ((sin 0) *1) + (getpos _eng select 0)
_5 = ((cos 0) *1) + (getpos _eng select 1)

_fightpos = _cover4  createVehicle [2, 2, 0]

_fightpos setdir _180

hint "object placed"

exit


eng is the name of the player ang cover4 is the name of the fightposistion.

The only thing that works seems to be the hitn ??? ???
Title: Re:Creating Fightposistion
Post by: macguba on 12 Feb 2005, 12:31:10
Bad luck.   ;D   We all know how that feels.

Use hint format commands to check that your variable values are what you think they are.

I can't remember the syntax but it seems to be that you are creating the cover in the sea at the bottom left hand corner of the map.
Title: Re:Creating Fightposistion
Post by: Robinhansen on 12 Feb 2005, 14:13:00
okaay? Hint Format means what? And what do I write then if I whant to create the cover in front of the player? :-\
Title: Re:Creating Fightposistion
Post by: macguba on 12 Feb 2005, 14:33:42
http://www.ofpec.com/editors/comref.php?letter=F#format
Title: Re:Creating Fightposistion
Post by: Planck on 12 Feb 2005, 14:39:04
Looking at your script.........

Why have you defined a variable _5 as:

_5 = ((sin 0) *1) + (getpos _eng select 0)

And then immediately changed it with the next line:

_5 = ((cos 0) *1) + (getpos _eng select 1)


However, the variable is never used anyway, so I don't understand why you defined it. Also the _mydistance variable doesn't seem to be used either.

Try this version and see if it is any better:
Code: [Select]
_eng = _this select 0
_cover4 = _this select 1

_mydistance = 5

_heading = getdir _eng

_x = ((sin 0) *1) + (getpos _eng select 0)
_y = ((cos 0) *1) + (getpos _eng select 1)

_fightpos = _cover4  createVehicle [_x, _y, 0]

_fightpos setdir _heading

hint "object placed"

exit

I changed some of the variable names because I don't like variables with numeric names, it can be confusing to read.

Anyway, hope some of that helps.


Planck
Title: Re:Creating Fightposistion
Post by: Terox on 12 Feb 2005, 14:59:27
what is "cover4"

i dont recognise it as an object/vehicle class
and from what you posted, you havent shown that you have declared it as anything

eg cover4 = "classname of object"

and it needs to be either the real classname of an object, or a variable that has been declared as one


*****************************************************

To know how to use  titletext format  or hint format to debug a script, is propabably the most useful weapon  in a scripters arsenal.


i give you an example.

A fired event handler, returns an array of various elements every trime it is triggered.

say for instance we didnt know what those elements were or how many there were

we can find out in the following way


INIT.sqs
Quote
player addEventHandler ["Fired", {_this exec "debug.sqs"}]

DEBUG.sqs
Quote
_A = _this select 0;  
_B = _this select 1
_C = _this select 2
_D = _this select 3
_E = _this select 4
_F = _this select 5
_G = _this select 6

hint format ["A = %1\n\nB = %2\n\nC = %3\n\nD = %4\n\nE %5\n\nF=%6\n\nG=%7",_A,_B,_C,_D,_E,_F,_G]

when you as a player fire a weapon a hint box will appear and the following will be displayed

A= Terox
B= M16Grenadelauncher
C= M16Muzzle
D= Burst
E= M16
F = stringoxcliffee etc etc
G = stringoxcliffee etc etc


we can then see that there are only 5 elements
first element = players name
2cnd element = weapon name etc.


Now that we have this info, we can further debug the script we are working on.

Lets say for instance, that we are developing a weapon jamming system

and we are trying to remove and re add the magazine for the M16grenadelauncher when the weapon is fired using the standard rifle, not the grenade launcher part

we find that in our script, when we fire the weapon normally, the script doesnt remove the mag

and are sure that the line
?(_C == "M16muzzlemode"): Player removemagazines "M16"
is correct.

So we run another hint format in our debug script

hint format ["Muzzle Type  = %1",_C]

hey presto, it returns
Muzzletype = M16muzzle"

debugged and so we change the line
to
?(_C == "M16muzzle"): Player removemagazines "M16"







Additional items you can use in debugging is
Have a radio trigger that when activated causes a boolean to become true
Then you know, that even if the trigger didnt activate the boolean, you did

or a marker that you setmarkerpos to an object, so that you can see where that object is etc etc

Hope that helps a bit
Title: Re:Creating Fightposistion
Post by: Planck on 12 Feb 2005, 15:06:17
I'm guessing here Terox......but it might be the class name of a third party addon he is using, although I'm not sure whether that has to be declared by using the class name or if putting the class name into a variable and using the variable works correctly.


Planck
Title: Re:Creating Fightposistion
Post by: Robinhansen on 12 Feb 2005, 15:13:30
TY Planck! The modyfied script works the way it's supposed to! Next problem is to add it to the playeres action menu...  ;)

The script used is Devilchaser's Mission/Scripting Guide
http://www.ofpec.com/editors/browse.php?searchopts=&start=125 (http://www.ofpec.com/editors/browse.php?searchopts=&start=125)

Cover4 is the classnavn (at least I think it is) of Sparks fightposistions
http://ofp.gamezone.cz/index.php?showthis=7368 (http://ofp.gamezone.cz/index.php?showthis=7368)

I hope that ironed out most doubt.. ;)
Title: Re:Creating Fightposistion
Post by: Robinhansen on 12 Feb 2005, 15:37:09
Ok - even though it works I'm still not satisfied. I whant to turn the posistion 180 degrees and I whant it to be placed aprox 5-10 meters in front of me, everytime. At the moment it places itself at random places all around me... :-\
Title: Re:Creating Fightposistion
Post by: Triggerhappy on 12 Feb 2005, 16:48:29
180 degrees from the engineers direction right?

Code: [Select]
_eng = _this select 0
_cover4 = _this select 1

_dir= getdir _eng

_x = ((sin _dir) *(5 + (random 5))) + (getpos _eng select 0)
_y = ((cos _dr) *(5 + (random 5))) + (getpos _eng select 1)

_fightpos = _cover4  createVehicle [_x, _y, 0]

_fightpos setdir (_dir +180)

hint "object placed"

exit

or if you want it alwasys at 180:


Code: [Select]
_eng = _this select 0
_cover4 = _this select 1

_dir= getdir _eng

_x = ((sin _dir) *(5 + (random 5))) + (getpos _eng select 0)
_y = ((cos _dr) *(5 + (random 5))) + (getpos _eng select 1)

_fightpos = _cover4  createVehicle [_x, _y, 0]

_fightpos setdir 180

hint "object placed"

exit
Title: Re:Creating Fightposistion
Post by: Robinhansen on 12 Feb 2005, 19:40:55
Now we got the direction under control! ;D but I still can't figuer out the random placement... ???
I've been planing to expand the script with sandbags, wires ect. so they must be placed at the exact same place from the engenieer every time  :-\
Title: Re:Creating Fightposistion
Post by: Raptorsaurus on 12 Feb 2005, 20:21:52
Try this function I wrote for geting a postition relative to a reference object.  The function is: PosAtAngDirDis.sqf.  If you call it like this:

_pos = [_eng, 0, 180, 5] call PosAtAngDirDis

The _pos will be the 3D position at the same elevation (0) as the engineer (_eng), behind the engineer (180) and 5 meters away from the engineer (5).

Then do:

_obj setPos _pos (where _obj is the object you want to place).

The function file is attached.
Title: Re:Creating Fightposistion
Post by: Robinhansen on 12 Feb 2005, 20:56:47
I like it, but due to the face that I'm a total idiot when it comes to scripting  I need a lot more of informations of exactly what to do.

Thanks for spending your time solving this "mess"

 ;D
Title: Re:Creating Fightposistion
Post by: Terox on 13 Feb 2005, 12:50:34
I'm guessing here Terox......but it might be the class name of a third party addon he is using, although I'm not sure whether that has to be declared by using the class name or if putting the class name into a variable and using the variable works correctly.


Planck

either are fine m8
Title: Re:Creating Fightposistion
Post by: Triggerhappy on 14 Feb 2005, 02:03:32
ok i thought you wanted it randomly between 5-10 m in front
here you go:
Code: [Select]
_eng = _this select 0
_cover4 = _this select 1

_dir= getdir _eng

_x = (((sin _dir) *5) + (getpos _eng select 0))
_y = (((cos _dr) *5) + (getpos _eng select 1))

_fightpos = _cover4  createVehicle [_x, _y, 0]

_fightpos setdir (_dir +180)

hint "object placed"

exit

i saw in another post that you wanted these as user actions right?

heres how you do that:

create an action for each of the different things you want to build
and execute your build script from those action scripts
for example

player addaction [{Build "cover4"},"cover4.sqs"]

cover4.sqs:
Code: [Select]
_eng = _this select 0
[_eng,"cover4"] exec "create_object.sqs"
exit

and just make a seperate script like that for each of the things you want to build (each being its own action) or you could add an action "Build Something" which then gives you the actions of what to build (that would be more complicated because you would have to remove the actions once used
you could also try to make a dialog but thats a lot harder
Title: Re:Creating Fightposistion
Post by: Robinhansen on 14 Feb 2005, 15:32:33
The addaction works ;D tnx for that...

The posistions are still a bit random but it's the best so far... ;D
I dont think its getting any better by now. :)

Cheers to all hwo helped me solving this... ;)
Title: Re:Creating Fightposistion
Post by: Robinhansen on 16 Feb 2005, 11:35:22
Look who's back, lol. I've an additional question. Is there a way to remove what the player just created again? But only when the player is within aprox. 1m. from the item. Then the script would be a great cargoscript as well...
 :P :P
Title: Re:Creating Fightposistion
Post by: Triggerhappy on 16 Feb 2005, 22:06:32
give it an action to delete it
when the player gets close to it the action will be given to him
Title: Re:Creating Fightposistion
Post by: Robinhansen on 16 Feb 2005, 22:12:38
I've allready thought of that ;) but the only eraser script I could find is this one made by shark attack, but I can't make it work >:(

http://www.ofpec.com/editors/browse.php?searchopts=&start=125 (http://www.ofpec.com/editors/browse.php?searchopts=&start=125)
Title: Re:Creating Fightposistion
Post by: Triggerhappy on 17 Feb 2005, 22:33:18
when you create it give it an action to delete it

here is the script you'll need:
Code: [Select]
delectevehicle (_this select 0)
thats it

actions can't have arguments in with the script, so there are only a few things you can get when you use actions
Title: Re:Creating Fightposistion
Post by: greg147 on 17 Feb 2005, 23:58:17
I'm not too good at this type of thing, but couldn't you de-pbo the 'hold montignic' mission from the Red Hammer campaign and see what script was used there, when you could place a tank trap in front of you using the action menu?  :P
Title: Re:Creating Fightposistion
Post by: Robinhansen on 18 Feb 2005, 13:08:36
I know what you mean. Hold Montinac is my inspiration, no doubt about that  ;) But that mission only allow the player to create limited tankbarreirs, due to the fact that they allready are placed on the map (I guess some kind of a "teleportation" script are used here).
The script I whant is the player is able to create several items out of "nothing" and beeing able to erase it again when near it.
 :D
Title: Re:Creating Fightposistion
Post by: Robinhansen on 22 Feb 2005, 17:31:15
No matter what I try this sentence: delectevehicle (_this select 0) is not enough to delete the item again. At least I don't konw how to. :(
Sorry for being a scripting noob :-\
Title: Re:Creating Fightposistion
Post by: Triggerhappy on 22 Feb 2005, 22:59:48
in the script that makes the object, put this line:
_fightpos addaction ["get rid of this crap!", "delete_it.sqs"]

then put this in a script called delete_it.sqs
deletevehicle (_this select 0)
(_this select 0) removeaction (_this select 2)

when a player walks up to it, he will get the action "get rid of this crap!"
when used, it gets deleted
ok? ok :P
Title: Re:Creating Fightposistion
Post by: Robinhansen on 22 Feb 2005, 23:33:36
I'm really pleased about all the work that you have putted in this script, so I'm sad to announce that the delete_it script doesen't work. I been trying the whole day with something simular, wich did'nt work either by the way... :'(
Title: Re:Creating Fightposistion
Post by: Triggerhappy on 23 Feb 2005, 04:33:52
that should work, always has, always will, either syntax problems or... i don't know what else
perhaps you get error messages? or maybe you accidentally saved the script as delete_it.sqs.txt?
or some other silly mistake?
Title: Re:Creating Fightposistion
Post by: Triggerhappy on 23 Feb 2005, 04:55:36
in fact, i just did it
attached are 2 create delete actions (one of each) and you get to sit on desert isle and make a jeep then delete it and then destroy it again.

at first the action doesn't seem to register, but just wait a second, and it will show up (on the jeep you make) then you can delete it and make a new somewhere else.
it also setsthe jeeps pos/direction in relation to the player
problem solved now?
Title: Re:Creating Fightposistion
Post by: Robinhansen on 23 Feb 2005, 15:49:38
This is so mutch it!! :D

I really suggest that you send this to the Editors Depot, and take full credit for it.

Can't explain enough how much I like this script!!!

 ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D
Title: Re:Creating Fightposistion
Post by: Robinhansen on 14 May 2005, 02:17:35
So, after playing around with this script for aprox 3 month now, I've commed to the conclution that it's to inaccurate. When creating fightposistions it works fine, but when creating barbwire and sandbags it useless :-[! How can I create the wire'n sandbags excactly 2 meters in front of the player in an angle of 90 degrees? (Just like in the SP-game Iron Wall and mission 18 - Ambush in Red Hammer...

P.S I've tried aprox 1000 solutions, so this forum is my last chance... ;)
Title: Re:Creating Fightposistion
Post by: bedges on 14 May 2005, 10:52:43
not having followed this thread i'm not sure what solutions you're working with. however, i'll offer my tuppenceworth of advice ;)

firstly, decide which method you're using to create the sandbags and/or wire - are they created somewhere secret on the map and then called into position, or are they created out of thin air with the camcreate command...

either way, the objects need a name.

to answer the first part of your question - "wire'n sandbags excactly 2 meters in front of the player..."

Code: [Select]
_x = getpos player select 0
_y = getpos player select 1
_dir = getdir player

object_name setpos [_x + (2*sin(_dir)), _y + (2*cos(_dir))]


now when you say "in an angle of 90 degrees" i assume you mean you want the sandbag/wire to be at 90 degrees to the player.

Code: [Select]
object_name setdir _dir+90
will do the trick. now this all works if you have the objects already on the map and named. if you're using camcreate it's a little different. you'll need the name of wire and sandbags that the editor will recognise - i think it's something like "Fence" and "Wire".

so it would look something like this:

Code: [Select]
_x = getpos player select 0
_y = getpos player select 1
_dir = getdir player

w1 = "wire" camcreate [_x + (2*sin(_dir)), _y + (2*cos(_dir))]
w1 setdir _dir+90


that's not tested, but i'm 99% sure it'll work. hope it helps.

EDIT - now tested, see attached missionette....
Title: Re:Creating Fightposistion
Post by: Terox on 14 May 2005, 11:29:40
look at the build system attached to the repair trucks on CTi's, especially the CRCTI version, you have everything you need there

A dialog system
a bunch of things you can build
and a positioning system
Title: Re:Creating Fightposistion
Post by: Robinhansen on 14 May 2005, 11:39:59
OUTSTANDING!! Now I must say that the scripts works the way I whant'em to ;D