Quantcast

Jump to content

» «
Photo

Y_Less's Coding Tutorial

32 replies to this topic
Y_Less
  • Y_Less

    629

  • Members
  • Joined: 14 Mar 2004

#1

Posted 25 December 2004 - 09:19 PM

As the title above says, I have ripped this from my posts in Mission Coding (my posts, so it's not plaegerism).

As a result, they may seem a little odd as they were written over the course of a few months, so follow my progression in coding, and I can't be bothered to edit them.

I just wanted a bit more exposure for them, so, here we go:

Y_Less
  • Y_Less

    629

  • Members
  • Joined: 14 Mar 2004

#2

Posted 25 December 2004 - 09:20 PM

Alex "Y_Less" Cole's n00b guide to coding.

I know a coding n00b writing a tutorial on coding may seem a bit odd at first, but there is method in my madness. I am just starting coding, as I know alot of other people are or would like to, so I am putting things here as I find them out, in n00b terms, from the point of a n00b, so that hopefully other n00bs will be able to follow it. Its all well and good going "how do I do this?" and the experienced people go "using OpCodes bla bla bla with some variable doing this", nut I don't know about you, but I would much rather know how to figure all this stuff out myself, as, I am sure, everyone else (including experienced coders - whose time would be freed up by not having to tell 5 different people how to do an OR cos they can't find the command) would.

If anyone with more experience would like to contribute, please fell free to, but remember that we don't know what OpCode 04AE or 02A7, for example, do off by heart and would need to be explained.

I am hoping that eventually, as I get more experienced, and other people do, I will be able to make this into a full blown tutorial on coding for beginners, easy to understand for them, and others.

Anyway, enough about all that, on to Part 1: Placing Items.

There are a couple of items I am going to cover in this, pickups, vehicles, weapons, marker points and other models, this is probably the best place to start as without these, you can't do anything else.

1. Pickups.

The easiest way to find out how to do things is to search the code for existing examples of it. When you first power up the editor, you see a long list of object definitions, one of which looks like this:

CODE
DEFINE OBJECT BODYARMOUR                  \\ Object number -18


We know what the object is called, so it we want to place one, just go to search and search for BODYARMOUR. Whats the first result that somes up, besides the object definiton we just looked at? this line:

CODE
0107:  3572?? = create_object -18? (BODYARMOUR) at -66.629! -1488!  12.113!


Unfortunately, we are looking for the body armour pickup, that is just an object, so keep searching until you find this line:

CODE
0213:  5272?? = create_pickup -18? (BODYARMOUR) type  15? at -314.7! -551.2!  10.3!


0213 is the create_pickup OpCode, used for item pickups (except weapons except mele weapons). If you look below the line you are on, you will se the line:

CODE
0213:  5276?? = create_pickup #CHNSAW type  15? at -310.7! -551.2!  10.3!
- the 0213 OpCode

And then a bit further down, the line:

CODE
032B:  5280?? = create_weapon_pickup #PYTHON  15? ammo  24? at -306.7! -551.2!  10.3!
- not the 0213 OpCode - it has ammo values as well.

Back to our armour pickup, you can see after the OpCode a variable, this is what stores the armour, if we want to add our own, we need to change this to an unused variable, you can either find out what the lowest unused variable number is, or you can use a string variable, e.g:

CODE
0213:  $my1starmour = create_pickup -18? (BODYARMOUR) type  15? at -314.7! -551.2!  10.3!


Now to where to put it, fire up Code Creator and VC and walk to where you want it, I'm going to put it at:

108.0565! -839.6693! 10.46322! - by the front door of Ken's next door neighbours, so change the co-ordinates at the end to those, and you get:

CODE
0213:  $my1starmour = create_pickup -18? (BODYARMOUR) type  15? at 108.0565! -839.6693! 10.46322!


Now you can't put this line into the code where you got it from because that was in the middle of a thread, so continue searching through the code until you find a long list of pickups next to each other (at around line 28430) and insert in in there. Now save, compile and run.

user posted image

2. Vehicles

We will use the tequniques used in the previous part to find how to make vehicles, if you are still on the part with the armour, scroll up a little bit and you will find the code for the vehicles. I am going to place a packer (the car transporter) outside the Malibu to jump over it, find the line for the packer in the Vice Port and copy it:

CODE
014B:  7516?? = init_parked_car_generator #PACKER -1? -1?  0? alarm  0? door_lock  0?  0?  10000& at -946.3! -1379.5!  11.5! angle  69!
014C: set_parked_car_generator  7516?? cars_to_generate_to  101?


The co-ordinates I got were:

470.9084! -121.0596! 10.36153! and the rotation is 0 as I am looking North (rotation is done in degrees anti-clockwise from North). There is also another variable in these 2 lines, so replace them both with a new one (they are the same, so leave them the same).

CODE
014B:  $my1stcar = init_parked_car_generator #PACKER -1? -1?  0? alarm  0? door_lock  0?  0?  10000& at 470.9084! -121.0596! 10.36153! angle  0!
014C: set_parked_car_generator  $my1stcar cars_to_generate_to  101?


