Quantcast

Jump to content

» «
Photo

[CLEO]Some Tutorials...

3 replies to this topic
Deji
  • Deji

    Coding like a Rockstar!

  • Feroci Racing
  • Joined: 24 Dec 2007
  • None

#1

Posted 25 June 2009 - 08:40 PM

Since so many people have been helping me lately (thanks biggrin.gif ) I thought I'd do something to help others... Here are some tutorials I made AGES ago but never had a chance to post here...


Making Panels

This is one of the things I hate doing most when it comes to coding. It's annoying and requires wayy too much coding for the simple thing it does. This is useful for making menus in which people can choose things...

The way I'm going to be teaching is only a fraction of what you can do with panels, but hopefully you will experiment with what I've taught you and learn how to do things for yourself.


Firstly, we need to create the panel...

08D4: 0@ = create_panel_with_title 'MYPAN' position 29.0 170.0 width 180.0 columns 1 interactive 1 background 1 alignment 0

0@ is the variable where the panel is stored and can be accessed by. You should already know about the basics of variables.

title 'MYPAN' is the text that appears at the top in the San Andreas font. Don't be confused into thinking that the text will be "MYPAN" in-game. 'MYPAN' is simply the entry name in the gxt file. You should already know about using gxt.

position 29.0 170.0 is the location of the panel. No, this is not coordinates. It's the location on the screen which is why it only has X and Y axis'. You may need to experiment to get it in the right place on the screen.

width 180 is the width of the panel. The wider the panel, the more text you can put on without squashing it up. Although, too wide and it may cover up the screen.

columns 1 are the amount of columns. If you don't know what a column is... Go to school!

interactive 1 whether the user can interact with the column... 1 = on, 0 = off. If off, then the user cannot select rows.

background 1 whether the panel should have a semi-transparent black background. 1 = on, 0 = off.

alignment 0 whether the panel is left, right or center aligned.


Now you'd have a panel with some stylish text at the top and nothing else on it. So let's put some stuff on it!


08DB: set_panel 0@ column 0 header '50' data '1' '2' '3' '4' '5' '6' '7' '8' '9' '0' '11' 'DUMMY'

[0@] is the panel we're effecting...

[column 0] is which column we're changing the rows of.

[header '50'] is the gxt of a header. This looks rather ugly though, I recommend using it if you want to add notes about the panel.

[data '1' '2' ect.] Are the rows. You MUST NOT delete any strings (' ') or the game will not like you. Instead just change any you don't want to 'DUMMY'.

Again, header and data strings (' ') are the gxt entries of each row. '1' would be the top row... 'DUMMY' is the bottom. 'DUMMY' is nothing... It not only displays no text, but disables the whole row.

You can user 1number gxts using 08EE to do each row one at a time. It's a bit more tedious but managable.

Now you'll have a panel with text! You can press up and down to select the rows. But one problem... Nothing happens when you try to exit (Enter) or select (Sprint)!



Randomization Tutorial


Here's a lil tutorial on ways to make something random.

There are 3 ways to do this. The first way is to use a jump table like this...

0871: init_jump_table $VIDEO_GAME total_jumps 8 default_jump 0 @MAIN_5502 jumps 0 @MAIN_5335 1 @MAIN_5353 2 @MAIN_5371 3 @MAIN_5389 4 @MAIN_5407 5 @MAIN_5425 6 @MAIN_5443

0872: jump_table_jumps 7 @MAIN_5461 -1 @MAIN_5502 -1 @MAIN_5502 -1 @MAIN_5502 -1 @MAIN_5502 -1 @MAIN_5502 -1 @MAIN_5502 -1 @MAIN_5502 -1 @MAIN_5502

I'm not familliar with this and could use some confirmations or extra info from someone who knows more about it but I think it would work in a pretty simple way.

The global variable; $VIDEO_GAME would have a pre-defined value. If the value was 2, then it'd jump to :XX_XX - This is just my idea. It's probably totally wrong so ignore it.


The second way is my favourite. All you have to do is use this opcode...

0209: 17@ = random_int_in_ranges 0 10

The variable is where the random number is stored and the random number is between the 1st number and the second number.

So, let's break the parameters down and explain a bit more...

17@ is the variable to store the number.
0 is the first integer (number). This is the lowest possible answer for the random number to be.
10 is the second int (number). This is the highest possible answer for the random number to be.


Now for an example:

0209: 5@ = random_int_in_ranges 150 165

Here the random number could be anything between 150 and 165.

The number could be... 150,151,152,153,154 ect. all the way to 164, 165...

Any one of those numbers will be stored in a variable which means it'll be remembered by the game via that chunk of space... Best way I can describe it, really...

So, 5@ is our chunk of space (variable). That is where our number is stored.

We can ask the game what the number is in the same way that you usually might with 0039. So lets see a larger example of using the random_int.

:MYTHREAD
wait 1000
0209: 5@ = random_int_in_ranges 150 165
if
0039: 5@ == 154
else_jump @MYTHREAD
jump @MYTHREAD1

:MYTHREAD1
02A3: enable_widescreen 1
jump @MYTHREAD

