Home   Help Search Login Register  

Author Topic: Add script into cpp file  (Read 4106 times)

0 Members and 1 Guest are viewing this topic.

Maximus-Sniper

  • Guest
Add script into cpp file
« on: 23 Jul 2004, 01:28:38 »
Hei
How di i add script files into my cpp file to work???
And where inn the cpp file so i put it in?
And what should i write inn cpp file?
I will add a bulletcamera to my addon. If not i have to copy all those files into my mission ebery time and make some trigger and use the radio to Turn on and off the bulletcamera, how do i get it to work inn my cpp file??

I got two script to work but not the bullet cam script its about 4 files in the bullet cam, init.sqs, fired.sqs, PosBullCam.sqf and description.ext How do i do that to get them all to work.. take a look:

.
.
.
.
class UserActions
      {
      class Selfheal
      {
         displayName = "First Aid";
         position = "axisgoggles";
         radius = 1.00000;
         condition = "(Format [{%1},BaB_heal] != {false}) && (player == this)";
         statement = "this exec {\bab\script\heal.sqs}";
      };
      class sniperslow
      {
         displayName = "Sniper Slow";
         position = "axisgoggles";
         radius = 1.00000;
         condition = "(Format [{%1},sniper_slow] != {false}) && (player == this)";
         statement = "this exec {\bab\script\sniperslow.sqs}";
      };
      class sniperbulletcam
      {
         displayName = "Sniper Bullet Camera";
         position = "axisgoggles";
         radius = 1.00000;
         condition = "(Format [{%1},sniper_bullet_camera] != {false}) && (player == this)";
         statement = "this exec {\bab\script\init.sqs}";
      };
.
.
.
.
Can i load more tha one file? And how, how do i fix this problem??

please help
« Last Edit: 23 Jul 2004, 04:37:11 by Maximus-Sniper »

Offline Peter_Bullet

  • Members
  • *
  • "The evil that men do lives on and on"
Re:Add script into cpp file
« Reply #1 on: 23 Jul 2004, 07:13:11 »
Okay, so, are you asking that how do you add BulletCamera script to your config?  ???

If so, I can help... you need an eventhandlers class inside your vehicle class  :P. Here is an example:


      class EventHandlers
      {
         Init=[_this select 0]exec "\Epl_Gr3\Scripts\Init.sqs";
      }; //End the class EventHandlers

If you want bullet camera, you just change the "Init" with "Fired" And after that you type the parameters and the path, like above (In the script, remember to use the parameter "_this select 0" as the unit...  8)

I hope this helps.... If not, let me know! ;)
« Last Edit: 23 Jul 2004, 07:16:25 by Epeli »

Maximus-Sniper

  • Guest
Re:Add script into cpp file
« Reply #2 on: 23 Jul 2004, 10:20:18 »
tnx man :)

I put so this line into my vehicle class:

class EventHandlers
      {
      init=[_this select 0] exec "\BAB\Scripts\Init.sqs"; then {_this call loadFile ""\BAB\script\load.sqf""};
      };

and i use call loadfile .....
because its 3 more files in that bullet camera script i got from this site (bullet camera v1.2)

take a look inside my load.sqs file:

_this call loadFile "\BAB\script\PosBullCam.sqf";
_this call loadFile "\BAB\script\description.ext";
_this call loadFile "\BAB\script\fired.sqs"

so i hope its correct???

Offline Peter_Bullet

  • Members
  • *
  • "The evil that men do lives on and on"