We want it unlocked and unalarmed, so leave those as 0, and we want it to appear, so leave the cars_to_generate_to as 101?

Save, compile and run again. Remember that you need to start a new game after every little tiny mod.

user posted image

3. Weapons

We have already covered the OpCode for weapons, most weapons are directly under the cars, so go down to them and copy the line for an M4

CODE
032B:  8096?? = create_weapon_pickup #M4  15? ammo  60? at -1221! -641.6!  11.7!


Then decide where you want it and and how much ammo you want to give it and put them in (?'s are interger values and !'s are floating point values). Finally, change the variable at the beginning again (you always need to do this), save, compile and test.

CODE
032B:  $my1stgun = create_weapon_pickup #M4  15? ammo  100? at 5.266161! -939.0254! 16.116!


user posted image

4. Marker points

I don't know what the code for this is, but thankfully, the people who find these things out give them sensible names, so, as we want to create a marker, search for create_marker, and what do we get? - a bit of marker code! The second one I came accross I know is a small round pink one as it is the marker from the 'The Party' mission outside Rafael's, so copy this and edit it.

CODE
02A8:  236?? = create_marker  28? at  396??  400??  404??


Note on this one, unlike the others, the co-ordinates are stored as variables instead, these will have been defined earlier in the mission as the actual co-ordinates and just used here.

CODE
02A8:  $my1stblob = create_marker  28? at  556.2355! -3.073752! 14.3036!


I have made mine by the front door of the WK Chariot, insert this code somewhere sensible, e.g. with all the other pickups in Mission 0, this will mean it is there from the start. And now, of course, test.

If you have been following, you will have discovered that testing is very important, as that is infact the wrong OpCode! That just creates a marker on the radar that looks like a T-shirt (the Rafael marker). After a bit more searching through the code, I found these markers to test:

CODE
02A7:  892?? = create_icon_marker_and_sphere  1668?? at  1824??  1828??  1832??
018A:  76?? = create_checkpoint_at  8452??  8456??  8460??


But when I tested it, I found the first was the Lawyer radar marker and the second was just the pink marker on the radar that shows whether something is below, level with or above you. So after alot more searching, I found this:

CODE
0189:  264?? = unknown_create_checkpoint_at  240.4! -1280.2!  10!


In the end I just searched for instances where I know it existed, i.e. the hotel marker at the very beginning an searched for those. But this does show you how easy it is to get it wrong and how important testing is (I did consider re-writing this part, but I decided to leave my blunder in just to show you how to sort things like this). So after editing it, and removing the t-shirt marker (I kept in the height marker for show), I ended up with code that looked like this:

CODE
018A:  $my1stblob = create_checkpoint_at  556.2355! -3.073752! 14.3036!
0189:  $my2ndblob = unknown_create_checkpoint_at  556.2355! -3.073752! 14.3036!


Which, after testing, does work.

user posted image

5. Other models

From what I have read, alot of people consider this quite advanced as it allows you to do map manipulation, which is supposedly hard, but I think its quite fundamental.

The first thing you need to do for this is define the model, if you have Moo Mapper, this is probably the easiest way to find a model. For this, I am going to put a security box outside 1102 Washington Street - not exciting, but it can be expanded on.

First, you need to find add the model. At the top, where we first got the body armour info, to the bottom of the list, add this line:

CODE
DEFINE OBJECT bar_gatebox01             \\ Object number -204


And increase the number of models at the top by one. This has now defined the model in the code.

Now you need to find the code to put the model into the world, simply scrolling down a few lines reveals these lines:

CODE
029B: $ARENA_DOOR_1 = init_object -1? (DTN_STADDOORA) at -1109.615!  1330.097!  20.372!
01C7: spawn_object $ARENA_DOOR_1


Using these co-ordinates:

103.192! -812.6703! 10.46329!

We can modify the code to add our model. Note - the model number in the above example is above -128, so it can be a short integer variable, as ours is -204 - much less that -128 we need to use the & variable type.

CODE
029B: $my1stobject = init_object -204& (bar_gatebox01) at 103.192! -812.6703! 10.46329!
01C7: spawn_object $my1stobject


This will spawn a random box outside 1102 Washington Street - it is above the ground and flies off when you touch it, but it is a start and this can easilly be rectified later.

user posted image

Practice activites:

1. Put a police bribe in the room at the top of the lighthouse.

2. Add a marker to the radar to show you where it is.

3. Spawn a motorbike inside the grocery store down the road from El Swanko Casa, and turn its alarm on.

4. Find the OpCode for the large, racing checkpoint circles and put one on the bridge to Starfish Island.

5. Find the weapon number for the camera as used in Marthas Mugshot and give the player it.

I hope this is a useful introduction to coding, if so I will continue and try to write more as I find more, please add any comments you like below (except flames for the maker mess up - I think I deserve to not get flamed for owning up to it).

Y_Less
  • Y_Less

    629

  • Members
  • Joined: 14 Mar 2004

#3

Posted 25 December 2004 - 09:20 PM

Alex "Y_Less" Cole's n00b guide to coding.

Its finally here: Part 2: Using Threads and Labels.

