Home   Help Search Login Register  

Author Topic: Scripting for begginers...  (Read 1738 times)

0 Members and 1 Guest are viewing this topic.

Gameer_77

  • Guest
Scripting for begginers...
« on: 27 Aug 2002, 21:54:00 »
This is a quick guide for those of you who are new to the whole scripting business.

The Basics:

A script is basically a text file containing lots of bits of code. This makes it easier and more organized than using triggers. It also opens up new features otherwise unavailable using triggers.

Ok, first were going to make a script which detects how far away the player is from an object. Open up a new mission and place the player and an empty helicopter about 100 meters apart. Name the helicopter heli1 or something similar. Save the mission, Alt-tab out of OFP and go to the saved mission's folder. (OperationFlashpoint/users/username/missions/missionname) Make a new text file and save it as script1. Now open it up and in it put the following text:

Code: [Select]
;This is a script to make a helicopter blow up when the player comes near it.

#loop
? player distance heli <50:heli setdammage 4;exit
~1
goto "loop"

Ok let me explain: you see that ; next to the this at the top of the script? If you put that at the start of the line then everything on that line will be ignored when the script is 'run'. This is useful for adding comments about a certain part of the script. Now the next part is the #. An # defines a certain part of the script. You are able to jump to that part of the script using the goto command. in the example above the "#loop" defines the part of the script i want to jump back to and goto "loop" tells OFP to go back to #loop. It doesnt have to be loop though, it could be anything just make sure that the # and the goto are the same. (ie. #startofscript and goto "startofscript") The next bit is the "?" and the ":". The ? basically means if. So i could say - ? alive player:hint "Im alive!" - or  -? getdammage player >0.5:hint "Im hit" - you get my drift though, dont you? The ":" tells OFP what to do if the code before it becomes true. So in the latter example when the players health goes above 0.5 then a hint pops up saying "Im hit". And finally you can still use the ";" to tell OFP to do multiple commands. Like the script we made above makes OFP blow up the Chopper and makes the script exit. (IMPORTANT: The command 'exit' makes the script end)

Using your script:

This is the part most people tend to trip up at. Im going to take it step by step though: When you've made your script (like the one above) you must save it into '.sqs' format instead of the usual '.txt' format. Don't worry its very easy. Click file then go to save as... When the window pops up, name your file. But, when you've done that dont hit save yet. Wordpad and notepad save the file as a .txt file and we want to change that so you must do this: At the bottom where it says Save as Type: click the down arrow and select All Files (*.*). Now add .sqs onto the end of the name you are going to save it as. Good. Save and close the window. Now go into your mission and in the init field of the player put the following: [] exec "script1.sqs"

Ok, explanations: The [] is for passing 'arguments' to the scripts. Dont worry, its not as complicated as it sounds. The exec stands for execute and the "script1.sqs" is telling it what to execute. (make sure to always have the .sqs). Preview and run towards the chopper, when you get close it should blow up. Well done, you've just done your first script! :D

FAQ.

Q. When I try and use my script it says "Script Sciptname.sqs not found"

A. When saving your file did you remember to save it as in all file types and with .sqs at the end of it? If you done all of that and its still not working be sure to type the whole name when accessing the script (ie. [] exec "script1.sqs" and NOT [] exec "script1")

Q. Ive heard about 'Arguments', what are they and how do i use them?

A. Arguments are used to pass information onto the script. This can be useful for using a certain script for many people. You can do this by entering the persons name into the []'s. For example: [jack] exec "script1.sqs". Then in the script at the top put   " _unit= _this select 0 " (without the quotes) Then use _unit instead of the persons name. So if i was wanting to modify the script above i'd put this:

Code: [Select]
_jinx= _this select 0
#loop
? _jinx distance heli <50:heli setdammage 4;exit
~1
goto "loop"

And the code is - [jinxdude] exec "script1.sqs"

You can have more than one argument simply by puting a comma between the two when you are calling the script and adding 1 onto the "_this select 0".

Q. I'd Like to explore new commands but I don't know any of them.

A. I recommend www.flashpoint1985.com/docs/misc.html. But there is also another unofficial one deep in the realms of the internet.

Q. Where can i find more tutorials?

A. Snypir's infamous tutorial is available at all good OFP sites (Like OFPEC).

Q. I have other questions and i cant find any answers. Help!

A. Don't worry as the friendly folk at the OFPEC's forums are on hand 24-hours a day to help you out.

Thanks for reading, bye all!  :-*

 8)PEACE
« Last Edit: 28 Aug 2002, 22:04:31 by Gameer_77 »

tai mai shu

  • Guest
Re:Scripting for begginers...
« Reply #1 on: 27 Aug 2002, 23:01:54 »
nice tute.  there is also a very comprehensive tute by John Gustaffson, which i recommend any newb to read.  it was the one and only tute ive ever read, and it really is a great tute for newbs. http://www.toadlife.net/ofp/downloads/tutorials/scripting_guide/scripting.htm

Gameer_77

  • Guest
Re:Scripting for begginers...
« Reply #2 on: 28 Aug 2002, 00:48:53 »
Yes, that is a good tute. Cause the tutorial etc. sections are down at OFPEC I thought this could be temporary or for quick reference.  ;)

Adios! Amigos!  ???

 8)PEACE

Offline Sefe

  • OFPEC Patron
  • Former Staff
  • ****
Re:Scripting for begginers...
« Reply #3 on: 28 Aug 2002, 16:06:34 »
Gameer_77,

Could you please solve the topic to give the ed depot staff the opportunity to enter the data to the ed depot, once it's online?

Thank you.

Gameer_77

  • Guest
Re:Scripting for begginers...
« Reply #4 on: 28 Aug 2002, 21:27:16 »
Will do, but i'll add some other stuff beforehand.

 8) PEACE