Re:Add script into cpp file
« Reply #3 on: 23 Jul 2004, 13:25:53 »
I'm sorry dude, but I know nothing of how you write function files, so I'm not sure...  :-[ Though that's the way how you execute the script... Though I recommend using the event fired like:

      class EventHandlers
      {
         Fired=[_this select 0]exec "\Epl_Gr3\Scripts\Fired.sqs";
      }; //End the class EventHandlers

Then you just script the Camera effect and stuff inside the Fired.sqs script... But I know nothing about functions, they seemed too complicated when I looked at snypir's tutorial a while ago....  :-[

Unnamed

  • Guest
Re:Add script into cpp file
« Reply #4 on: 23 Jul 2004, 22:22:45 »
Hi,

For the event handlers use this instead:

Code: [Select]
class EventHandlers
      {
      init="[_this select 0] exec ""\BAB\Scripts\Init.sqs"" ; MyFUnction call loadFile ""\BAB\script\load.sqf""";
      };

Eventhandles called from the cpp are strings so you have:

Code: [Select]
class EventHandlers
{
Init="";
};

Any quotes you use within that string need to be doubled up:

Code: [Select]
class EventHandlers
{
Init="MyName=""Buba""";
};

Loadfile loads up a function into a global variable, without pre-processing it. So it will not be as fast as a function loaded with PreProcess. BTW you can only load functions within a cpp using LoadFile. To load your function into a variable called MyFunction use this:

Code: [Select]
init="[_this select 0] exec ""\BAB\Scripts\Init.sqs"" ; MyFunction=loadFile ""\BAB\script\load.sqf"" ; [""Buba""] Call MyFunction";

You can only use LoadFile with *.sqf files. You cant use it with *.sqs or *.ext files.

Description.ext can not be included in your addon, you will have to copy that manually into your mission folder. Your sqs files can be included, but you just call them the same way you call any other script.
Code: [Select]
Code: [Select]

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:Add script into cpp file
« Reply #5 on: 23 Jul 2004, 23:16:06 »
Ok, I know I'm not helping much, but I just need to comment on a couple of things... :P

Quote
You can only use LoadFile with *.sqf files. You cant use it with *.sqs or *.ext files.
I beg to differ...

You can use call loadFile on *.sqs, but there's some to be noted; the *.sqs is treated as sort of semi-function, so ~ delays won't work (as they don't in functions), but you don't need the ; at the sentences end, as you do in functions...

(Actually if I remember correctly you can preprocessFile *sqs's too...)

But that's in the mission editor, not in the config....

And, you can include description.ext in your addon, but not as *.ext... (I'm not sure that the whole description.ext would be wise to be distributed in an addon anyway...)

But, you can include for example the class titleRsc portion of the description ext (or dialogs) by using a file called *.h..

So you can include yay_my_titleRsc.h in your addon. Then it's used in a mission by including it (like in C, C++...) by adding this to the missions description.ext:
#include <addon_pbo_name\yay_my_titleRsc.h>

But, if the mission maker is already using titleRsc, that cannot be used.
Same goes for dialogs...

So with this method you should be able include a whole description.ext into an addon (as unwise as it could be)...

Quote
Loadfile loads up a function into a global variable, without pre-processing it. So it will not be as fast as a function loaded with PreProcess.
I'm not so sure about this... OFP does not have compiler for it's scripting language...

loadFile does have a bug though... You can not have any   comments like:  //  /**/  or comment "Blah blah" in your functions... It will result in 'Unknown Operator' errors...
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Unnamed

  • Guest
Re:Add script into cpp file
« Reply #6 on: 24 Jul 2004, 02:38:33 »
Quote
I beg to differ...
You can use call loadFile on *.sqs, but there's some to be noted; the *.sqs is treated as sort of semi-function, so ~ delays won't work (as they don't in functions), but you don't need the ; at the sentences end, as you do in functions...

I was trying to keep it simple. Unless Maximus really wants to ask about strings and the call function, but was to shy to come right out and say it :)

Quote
So with this method you should be able include a whole description.ext into an addon (as unwise as it could be)...

You can include any files you want into an addon. But Description.ext will not be called from within it, its called from the mission folder. So there is little point in including it, unless its just for reference?

Maximus-Sniper

  • Guest
Re:Add script into cpp file
« Reply #7 on: 24 Jul 2004, 02:54:16 »
Tnx for all help, i got it work like 50% :)
I canche a bit in my init.sqs :

player addaction ["Bullet camera on","\Bab\script\TrackEryx.sqs"]
player  addEventHandler ["fired",{_this exec "\Bab\script\fired.sqs"}]

track = false

PosBullcam = preprocessFile  "PosBullCam.sqf"

validation = false

Please help if you see something wrong

Then a chance a bit in fired.sqs:

_Missile = nearestObject [vehicle(player), _this select 4]
? isNull  _Missile : exit
? !(track) : exit
_ok = createDialog "Speed"
? !(_ok) : exit
setAccTime 0.01
_Type= typeOf _Missile

_cam = "camera" camcreate [0,0,0]
_cam cameraeffect ["internal", "back"]


sliderSetRange [100, 0.01, 1]
sliderSetSpeed [100, 0.5, 2.0]
sliderSetPosition [100, 0]
sliderSetRange [99, 0.1, 1]
sliderSetPosition [99, 1]
sliderSetSpeed [99, 0.1, .25]
sliderSetRange [98, -180, 180]
sliderSetPosition [98, 0]
sliderSetSpeed [98, 0.5, 2.0]
sliderSetRange [97, -15000, 15000]
sliderSetPosition [97, 0]
sliderSetSpeed [97, 0.5, 2.0]
#loop
? _Type != typeOf _Missile : goto "end"
[ _Missile ,_cam,(sliderPosition 99),(sliderPosition 98),(sliderPosition 97)] call PosBullcam
setAccTime (sliderPosition 100)
? ctrlvisible 100 : goto "loop"


#End
? (getpos _cam select 1 == 0) or !(_Type != typeOf _Missile) : goto "SkipSlowEnd"
 setAccTime 0.2
~0.5
#SkipSlowEnd
_cam cameraeffect ["terminate", "back"]
 camdestroy _cam
closedialog 0
setAccTime 1
exit

help if something is wrong her

Then a use a another script from another bullet cam (TrackEryx.sqs) :

_ID = _this select 2
player removeAction _ID
? !(track) : track = true ; player addaction ["Bullet camera off", "\Bab\script\TrackEryx.sqs"];exit
? (track) : track = false; player addaction ["Bullet camera on", "\Bab\script\TrackEryx.sqs"]

use it to got the Bullet Cam on and Off in the user menu in game.. If work help need :)

The i past the worse file :(  PosBullCam.sqf ) :

private ["_Cam", "_Zoom", "_Missile", "_Rotate ","_zView"];
_Missile = _This select 0;
_Cam = _this select 1;
_Zoom = _This select 2;
_Rotate = _This select 3;
_zview = _This select 4;

_cam camsetpos getpos _missile;
_cam camSetFov _Zoom;
_cam camsettarget [((getpos _missile select 0) + ((sin (getdir _Missile + _Rotate  ))* 5000 )), (getpos _missile select 1)+ (((cos (getdir _Missile +_Rotate  ))* 5000 )) , ((getPos _Missile   select 2)+(velocity _Missile select 2))+ _zview ];
_cam   camcommit 0;
ctrlSettext [101,format["%1  meters",(_Missile distance player)]] ;
ctrlSettext [102,format["%1 m/s",( (Speed  _missile )* 1000 ) / 3600  ]];
ctrlSettext [103,format["%1", velocity _Missile   ]];

got lot of error in upper screen in game. But this work if i copy this in to ,y mission folder.. How do i add this in my addon.???  
And my load.sqf look like this:

_this call loadFile "\BAB\script\PosBullCam.sqf"

i'am not sure if this are correct.


About the description.ext, then i have allwas to copy inn mission folder, but thats ok..If i gor every thing to work i only need to copy one file into mission folder.. thats ok, but only need a help for the rest of the files over here..
Tnx allot again for the help i got :)

So how do the class eventhandles look if somebody got it to work??
Here is mine:

class EventHandlers
            {
         Â Â Â init="[_this select 0] exec ""\BAB\Script\Init.sqs"" ; MyFunction=loadFile ""\BAB\script\PosBullCam.sqf"" ; [""Buba""] Call MyFunction";
      };


do i have to change something here???

Tnx for your all answares and help... it's work like 50% better than 0% :)


BACK AGAIN :)