In this tutorial I will be exploring how to use threads, labels and ifs to check for conditions being met in order for more things to be done.

1. Labels.

A label names a small section of code so it can be called at any time, e.g.

CODE
:Label0B0910
00D6: if  0?
00DF:   actor  18576?? driving
004D: jump_if_false £Label0B0925
03E2: actor  18576?? exit_car


This is just a random bit of code I got from the main.scm, but anytime you put
CODE
0002: jump £Label0B0910
it will run that piece of code, and any bits linked to it by it, e.g. all the bits of code under £label0B0925 (and al the bits under that), (which happens to be just this):

CODE
:Label0B0925
0002: jump £Label0B0942


2. Threads.

A thread is a label, or collection or labels, that runs continuously to see if the player is doing something, every mission has a thread to check if the previous mission has been competed, and if it has, to check if the player is in the spot that triggers the mission (i.e. the contact point), and if those are both true, runs the mission. Threads are used to run all the things that happen in the game, they don't do them, generally, but will check conditions and run the associated mission if all the conditions are met. There are exceptions, threads can and do do things themselves, but generally these are more complex.

3. Ifs.

These are the bits that actually check for if something is happening, and jump somewhere if it isn't happening. This may seem a little backwards at first but is quite sensible as it means you can say 'Is this happening? No? Oh well sod off then'.

CODE
00D6: if  0?
0214:   pickup $PRINT_WORKS_ASSET picked_up
004D: jump_if_false ££Label00CA42
0417: start_mission  36?
004E: end_thread


This is another random piece of code taken from the Print Works Asset buying thread (surprisingly). It checks to see if the player has picked up the buy asset marker (by this point in the code it will be available), and if they have, run the buy Print Works asset mission (yes, even buying things is classed as a mission). But if it hasn't been picked up, it never gets to that piece of code as it is redirected (jumped) to another label, which restarts the thread to check again. if 0? means the code will check 1 condition, 1 means 2 etc, 20+ are ors'. e.g. if 21? means if condition 1 OR condition 2 is met, return true.

4. Using them together.

There are a few things that all threads need to work, firstly a definition. Without this, the code will not know that the thread exists and will not run it to check.

CODE
004F: create_thread ££Labelmy1stlabel


This OpCode is always used for this, you just change the label name depending on your threads first label.

Second, you need to create the label for the first part of the thread and, although from what I have read, this is not essential, name it.

CODE
:Labelmy1stlabel
03A4: name_thread "my1stth"


This tends to be all there is in the first label, although I belive this is more down to conventon and good coding practice than actual need. When using multiple labels in a thread, unless you jump in on label, the code will continue running through to the next label. e.g.

CODE
:Labelmy1stlabel
03A4: name_thread "my1stth"

:Labelmy2ndlabel
0001:wait $default_wait_time ms


This will run the first label, then continue on to the second part. You will also notice a wait in there, the code needs this or the game will crash. It would run the thread continuously, but that gives it a break (in ms) so it is not running it then re-running straight away, the length of the wait depends on how often or quickly the thing could happen. If you were writing code to see if the player is jumping, you would need a short wait, but if you were checking to see if they have completed a mission, it can be a longer wait as they will have still completed is several seconds later, $default_wait_time is a standard variable with a preset time in.

The final thing they need is a bit at the end to loop back to the beginning to re-run the code and re-check. This tends to also be in its own label so you can jump to it if a condition is not met.

CODE
:Labelmy3rdlabel
0002: jump ££Labelmy2ndlabel


Note the jump to ££Labelmy2ndlabel, this is because we don't need to re-re-name the thread.

5. My 1st Thread

In section 4, we have already established how to run a thread, and all the esentials needed for it, so now we can start constructing our own thread. We will use the pink marker created in the last part and the truck to create a thread to only spawn the truck after you have stepped in the pink marker.

First we will need to stop the truck spawning in the first place, but we still need it to be defined, so go to the part of the code where your truck is, i.e. this bit

CODE
014B:  $my1stcar = init_parked_car_generator #PACKER -1? -1?  0? alarm  0? door_lock  0?  0?  10000& at 470.9084! -121.0596! 10.36153! angle  0!
014C: set_parked_car_generator  $my1stcar cars_to_generate_to  101?


and change the 101 at the end to just 0.

CODE
014C: set_parked_car_generator  $my1stcar cars_to_generate_to  0?


Now if you placed your marker at the same place as me (over-looking the truck from a distance), then the co-ordinates for your blob should be:

556.2355! -3.073752! 14.3036!

, if not just use your instead.

We already have th start of our thread, with :Labelmy2ndlabel being the main part, but we need to make it check that the player is near the pink blob. There are alot of OpCodes which will check where a player is, so go to search and search for 'near' (or use F1) we want the player to be on foot when doing it, not in a car, so keep going until you find this line.

CODE
00F6:   player $PLAYER_CHAR  0? ()near point on foot  1812??  1816??  1820?? radius  1.4!  1.8!  1.5!