Here we have a random number being created in a loop running every second meaning that we get 1 random number per sec. Once the random number is 154, widescreen mode is activated. If not, a random number will be made again after one second until it is 154.

Eventually, the widescreen will be activated. It could take a second, it could take a year (unlikely). It all depends on what random number is selected. Of course, there are more useful ways to use that opcode than what the example shows... You could use it for thread jumping or even simply getting random numbers to use. Imagine you wanted a level where the player had to press the number that appears on screen as fast as possible... You could define the numbers one by one... But then the player could memorize them making it easy work. With the beauty of the random int opcode, you can make it so it's a different number each time.


The third way is a little restricted. You can only use it for one type of thing. This way is very simillar to the second way.

Here it is...

0208: 90@ = random_float_from -1620.9921 _to_ -1642.4629

This is just like the random number/integer except with a float which means a decimal number.

To me, this just screams out "Coordinates!". It's perfect for randomization of locations. If you've been to ammunation on the shooting range, you'll see how on the third round... The target is created anywhere between the range. This is a great way to do just that!

I used it myself for a shooting range code in my Vigilante Justice Mod. It was great!

Here's a little sample (slightly edited) of my use of the code in Vigilante Justice...

0208: 1@ = random_float_from -1620.9921 _to_ -1642.4629
0107: 0@ = create_object #MYOBJECT at 1@ 648.2003 -5.2422

Here it gets a random float (decimal number) from -1620.9921 to -1642.4629. These coords are each side of one of the walls at SFPD underground. So, the object is created at the exact Y and Z axis. But the X axis has been randomized, so it'll spawn anywhere from the left to the right smile.gif

Again, I'll simplify that.

1@ is the result to the random float that is created.

The floats you should know by reading the second way.

0@ is the object. This is not relevant to this tutorial, ignore it.

#MYOBJECT See above. This is the object model.

1@ this is the X axis which travels from left to right in the PD compound. This is the only axis to change.

The other 2 floats are the Y and Z axis. They will stay the same, otherwise chances are that they will go off the screen. We dont want the object anywhere in San Andreas, do we? We only want it to be anywhere along the X axis.

It's very simple. Try testing it out. You might try making a system where the player has to run around to different markers and collect them. You dont have to leave out the Y and Z axis. Just set the right from - to values. Also, make sure that you dont make it possible for one of the axis' to f- things up. For example: You might put -100.0 as the from value of the z axis meaning people would have to fall through the floor to get there...



Using Timers


As you should know, 0@ - 31@ are local variables. 34@ - 999@ are local variables for use in missions. So what are 32@ and 33@? Well, these are timers. They are basically stopwatches that count in milliseconds.

32@ and 33@ are always going up. If you were to randomly ask the game what that number was, it'd be high. Very high, unless you've recently done a certain thing. That is because to make these timers count up from 0, they need resetting. Unlike what you'd expect... There is no start_timer command. Well, there is... But that is for a totally different thing. Instead, we just use 0006...

0006: 32@ = 0

Thats it! It's that simple. We can put it to anything else we want too... Such as 1000 meaning it will start from 1 sec instead of 0 secs.

Now that you've set it to 0 it will be counting up automatically. So after 4 seconds, the timer will be 4000 regardless of what the code is doing or what it isn't. The timers are just automatic. They are hard-coded to count up forever.

Now, one could try using the 0039 opcode to test if it has reached a certain amount... But that would be risky as if the timer went above that without the code checking in time, it'd never count the check as true.

The correct opcode to use is 0019...

0019: 32@ > 5000

The above would test if the timer is higher than 5000 (5 seconds).

That's basically it! It's simple but very useful. Unlike the wait's... The code can carry on while the timer is counting meaning you can loop a text draw and fade after 5 seconds properly without using waits which would make the text either flash or not appear.



N'joy.

PatrickW
  • PatrickW

    GTA Juggernaut

  • Inactive Staff
  • Joined: 07 Jan 2004
  • Netherlands
  • Best Script 2013 [DYOM]
    Best Script 2012 [DYOM]

#2

Posted 26 June 2009 - 09:30 AM

Tutorials belong in the tutorial section, moved.

I advise to use some more bb-codes to make it more readable (like [ code][/ code] ).

Deji
  • Deji

    Coding like a Rockstar!

  • Feroci Racing
  • Joined: 24 Dec 2007
  • None

#3

Posted 26 June 2009 - 11:25 AM

QUOTE (PatrickW @ Jun 26 2009, 09:30)
Tutorials belong in the tutorial section, moved.

I advise to use some more bb-codes to make it more readable (like [ code][/ code] ).

Couldn't be bothered tounge2.gif I don't really use BB code much. Plus, I made all these in notepad and just pasted them in. Can't even be bothered to read them to check they say the right things xO

I'm lazy, yeah.

wangxiulin
  • wangxiulin

    f*ck you

  • Members
  • Joined: 02 May 2011

#4

Posted 03 June 2011 - 12:26 PM

good...very good lol.gif rampage_ani.gif whatsthat.gif




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users