It'a seems to be 80% ok now, i Only got one error: I still have to copy PosBullCam.sqf  into my mission folder :(
How do i add the PosBullCam.sqf file into my addon???

I only change a bit inn init.sqs:

player addaction ["Bullet camera on","\Bab\script\TrackEryx.sqs"]
player addEventHandler ["fired",{_Missile = nearestObject [vehicle(player), _this select 4];[_missile] exec "\Bab\script\fired.sqs"}]

track = false

PosBullcam = preprocessFile  "PosBullCam.sqf"

validation = false


And set back the orginal fired.sqs:

_Missile =  _this select 0
? isNull  _Missile : exit
? !(track) : exit
_ok = createDialog "Speed"
? !(_ok) : exit
setAccTime 0.01
_Type= typeOf _Missile

_cam = "camera" camcreate [0,0,0]
_cam cameraeffect ["internal", "back"]


sliderSetRange [100, 0.01, 1]
sliderSetSpeed [100, 0.5, 2.0]
sliderSetPosition [100, 0]
sliderSetRange [99, 0.1, 1]
sliderSetPosition [99, 1]
sliderSetSpeed [99, 0.1, .25]
sliderSetRange [98, -180, 180]
sliderSetPosition [98, 0]
sliderSetSpeed [98, 0.5, 2.0]
sliderSetRange [97, -15000, 15000]
sliderSetPosition [97, 0]
sliderSetSpeed [97, 0.5, 2.0]
#loop
? _Type != typeOf _Missile : goto "end"
[ _Missile ,_cam,(sliderPosition 99),(sliderPosition 98),(sliderPosition 97)] call PosBullcam
setAccTime (sliderPosition 100)
? ctrlvisible 100 : goto "loop"