It is using a variable to define the co-ordinates, so change these to ours, we can also tell that this is an if statement check by the indent, which most of them have (if you aren't sure which is which, look in the OpCodes list file which has a complete list of all the OpCodes and what sort they are).

CODE
00F6:   player $PLAYER_CHAR  0? ()near_point_on_foot  556.2355! -3.073752! 14.3036! radius  1.4!  1.8!  1.5!


You can leave the radius as it is, this just says how close to the point you need to be. Now put this in an if statement with a jump_if_false to my3rdlabel, and you will have your first check (if 0? as there is only one condition).:

CODE
00D6: if  0?
00F6:   player $PLAYER_CHAR  0? ()near_point_on_foot  556.2355! -3.073752! 14.3036! radius  1.4!  1.8!  1.5!
004D: jump_if_false ££Labelmy3rdlabel


Now we know when the player is in our blob, we need to do something with that fact, as in, make the truck spawn. This is very easy, just copy the 014C opCode line you edited earlier, paste it under the if statement, then change the number back to 101. If you have done all this, you should have code something like this:

CODE
:Labelmy1stlabel
03A4: name_thread "my1stth"

:Labelmy2ndlabel
0001:wait $default_wait_time ms
00D6: if  0?
00F6:   player $PLAYER_CHAR  0? ()near_point_on_foot  556.2355! -3.073752! 14.3036! radius  1.4!  1.8!  1.5!
004D: jump_if_false ££Labelmy3rdlabel
014C: set_parked_car_generator  $my1stcar cars_to_generate_to  101?

:Labelmy3rdlabel
0002: jump ££Labelmy2ndlabel


If we compile and run this it will work.

Before:

user posted image

After:

user posted image

Unfortunately, as you can see here:

user posted image

, the marker is still there (and active) so everytime you go there again, you can still see it and it will continue to turn on the truck, even though it is already there. The easiest way to counter this is to set a variable that says it has already been done, then disable the markers. All the markers use the same command to disable them:

CODE
0164: disable_marker  264??


(after search). There are 2 markers in our code, $my1stblob and $my2ndblob, the pink marker and the radar marker, so copy the line twice and replace the variables with our variables.

CODE
0164: disable_marker  $my1stblob
0164: disable_marker  $my2ndblob


Put this with the set_parked_car_generator line, and it will turn off the markers at the same time as it turns on your car.

user posted image

Your first thread is now basically complete, you can leave it as that, or you can add, as mentioned before, a variable so that it doesn't keep doing things it has already done. This is another important OpCode, 0004.

CODE
0004:  $my1stvar =  1?  \\ integer values


Put this with the other parts done after the if statement and when you stand in the circle, it will set your variable to 1, which is all well and good, but you need the code to know that it is 1. Using the if statement, change the value to 1, for 2 conditions, then add a new line to check if $my1stvar is 0 (1 means it has already been done and will skip the bits being done). However, this time, I'm not going to tell you the OpCode, you can look it up yourself, but I will tell you you are looking for
CODE
==  0?


Practice activites:

1. Place a pink marker and a radar marker in the middle door of the large building next door to 3321 Vice Point (the one with the armour next to it).

2. Make a thread and get it to run with a delay of 500ms.

3. Add an if statement to check whether the player is within a radius of 4! 4! 4!, in a car, of it (don't add a section to check if you have done it before).

4. Use OpCode 00BC, and text "TAX2_4" to print a message to the screen when you are there.

5. Add to the if statement so the text will only appear if you are driving a Boxville (you may want to spawn one somewhere for ease of access).

Thats it for this Part, I don't know what to do for the next yet, but if I think of anything, or someone gives me a good idea, then I will do another. So again, please comment below.

Y_Less
  • Y_Less

    629

  • Members
  • Joined: 14 Mar 2004

#4

Posted 25 December 2004 - 09:21 PM Edited by Y_Less, 26 December 2004 - 12:52 PM.

Alex "Y_Less" Cole's n00b guide to coding.

Part 3: Variables.

Its been a while since I did parts 1 and 2, so I decided to do another as since that time I have progressed (IMHO) considerably. NOTE: this is designed for BWME 0.22, I do try to outline the differences between that and 1.3, but as that is not my prefered editor, the information may not be accurate.

1. Basics.

In Vice City, for the most part (all the parts I have found, but there may be an exception), integers and floating-points are handled separately, using different sets of OpCodes for definitions, checks and manipulations, although they all do the same thing, just some do it for one type, some for another. Integers are (as most people will know) whole numbers, floating-points are decimal numbers. Variables can hold either type, but must be set up using the correct OpCode set for each type, and they must not be swapped around (they can be changed, but I will cover that later).

So for example:

CODE
0004:  2420?? =  2000&  \\ integer values
0011:  2420?? *=  100!  \\ floating-point values


would not work, wheras:

CODE
0004:  2420?? =  2000&  \\ integer values
0010:  2420?? *=  100?  \\ integer values


would (should) work, giving an answer of 200000&& (I'll come to the symbols after the numbers, people using 1.3 can just ignore them.)

As you can see, you can set a variable immidiately, or you can set it to the result of something else. Most variable OpCodes only have 2 parameters, so you could not use something like:

CODE
0AA5:  2420?? =  2424?? * 5?  \\ integer values and handles


as a) it doesn't exist and, b) there is more than one parameter. If you wanted to set 2420?? to 5 times the value of 2424??, whilst still retaining the value of 2424?? you would need to use code such as:

CODE
0084:  2420?? =  2424??  \\ integer values and handles
0010:  2420?? *=  5?  \\ integer values


to some this may seem awkward and unwieldy, but it reduces the number of OpCodes and can be quite powerful once got used to.

The symbols after the numbers represent the type of number they are:

! - floating-point
? - short integer (0 - 255)
& - integer (256 - 32767)
&& - long integer (32768+)

?? means variable and a preceding $ means custom variable (in 1.3 this is used to represent all variables, integers are assumed and floating-points require at least 1 decimal point (even .0) to identify it as such).

0.22 code:

CODE
0213:  5120?? = create_pickup -205& (CAMERAPICKUP) type  2? at  18!  1148!  24!
0213:  5124?? = create_pickup -4? (BRIBE) type  15? at  474.4158! -1717.396!  57.25289!
018A:  5128?? = create_checkpoint_at  474.4158! -1717.396!  57.25289!
014B:  348?? = init_parked_car_generator #DELUXO -1? -1?  1? alarm  0? door_lock  0?  0?  10000& at -1022.6! -868.6!  12.2! angle  175!
014C: set_parked_car_generator  348?? cars_to_generate_to  0?


corresponding 1.3 code:

CODE
0213: $500 = create_pickup -205 (CAMERAPICKUP) type  2 at  18.0  1148.0  24.0
0213: $501 = create_pickup -4 (BRIBE) type  15 at  474.4158 -1717.396  57.25289
018A: $502 = create_checkpoint_at  474.4158 -1717.396  57.25289
014B: $57 = init_parked_car_generator #DELUXO -1 -1  1 alarm  0 door_lock  0  0  10000 at -1022.6 -868.6  12.2 angle  175.0
014C: set_parked_car_generator $57 cars_to_generate_to  0


2. Integers.

A list of useful integer OpCodes (the corresponding floating-point ones can be found in the next section).

CODE
0004:  268?? =  3?  \\ integer values
0084:  2892?? =  2896??  \\ integer values and handles
0010:  2904?? *=  2?  \\ integer values
0014:  3072?? /=  1000&  \\ integer values - be careful with this one, i'm not sure what happens if the result is not a whole number.
0008:  32?? +=  1?  \\ integer values
000C:  3404?? -=  1?  \\ integer values


Conditionals:

CODE
003A:    6068?? ==  5688??  \\ integer values and handles
0038:    72?? ==  3?  \\ integer values
001C:    1584?? >  4728??  \\ integer values


Their are many other OpCodes to do many other things, I suggest looking through before trying to do anything.

Integer Opcodes are also used for most of the other variables which aren't numerical, e.g. objects and properties. E.g:

CODE
0225:  5480?? = player $PLAYER_CHAR health


would save the result as an integer so you could then do:

CODE
0084:  5484?? =  5480??  \\ integer values and handles
0010:  5484?? *=  5?  \\ integer values


to end up with 5484?? being (if, say, Tommys health was 76) 380.

Also, if you used the OpCode:

CODE
0441:  8436?? = car  8432?? model

then
CODE
0084:  8440?? =  8436??  \\ integer values and handles


Whalst they are not numbers, those OpCodes would still work to set 8440?? and 8436?? to car 8432??'s model.

3. Floating-points.

Used the same as integers except they have differet OpCodes and only handle numbers, nothing else.

Corresponding OpCodes to the listed integer OpCodes:

CODE
0005:  268?? =  3.1!  \\ floating-point values
0086:  2892?? =  2896??  \\ floating-point values only
0011:  2904?? *=  100!  \\ floating-point values
0015:  3072?? /=  2!  \\ floating-point values
0009:  32?? +=  .1!  \\ floating-point values
000D:  3404?? -=  1.85!  \\ floating-point values


Conditionals:

CODE
2 variable conditional never used in VC or GTA 3
0042:    2900?? ==  100!  \\ floating-point values
0024:    3008?? >  2996??  \\ floating-point values only


4. Types of variables.

$type1 - These can be named anything as long as they have a '$' sign at the beginning.

20?? - These are the variables used in the compiled script, all the variables used in the code are compiled into this format, but can be written into it as well.

3@ - These are local variables, they are only used within 1 thread and range from 0 - 17 (apparently there is a 19, but that only works between waits, and I don't know about 18). These can be floating-point or integer, and have their own OpCodes which work for both types.

16@ and 17@ are timer variables. You set them to 0, then next time you access them they will have incremented by the number or milliseconds since your last usage. I.E. they increment by one every millisecond.

5. Usage.

Variables are used to store everything in memory. Anything you define or use must be stored in a variable so the engine can keep a track of it and so you or it can manipulate them later:

CODE
029B: $carcrane = init_object -207& (doc_crane_cab01) at -947.878! -1504.33! 22.3812!


This creates an object (in this case a crane) and stores a reference to it in the variable $carcrane (after compilation - 1008??). This information can then later be used to manipulate the crane:

CODE
00D6: if 0?
834D:   NOT unknown_rotate_object  $carcrane unknown_angle  247!  0.5!  0?
004D: jump_if_false ££Labelsumlabel


It is very difficult to define the use of variables, they are used everywhere and any code without them would be immensly basic, many things can be done without, but they really are important.

I said before that changing between the 2 types is not as straight-forward as it may seem, it can however be attained with the use of:

CODE
008C:  3076?? = float_to_integer  3088??
008D:  3092?? = integer_to_float  3076??




These simply convert between one and the other.

Practice activites:

This tutorial was mostly just information (sorry), but that means there aren't really any practice activities.

Thats it again for another part, I know this one was not as interesting as some of the others, but I did it anyway. My next one will be interesting (for me to write as well) as it is an expansion on variables into the often avoided area of arrays. Many people either despise tham or steer clear of them, but I will attempt to unravel them and make them easier to understand, and show how to use them in 0.22 - its dead easy once you know how they work.

Edit: Added local timers.

Y_Less
  • Y_Less

    629

  • Members
  • Joined: 14 Mar 2004

#5

Posted 25 December 2004 - 09:21 PM Edited by Y_Less, 26 December 2004 - 12:53 PM.

Double post I know, but I have written another part to my mission coding tutorial for newbs after a request (of sorts) from timmy2004.

Alex "Y_Less" Cole's n00b guide to coding.

Part 3b: More Floating Point Numbers.

After a comment by Timmy 2004 on my website about not understanding floating point numbers, I thought "well if he doesn't, what chance do new people stand?" So I decided to write this to help explain them.

Basically, a floating point number is not a whole one 1.2 is a floating point number, 12 isn't. In mission coding, whole and floating numbers are handled by different OpCodes to speed things up (Its a lot easier for computers to do integer operations than floating ones, so they reduce thhe number needed to be done).

You can manipulate whole numbers as floating point ones (e.g. 12 effectively becomes 12.000) and this does have its uses, but this takes longer to process and sometimes you cannot do this due to the type and usage of the integer.

For this I will be using the later MB format of 12 for an integer number and 1.2 (or 12.0) for a floating point (or whole floating point).

As stated earlier, floats use different OpCodes to whole numbers and these cannot be mixed and matched so 5 * 6 would use a different Code to 5.2 * 6.7. They cannot be used together either so 5 * 6.7 wouldn't work at all.

When a variable is stored, so is its type, and this is remembered, so adding 0.1 to 5.9 will not make it suddenly turn into an integer and only be able to use float OpCodes. This would wreak havoc with coding! (On a side note, you cannot use integer OpCodes with the answer at all, its the wrong data type.)

What do I need these for?

They are mainly used for positional data, times and other continuous data. Things like 'people killed' is discrete data, you cannot kill 6.74 people so it is stored as integer data. However you can be stood at co-ordinates 4.5 67.549 -89.6 (yes, negative numbers can be both), 76.1 8.0 1078.5 or pretty much anywhere else.

The only major things I can think of for them are co-ordinates, distances, times/ timings and rotations, though there will be more, minor ones.

So 2.5 by 2.5 is 1.0, not 1, right?

Yes.

But what happens if I divide 7 by 6, the answer isn't a whole number?

No, but if you are using them as integers, they just ignore the remainder.

Changing between them.

This is possible using OpCode's
CODE
008D: (int) integer_to_float (float)
and
CODE
008C: (float) float_to_integer (int)
, which do 'exactly what they say on the tin'

I've tried going into as exhaustive as possible detail, but if you still don't understand anything, or think i've missed something useful or fundamental, tell/ ask me and I'll add it.

Edit: Cheers Craig, added the division info.

Gforce
  • Gforce

    "Segregate and Rearrange" "The Hills"

  • Feroci Racing
  • Joined: 17 Sep 2003
  • United-Kingdom

#6

Posted 26 December 2004 - 12:46 AM

thank you very much for this, now i might try doing some code for my lots on myriad..........Merry Christmas catloaf_by_anuj.gif cookie.gif breadfish_by_Moto.gif

timmy2004
  • timmy2004

    Gangsta

  • Members
  • Joined: 05 Aug 2004

#7

Posted 27 December 2004 - 03:16 PM

Geez, I was wondering when you were going to post these here, they get alot more attention here. tounge.gif

Y_Less
  • Y_Less

    629

  • Members
  • Joined: 14 Mar 2004

#8

Posted 28 December 2004 - 01:27 PM

Yeah, shows! smile.gif

You, whose seen em and one other!

tounge.gif

htsb8
  • htsb8

    Crackhead

  • Members
  • Joined: 17 Mar 2005

#9

Posted 29 March 2005 - 06:46 PM

Nice!
thanx,Y_Less

ah.....

YeTi
  • YeTi

    S'up Bitches?

  • Andolini Mafia Family
  • Joined: 28 Mar 2005

#10

Posted 17 April 2005 - 03:43 PM

nice tutorial its helped me ALOT but i dont understand what you do with integer and floating points i think i understand how to use them but i dont understand what to use them on or were to use them could some body please explain thanks

YeTi

Y_Less
  • Y_Less

    629

  • Members
  • Joined: 14 Mar 2004

#11

Posted 18 April 2005 - 04:09 PM

Did you read part 3b?

I tried to explain them in there, dunno how better I can put it.

Floats are non-whole numbers, used when a whole number is not applicable, e.g. co-ordinates, angles (not times as I said in my tutorial, not sure why I put that).

Different OpCodes will only take one type for different parameters, you cannot interchange, just need to see where to use them (look at the original code if you're not sure what should be where).

YeTi
  • YeTi

    S'up Bitches?

  • Andolini Mafia Family
  • Joined: 28 Mar 2005

#12

Posted 18 April 2005 - 11:44 PM Edited by YeTi, 24 April 2005 - 06:36 PM.

ye i understood that i dont understand is where you have to use them and why?

EDIT: i think i understand now sorry for being dumb but is it just used for any number in the game?

YeTi

Y_Less
  • Y_Less

    629

  • Members
  • Joined: 14 Mar 2004

#13

Posted 27 April 2005 - 01:16 PM

What do you mean any number in the game?

In the script (as I have said), different OpCodes have different required parameters - those will relate to the game in ways described by the OpCode. Any numbers displayed ingame (ie as text on the screen) can only by integers.

YeTi
  • YeTi

    S'up Bitches?

  • Andolini Mafia Family
  • Joined: 28 Mar 2005

#14

Posted 27 April 2005 - 01:25 PM

right now i get you thanks for putting up with dumb me suicidal.gif have a cookie for it cookie.gif

YeTi

Drakos
  • Drakos

    Square Civilian

  • Members
  • Joined: 28 Jul 2005

#15

Posted 20 November 2005 - 12:47 PM

I want to ask a question. (I am posting it here because it has to do with the tutorial)

I have succesfully made a car spawn somewhere in Oceandrive. I want a cop to be in it. I searched for opcodes and I wrote this in the main.scm (in mission 0)

CODE
014B:  5208?? = init_parked_car_generator #POLICE  8?  8?  0? alarm  50? door_lock  0?  0?  10000& at 391.479! -746.434!  10.6! angle  -116.00!
014C: set_parked_car_generator  5208?? cars_to_generate_to  101?
0129:  2888?? = create_actor  4? #COP in_car  5208?? driverseat
01ED: spawn_actor  5208??


I start a new game but the game crashes while Ken and Tommy come from the docks to his office in the admiral. I spent more than 3 hours trying to figure out what's wrong but with no result. mad.gif sad.gif angry.gif confused.gif

wauzie
  • wauzie

    GTI + MI

  • Members
  • Joined: 12 Mar 2005

#16

Posted 20 November 2005 - 01:04 PM

Try this:

CODE
014B:  $5208 = init_parked_car_generator #POLICE  -1  1  0 alarm  50 door_lock  0  0  10000 at 391.479 -746.434  10.6 angle  -116.00
014C: set_parked_car_generator  $5208 cars_to_generate_to  101
0129:  $2888 = create_actor  4 #COP in_car  $5208 driverseat

Drakos
  • Drakos

    Square Civilian

  • Members
  • Joined: 28 Jul 2005

#17

Posted 21 November 2005 - 02:34 PM Edited by Drakos, 21 November 2005 - 02:42 PM.

Nothing angry.gif angry.gif die.gif die.gif confused.gif confused.gif confused.gif confused.gif confused.gif die.gif die.gif die.gif angry.gif angry.gif angry.gif angry.gif

the same sh*t again... Oh, yesterday while trying to figure out what is wrong I made a cop to come out of the Admiral and Rosenberg got out AFTER the cop did but i wasn't intended to do that. Mysterious, eh?

Can you try find a solution? any of your help is appreciated

Y_Less
  • Y_Less

    629

  • Members
  • Joined: 14 Mar 2004

#18

Posted 21 November 2005 - 06:44 PM

CODE
014B:  $5208 = init_parked_car_generator #POLICE  -1  1  0 alarm  50 door_lock  0  0  10000 at 391.479 -746.434  10.6 angle  -116.00
014C: set_parked_car_generator  $5208 cars_to_generate_to  101
0129:  $2888 = create_actor  4 #COP in_car  $5208 driverseat


Firstly, as I said in the tutorial (IIRC), use names for variables, not numbers, it will avoid mixing them up with other existing variables. Second you need to request the actor which isn't covered above, try looking in the mission coding forum and do a search.

Drakos
  • Drakos

    Square Civilian

  • Members
  • Joined: 28 Jul 2005

#19

Posted 21 November 2005 - 07:59 PM

I tried this:

:Labelmycop1
014B: $mycopget = init_parked_car_generator #POLICE -1? 1? 0? alarm 0? door_lock 0? 0? 10000& at 391.479! -746.4341! 10.6! angle -116.00!
014C: set_parked_car_generator $mycopget cars_to_generate_to 101?
0247: request_model #COP
038B: load_requested_models

:Labelmycop2
0129: $copspawn = create_actor 4? #COP in_car $mycopget driverseat
01ED: spawn_actor $copspawn

devil.gif BUT THE f*ckIN PROBLEM STILL EXISTS! is there any damn solution?
I'm angry.gif very f*ckin' angry with this sh*t. (sorry for the rude words inlove.gif , i am very upset angry.gif )

Y_Less
  • Y_Less

    629

  • Members
  • Joined: 14 Mar 2004

#20

Posted 22 November 2005 - 07:14 PM

QUOTE (Drakos @ Nov 21 2005, 19:59)
I tried this:

:Labelmycop1
014B: $mycopget = init_parked_car_generator #POLICE -1? 1? 0? alarm 0? door_lock 0? 0? 10000& at 391.479! -746.4341! 10.6! angle -116.00!
014C: set_parked_car_generator $mycopget cars_to_generate_to 101?
0247: request_model #COP
038B: load_requested_models

:Labelmycop2
0129: $copspawn = create_actor 4? #COP in_car $mycopget driverseat
01ED: spawn_actor $copspawn

devil.gif BUT THE f*ckIN PROBLEM STILL EXISTS! is there any damn solution?
I'm angry.gif very f*ckin' angry with this sh*t. (sorry for the rude words inlove.gif , i am very upset angry.gif )

You are using a parked car generator, if you want to do something like this you will need to spawn a car instead.

Currently $mycopget is referring to the GENERATOR not the CAR, so you are telling the cop to get into a car generator, not a car.

Finally, you also need to check the models are loaded:

CODE
:mycop010
0247: request_model #COP
0247: request_model #POLICE
038B: load_requested_models

:mycop011
0001: wait 0? ms
00D6: if 1?
0248:   model #COP available
0248:   model #POLICE available
004D: jump_if_false ££mycop011
00A5: $mycopget = create_car #POLICE at 391.479! -746.4341! 10.6!
0129: $copspawn = create_actor  4? #COP in_car  $mycopget driverseat
0249: release_model #COP
0249: release_model #POLICE


That *should* work, but I'm actually a little rusty on coding.


Drakos
  • Drakos

    Square Civilian

  • Members
  • Joined: 28 Jul 2005

#21

Posted 24 November 2005 - 06:15 PM

I'll try that

Drakos
  • Drakos

    Square Civilian

  • Members
  • Joined: 28 Jul 2005

#22

Posted 25 November 2005 - 12:52 PM

I tried it. now the game doesn't crash, but the police car doesn't spawn, neither does the cop. what's wrong? suicidal.gif suicidal.gif suicidal.gif

Y_Less
  • Y_Less

    629

  • Members
  • Joined: 14 Mar 2004

#23

Posted 02 December 2005 - 06:04 PM

Are you running the thread?

Drakos
  • Drakos

    Square Civilian

  • Members
  • Joined: 28 Jul 2005

#24

Posted 02 December 2005 - 07:02 PM

What do you mean by "am I running the thread"?

wauzie
  • wauzie

    GTI + MI

  • Members
  • Joined: 12 Mar 2005

#25

Posted 02 December 2005 - 08:04 PM

Does GTA read your thread, does some label jump to your thread, or have you created a create_thread code. GTA has to read your labels to use the code inside them.

Drakos
  • Drakos

    Square Civilian

  • Members
  • Joined: 28 Jul 2005

#26

Posted 11 December 2005 - 03:22 PM

Oh, i didn't check that...

Drakos
  • Drakos

    Square Civilian

  • Members
  • Joined: 28 Jul 2005

#27

Posted 28 December 2005 - 03:32 PM

the code consists of 2 labels, they are in the start of mission 1. the 1st thread can be read and at the end of the 1stlabel i put a jump to the code second label but the game crashes/ It looked something like this:


Mission 1

...........................
.........................
.........................
Jump_label_********

Label*******
........................
........................


Grant
  • Grant

    Back from the dead

  • Members
  • Joined: 12 Apr 2006

#28

Posted 18 October 2006 - 10:49 PM

Thanks for the tutorial. Helps me ALOT, i only needed to change some spawn points to get my mod rolling, thanks again. :wub:

Grant

Cousin ED
  • Cousin ED

    Player Hater

  • Members
  • Joined: 18 Jan 2007

#29

Posted 18 January 2007 - 07:42 PM

thanks for the tut, i understand how to use jumps and ifs now(i didnt used them til now, but it comes), but i got one left question: how can i make a garage with the same doors like PatrickW used on his Marina Carpark? i already got the garage coords and the mission for the house it belongs to, but when i put a car into it and save, it's away suicidal.gif ... i need that damn garage to work or i'll be execute!

Jusser
  • Jusser

    Player Hater

  • Members
  • Joined: 06 Jun 2008

#30

Posted 08 August 2008 - 10:20 AM

i don't know if anyone will read this.. but:

i want something that if you start a new game you completed all missions and you bought all buildings..
and maybe you spawn somewhere at the mansion as well..

i've searched very long but didn't really found anything, well, i did..
but like the all opened up mod you get more missions and other buyable buildings,
i just want that if i start a new game i completed whole vice city..

could someone help me? confused.gif




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users