Home   Help Search Login Register  

Author Topic: OFPEC Function Library Launched!  (Read 14334 times)

0 Members and 1 Guest are viewing this topic.

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:BETA: OPFEC Function Reference
« Reply #30 on: 08 Jan 2003, 13:54:57 »
Kool  ;D

:thumbsup:

@ snYpir - check ur mail ;) 3 functions are in dere  ;) (used in a script - so u may dont wanna post som of em  :-\)  

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline Spinor

  • Members
  • *
  • I'm a llama!
    • The chain of command
Re:BETA: OPFEC Function Reference
« Reply #31 on: 08 Jan 2003, 19:10:29 »
Quote
preprocessFile -> Compiles the file (most probaly into machine code in memory)

loadFile -> copies the content of the file line-by-line into memory
I'm not sure about this. According to the ComRef, preprocessFile only preprocesses i.e. you can use
#define aaa BBBBB
to make substitutions
and \\ to make comments.
When executing the function, there should be no difference in speed.
preprocessFile is still the way to go for precaching functions because of the two above advantages.

Offline snYpir

  • BIS Team
  • ****
  • OFPEC Jedi Master
    • OFPEC
Re:BETA: OPFEC Function Reference
« Reply #32 on: 08 Jan 2003, 20:32:12 »
Yeah, i was wrong (sort of) :-\

Suma made a comment on my tutorial, and yeah both loadFile and preprocessFile do the same thing (except for the preprocessing)

I will encourage people to use preprocessFile.
Bohemia Interactive Simulations

Offline Messiah

  • Honourary OFPEC Patron & Drinking Buddy of Wolfsbane
  • Honoured Contributor
  • ***
  • OFPEC Veteran
    • Project UK Forces
Re:BETA: OPFEC Function Reference
« Reply #33 on: 09 Jan 2003, 02:07:59 »
Code: [Select]
_unitarray= _this select 0
_hurt = []
_say = ["eng22","eng23","eng29","eng30","eng31","eng32","eng33","eng34"]

#start
_tmp= (count _unitarray) - 1
?_tmp < 0 : exit

#loop1
_unit = _unitarray select _tmp
? vehicle _unit != _unit : goto "cycle"
? "man" CountType [_unit] == 0 : goto "cycle"
? _unit in _hurt : goto "check"
? getdammage _unit > 0: _hurt = _hurt + [_unit]; goto "speak"

#cycle
~0.05
_tmp = _tmp - 1
?_tmp < 0 : goto "start"
goto "loop1"

#check
? getdammage _unit == 0: _hurt = _hurt - [_unit]
goto "cycle"

#speak
_rand = random 8
_rand = _rand - _rand % 1
_unit say (_say select _rand)
~5
goto "cycle"

so, could i convert that script into a function? its just a pain script - using a list trigger as the array it see's who is hurt and makes them say one of the editor voices, like 'MEDIC!' etc... can that be made into a function?
Proud Member of the Volunteer Commando Battalion

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:BETA: OPFEC Function Reference
« Reply #34 on: 09 Jan 2003, 02:26:28 »
no - u cant use delays in functions and u dont wanna make big loops in function cuz it wil b like big loops in scripts only faster  :o

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline Messiah

  • Honourary OFPEC Patron & Drinking Buddy of Wolfsbane
  • Honoured Contributor
  • ***
  • OFPEC Veteran
    • Project UK Forces
Re:BETA: OPFEC Function Reference
« Reply #35 on: 09 Jan 2003, 10:44:50 »
hmmm, well, could some1 post up and example of what you would write? I would like to work this function thing out, as my mission does require many, high end scripts and lag isnt an option.
Proud Member of the Volunteer Commando Battalion

Offline toadlife

  • OFPEC Old Skool
  • Former Staff
  • ****
  • Official OFP Editing Center Toad
    • toadlife.net
Re:BETA: OPFEC Function Reference
« Reply #36 on: 09 Jan 2003, 13:12:21 »
Messiah

Skim through snYpir's tute and visit the section with the few function examples.
http://www.ofpec.com/editors/funcref.php

I just added one, which shuffles an array.  Here is the code for that function for you to look at, only with comments that say what is happening.

Code: [Select]
//****************************************************
//
// Shuffle array function by toadlife
//
// http://toadlife.net
//
// Function: Shuffles an array's contents into random order
//
// Returns: array
//
// Initialize this fuction in your init.sqs file with this line: shuffle = preprocessFile "shuffle.sqf"
//
// Call this function like so:  myarray call shuffle -- (Example: [1,2,3,4,5] call shuffle)
//
//***************************************

// Keeps these variables from being snookered if they're used in other scripts? (not sure about that one)
private ["_this","_newarray","_acount","_rand","_moveitem"];

// Initialize the new array that will be returned after processing
_newarray = [];

// Shuffle code - takes "_this", shuffles the contents and put the contents into "_newarray"
while "count _this > 0" do {_acount = (count _this);_rand = random _acount;_rand = _rand - (_rand mod 1);_moveitem = _this select _rand;_newarray = _newarray + [_moveitem];_this = _this - [_moveitem]};