#End
? (getpos _cam select 1 == 0) or !(_Type != typeOf _Missile) : goto "SkipSlowEnd"
 setAccTime 0.2
~0.5
#SkipSlowEnd
_cam cameraeffect ["terminate", "back"]
 camdestroy _cam
closedialog 0
setAccTime 1
exit

So how do i fix the PosBullCam.sqf into my addon and cpp file????

If i remove the PosBullCa,.sqf from my mission folder i got this error before i got into my mission : "script PosBullCam.sqf not found"

How do i fix that?? I dont want to copy the file into my mission folder every time a make a new mission..

Someone have a answare??
Please help me
« Last Edit: 24 Jul 2004, 04:16:52 by Maximus-Sniper »

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:Add script into cpp file
« Reply #8 on: 24 Jul 2004, 08:13:02 »
Quote
got lot of error in upper screen in game. But this work if i copy this in to ,y mission folder.. How do i add this in my addon.???
You have that MyFunction=loadFile ""\BAB\script\PosBullCam.sqf"", right?
That is actually exactly the same as MyFunction = preprocessFile "possBullCam.sqf" in your mission...
So, you should rename that MyFunction to PosBullcam :)
That should take care of the problem...

You may got a bit confused from the Unnamed's and my posts above; the loadFile does exactly the same as the preprocessFile does... (you can use loadFile instead of preprocessFile in missions too, with no probs other than the bug I mentioned...)

So if you have MyFunction=loadFile ""\BAB\script\PosBullCam.sqf"" in your cpp in some unit init eventHandler, you will have a function called MyFunction to use when ever that unit in is the mission...

Oh, and remove the line [""Buba""] Call MyFunction from the eventHandler because that was just Unnamed's example, nothing to do with your addon and you don't even need to call that function from there... :)
What Unnamed meant was that you can call the function from the init EH if you need to...

Quote
About the description.ext, then i have allwas to copy inn mission folder, but thats ok
Yes, it would be much wiser to keep it this way, it's common use anyways...

As I said, you could easily include the whole description.ext in your AddOn, but it has that side effect of overriding the mission makers description.ext...
So if you have Dialogs configed in the description.ext and the mission maker also uses dialogs, there will most likely be a CTD which annoys the hell out of everybody :) ...

So keep the description.ext as a separate file...

Quote
So there is little point in including it, unless its just for reference?
[offtopic]
Well, the next MCAR beta will include a usage of this ::)
Very pointless one, but still.. ;D

There're 'add banners' you can use in missions if you want to be a 'MCAR Team KissAss' ;D ;D ;D
[/offtopic]
« Last Edit: 24 Jul 2004, 08:18:40 by HateR_Kint »
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Maximus-Sniper

  • Guest
Re:Add script into cpp file
« Reply #9 on: 24 Jul 2004, 12:10:33 »
Hei|
First of all I will thanks you all guys for heelping me :)

This class evenhandles work perfect :)

class EventHandlers
            {
            init="[_this select 0] exec ""\BAB\Script\bulletcam\Init.sqs""; PosBullcam=loadFile ""\BAB\script\bulletcam\load.sqf""";
      };

I'll thank you all again :)

I only have the description.ext file again, but i see that it would be hard to get work... :)
But if someone like to work with that, i' will be very thankfull....
Or how do I put this description.ext into another mission description.ext???
:)

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:Add script into cpp file
« Reply #10 on: 24 Jul 2004, 21:57:35 »
You better keep the description.ext as a separate file in your addon zip/rar/whatever...

Much easier and reduces the chances of description.ext conflicts...
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Maximus-Sniper

  • Guest
Re:Add script into cpp file
« Reply #11 on: 25 Jul 2004, 01:24:40 »
Hi HateR_Kint
Yes i understand that.
But if i want to edit a new mission, exsemple if i download a mission and i want to put my description.ext info to the new mission description.ext, but how?? I was trying to cop.y the info from my description.ext into the missions description.ext, but dosen't work.
And i have to use the description.ext form my bulletcam to work.
How do i do that to get the new mission to work??

Unnamed

  • Guest
Re:Add script into cpp file
« Reply #12 on: 25 Jul 2004, 03:19:04 »
Quote
Well, the next MCAR beta will include a usage of this
Very pointless one, but still..

Huh...MCar has an entire Description.ext file in the addon, used to override the mission Description.ext?

Quote
As I said, you could easily include the whole description.ext in your AddOn, but it has that side effect of overriding the mission makers description.ext...

Wow..After the numerous post I read saying you cant call dialogs from addons I'm a bit suprised. I know about include files e.t.c bit U thought you still had to call the dialogs from the missions Description.ext?

I cant help thinking how problematic it would be for OFP to have to check every addon for a description.ext.

If more than one addon is used, which description.ext is used and in what order?

Are each of the Description.ext files included in these addons all executed one after another?

Most files in addons are given a specific path, does OFP differ when it comes to Description.ext?

I could understand it looking in the default mission directory when the mission starts, and including Description.ext in a mission pbo. And I know you can declare somethings like sounds\identities in both Addons and Description.ext.

But this addon version of Description.ext appears to be the exception to the rule?

Where in danger of going off topic (in not already), perhaps you could write a tutorial?

I dont think I have read\seen anything along these lines on any of the forums, in fact they generaly say the opposite. If I remember correctly?

Cheers
« Last Edit: 25 Jul 2004, 03:35:12 by Unnamed »

Maximus-Sniper

  • Guest
Re:Add script into cpp file
« Reply #13 on: 25 Jul 2004, 03:57:47 »
Hei all :)

Now i got my bullet camera to work perffect..
I only rename my description.ext to sniper.h the i only have to do is past this line into a mission description.ext file :

#include <my_addon\sniper.h>

i read it on one of the post frome HateR_Kint :)

So i will now thank you all guys for heelping me.
Cya all, maybe a found another problem some day  ::)

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:Add script into cpp file
« Reply #14 on: 25 Jul 2004, 14:18:48 »
Quote
Huh...MCar has an entire Description.ext file in the addon, used to override the mission Description.ext?
No... It's just a *.h that has a few titleRsc 's 'coded' in it and it's just included in some missions description.ext with #include, just like M-S has now done with his bullet cam...
But that has one downside (also warning to you M-S) that if someone uses his/her own titleRsc (dialogs in your case M-S?) in his/her mission you can not use the #include because it causes at least 'member already defined' errors if not CTD...

That's why we have the titleRsc code also available as separate file so if someone already uses his/her own he/she can copy/paste only the MCAR relevant stuff to his/her description.ext...

So that's why Maximus-Sniper, you should also include the *.h you use as a separate file too...

Quote
Wow..After the numerous post I read saying you cant call dialogs from addons I'm a bit suprised. I know about include files e.t.c bit U thought you still had to call the dialogs from the missions Description.ext?
No no... You've misundertsood me...
You still need to preprocess the *.h in the missions description.ext by using the #include... As you already know...

So, no, you can not call a dialog straight from any *.pbo, you still need to 'call' it via a missions description.ext...

So you have not read misinformation... I just explained the stuff poorly (again, as usual ;) )...
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.