//This is  the new "shuffled" array. This is what is returned by the function.
_newarray;

Here would be an example:

Code: [Select]
_say = ["eng22","eng23","eng29","eng30","eng31","eng32","eng33","eng34"]
_hurt = []
#loop
~0.05
_soldiers = list mytrigger call shuffle
if ((getdammage _x > 0) && ("man" counttype [_x] == 1) && (!_x in _hurt) then {_hurt = [_x] + _hurt;[_x,_say] call injured} foreach _soldiers
if ((_x in _hurt) && getdammage _x == 0)  then {_hurt = _hurt - [_x]} foreach _soldiers
goto "loop"

Code: [Select]
//****************************************************
//
// Injured function by toadlife
//
// http://toadlife.net
//
// Function: Caused an soldier to scream out a random saying
//
// Returns: nothing
//
// Initialize this fuction in your init.sqs file with this line: injured = preprocessFile "injured.sqf"
//
// Call this function like so:  [soldier,[sounds]] call injured -- (Example: [unit1,["bum",crap","shiznit"] call injured)
//
//***************************************
private ["_rand"];
_rand = random count (_this select 1);
_rand = _rand - _rand % 1;
(_this select 0) say ((_this select 1) select _rand);

NOTE THAT THE PRECEEDING EXAMPLE HAS NOT BEEN TESTED FOR SYNTAX ERRORS OR OTHER MISC. BRAIN FARTS!  ;D
« Last Edit: 09 Jan 2003, 13:18:39 by toadlife »
"Whenever you want information on the 'net, don't ask a question; just post a wrong answer." -- Cancer Omega.

Offline Messiah

  • Honourary OFPEC Patron & Drinking Buddy of Wolfsbane
  • Honoured Contributor
  • ***
  • OFPEC Veteran
    • Project UK Forces
Re:BETA: OPFEC Function Reference
« Reply #37 on: 09 Jan 2003, 13:24:16 »
hmmm, ok, i'll have to work it out... cheers.
Proud Member of the Volunteer Commando Battalion

Offline toadlife

  • OFPEC Old Skool
  • Former Staff
  • ****
  • Official OFP Editing Center Toad
    • toadlife.net
Re:BETA: OPFEC Function Reference
« Reply #38 on: 09 Jan 2003, 13:28:08 »
Note:

Why you would want to shuffle the list of soldiers in your partucular script is beyond me :) -- I just inlcuded the function as an example. You could break your script down into more functions if you wanted to, though, I'm not sure what the benefits would be.

You could go function crazy, and make the line that removes soldiers from the "_hurt" array into a function.
"Whenever you want information on the 'net, don't ask a question; just post a wrong answer." -- Cancer Omega.

Offline toadlife

  • OFPEC Old Skool
  • Former Staff
  • ****
  • Official OFP Editing Center Toad
    • toadlife.net
Re:BETA: OPFEC Function Reference
« Reply #39 on: 09 Jan 2003, 21:54:11 »
HOw would you include multiple scripts in a pbo file? I tried and can't seem to access them once they are pbo'd.
"Whenever you want information on the 'net, don't ask a question; just post a wrong answer." -- Cancer Omega.

Offline KTottE

  • Former Staff
  • ****
Re:BETA: OPFEC Function Reference
« Reply #40 on: 09 Jan 2003, 22:58:27 »
Why would you want to .pbo only scripts anyway?

I suggest looking at the config.cpp for the entire game, and scripts.pbo
I'm sure those will tell you what to do.
"Life is not a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside, thoroughly used up, totally worn out, and loudly proclaiming 'WOW What a Ride!'"

Offline toadlife

  • OFPEC Old Skool
  • Former Staff
  • ****
  • Official OFP Editing Center Toad
    • toadlife.net
Re:BETA: OPFEC Function Reference
« Reply #41 on: 10 Jan 2003, 02:55:50 »
Why would you want to .pbo only scripts anyway?

I wouldn't. I would cause more problems than it would solve. At first I though it would be neat to include the functions in an addon, but when I envision the problems that addons allready cause, I think it would be a disaster. Nevermind :P
"Whenever you want information on the 'net, don't ask a question; just post a wrong answer." -- Cancer Omega.

Offline snYpir

  • BIS Team
  • ****
  • OFPEC Jedi Master
    • OFPEC
Re:BETA: OPFEC Function Reference
« Reply #42 on: 10 Jan 2003, 03:05:37 »
The 'function library' is now officially open. Now, everyone please upload their functions! ;D

There is also a massive tutorial on how to write functions, accessable from the function library main page.
Bohemia Interactive Simulations

Turver

  • Guest
Re:OFPEC Function Library Launched!
« Reply #43 on: 01 Mar 2003, 18:41:11 »
i thought u guys needed cheering up  ;D

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:OFPEC Function Library Launched!
« Reply #44 on: 02 Mar 2003, 05:06:33 »
Turver,

while that's good for a laugh, could you please refrain from posting off topic stuff in the Announcements forum... ;)

We do some serious stuff in here! ;D