Code Snippets

Anything to do with GTA1/GTA2 modding (tools, scripts and more).
User avatar
Sektor
Boss
Boss
Posts: 1387
Joined: 04 Mar 2008, 06:51
GH nick: Sektor
Location: GTAMP.com
Contact:

Re: Code Snippets

Post by Sektor »

[mis]//Electro Punch
PLAYER_PED p1 = ( 149.0 , 195.0 , 255.0 ) 22 0

COUNTER loop = 1
COUNTER punched
CHAR_DATA special

LEVELSTART

DECLARE_POLICELEVEL ( 6 )

WHILE_EXEC ( loop = 1 )

IF ( HAS_CHAR_PUNCHED_SOMEONE ( p1 ) )
STORE_LAST_CHAR_PUNCHED ( p1 , punched )
SET special = ( punched + 8 )
// this electrocutes the punched player instead of making them invincible because it is 8 bytes higher than the command expected
SET_CHAR_INVINCIBLE ( special , ON )
ENDIF

ENDWHILE

LEVELEND
[/mis]

User avatar
roarke
Mugger
Mugger
Posts: 16
Joined: 09 Dec 2013, 12:08
GH nick: Roarke
Location: Romania
Contact:

Re: Code Snippets

Post by roarke »

I don't understand how to use the snippets.
1. It will work in single player, or only in multiplayer ?
2. For one mission/map or for many ?
3. Booth players or more, must have the same snippet ?
4. The script (snippet) what name must have for .mis file ? Because how the game know how the file name lol.mis (an random name) will make the connection with the map game ?
Create your basic script as a textfile using any text editor.
Give it a name such as "text.mis" - all raw scripts must have a .mis extension
Compile the mis file using the Miss2.exe compiler program.
This will generate a .tmp file, a .txt file & a .scr file of your raw script.
Once successfully compiled, copy the resulting .scr file into the …/gta2/data/ folder on your harddrive.

Code: Select all

http://projectcerbera.com/gta/2/tutorials/scripting

User avatar
Sektor
Boss
Boss
Posts: 1387
Joined: 04 Mar 2008, 06:51
GH nick: Sektor
Location: GTAMP.com
Contact:

Re: Code Snippets

Post by Sektor »

roarke wrote:I don't understand how to use the snippets.
1. It will work in single player, or only in multiplayer ?
Both but they might need to be modified. It depends on the code.
roarke wrote: 2. For one mission/map or for many ?
Code needs to added to every SCR file that you want to use it in.
roarke wrote: 3. Both players or more, must have the same snippet ?
Everyone needs the same files. MIS files are ignored by GTA2, it needs the compiled version with SCR extension.
roarke wrote: 4. The script (snippet) what name must have for .mis file ? Because how the game know how the file name lol.mis (an random name) will make the connection with the map game ?
You can either edit gta2\data\test1.seq in notepad to point to the SCR file of your choice or the better way is to make an MMP file (this can support 1 to 6 players) and has to be launched from the GTA2 network create game screen.

User avatar
roarke
Mugger
Mugger
Posts: 16
Joined: 09 Dec 2013, 12:08
GH nick: Roarke
Location: Romania
Contact:

Re: Code Snippets

Post by roarke »

Thank you for the value of the reply.

Rick
Car Jacker
Car Jacker
Posts: 33
Joined: 29 Jan 2012, 18:56
GH nick: Sequential

Flashing Lights

Post by Rick »

For those detail lovers like me:
It´s a known bug that using flashing lights in your map causes desync.
So mappers could not use them in multiplayer maps.
:idea: Here´s how it works without getting out of sync:

We are using the script to create a light (must not be placed in the map file!) and simply change the intensity in a while loop.

This is a simple one using a straight / linear flashing:

[syntax=mis]COUNTER loop = 1 //number that runs the WhileLoop
COUNTER cyclecounter //every cycle +1, then set to zero when some favoured value is reached
LIGHT flashing_light = (100.5, 100.5, 2.02) 1.1 0 (255, 255, 111) 0 0 0

LEVELSTART

WHILE_EXEC ( loop = 1 )


IF (cyclecounter > 128)
SET cyclecounter = 1
ENDIF

//changing the intensity of the light

IF (cyclecounter > 0)
CHANGE_INTENSITY (flashing_light, 45) //intensity = 45 (glows a bit)
ENDIF
IF (cyclecounter > 64)
CHANGE_INTENSITY (flashing_light, 255) //intensity = 255 (full shining)
ENDIF

++cyclecounter
ENDWHILE //end of whileloop with value = 1

LEVELEND[/syntax]

This one is a little more complex, using different intensities and a "pseudo-random" flashing. Actually it´s a sequence.

[syntax=mis]COUNTER loop = 1 //number that runs the WhileLoop
COUNTER cyclecounter //every cycle +1, then set to zero when some favoured value is reached
LIGHT broken_light = (100.5, 100.5, 2.02) 1.1 0 (255, 255, 111) 0 0 0

LEVELSTART

WHILE_EXEC ( loop = 1 )


IF (cyclecounter > 2500)
SET cyclecounter = (cyclecounter - 2500)
ENDIF


//changing the intensity of the light

IF (cyclecounter > 480)
CHANGE_INTENSITY (broken_light, 0)
IF (cyclecounter = 481)
SET cyclecounter = (cyclecounter - 50)
ENDIF
IF (cyclecounter > 540)
CHANGE_INTENSITY (broken_light, 80)
ENDIF
IF (cyclecounter > 720)
CHANGE_INTENSITY (broken_light, 0)
IF (cyclecounter = 721)
SET cyclecounter = (cyclecounter - 200)
ENDIF
ENDIF
IF (cyclecounter > 1080)
CHANGE_INTENSITY (broken_light, 200)
ENDIF
IF (cyclecounter > 1500)
CHANGE_INTENSITY (broken_light, 0)
ENDIF
IF (cyclecounter > 1920)
CHANGE_INTENSITY (broken_light, 255)
ENDIF
IF (cyclecounter = 1923)
SET cyclecounter = (cyclecounter - 200)
ENDIF
IF (cyclecounter > 2200)
CHANGE_INTENSITY (broken_light, 0)
IF (cyclecounter = 2202)
SET cyclecounter = (cyclecounter + 200)
ENDIF
IF (cyclecounter = 2203)
SET cyclecounter = (cyclecounter + 200)
ENDIF
ENDIF
IF (cyclecounter > 2250)
CHANGE_INTENSITY (broken_light, 170)
ENDIF
IF (cyclecounter > 2280)
CHANGE_INTENSITY (broken_light, 0)
ENDIF

SET cyclecounter = (cyclecounter + 3)
ENDWHILE //end of whileloop with value = 1

LEVELEND[/syntax]

It´s probably better to use a randomization script you can find in this topic.
I am still wondering how to generate coincidences just by mathmatic operations.
Please tell me if something doesn´t work here. I modified it for the topic and did not test exactly THIS script.

Jones
Psycho
Psycho
Posts: 51
Joined: 08 Aug 2012, 21:25

Re: Code Snippets

Post by Jones »

Zombieees :) Makes every pedestrian on map running after your brain
Image
[mis]//Find new ped
IF(ped=0)
SET in = ( p1 + charpointer ) //all characters are stored after player 1

SET in = (in+360) // read sprite address of character
CHANGE_GANG_CHAR_RESPECT (in,out,104)

IF(NOT(out=0)) // check if sprite is existent, therefore character is walking around
SET ped= (p1 + charpointer) // store character in ped
ENDIF

SET charpointer = ( charpointer + 660 ) //adavance to next character address
IF ( charpointer > 32340 ) // 49 x 660 (each character has a struct of 660 bytes)
SET charpointer = 3960 // If you don't want to kill player 2-6, set to 3960 ( 6 x 660 )
ENDIF //charpointer > 32340
ENDIF

//set ped to null if character has died
IF((NOT(CHECK_CHARACTER_HEALTH(ped,0))) OR (HAS_CHARACTER_DIED(ped)))
SET ped=0
ENDIF

//if ped is alive
IF(NOT(ped = 0))
SET_CHAR_GRAPHIC_TYPE ( ped , DUMMY_GRAPHIC , 24 )
SET_CHAR_OBJECTIVE ( ped ,KILL_CHAR_ANY_MEANS , p1 )
SET ped=0

ENDIF[/mis]
See this thread for a similar complete script.

User avatar
T.M.
Immortal
Posts: 957
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: Code Snippets

Post by T.M. »

I love these hacks with pointers :D

Is there full "manual" for those pointer tricks yet? Would be nice to create some tool to generate the necessary pointer tricks for different things.
IF ( charpointer > 32340 ) // 10 x 660 (each character has a struct of 660 bytes)
That is interesting. What is the magic number 32340 ? How did you calculate it? To my knowledge, 10*660 = 6600.

Also, have you guys figured out the struct structure that is 660 bytes in size? 660 bytes sounds very large for a character struct. Would be interesting to know what it contains.

Jones
Psycho
Psycho
Posts: 51
Joined: 08 Aug 2012, 21:25

Re: Code Snippets

Post by Jones »

IF ( charpointer > 32340 ) // 10 x 660 (each character has a struct of 660 bytes)
That is interesting. What is the magic number 32340 ? How did you calculate it? To my knowledge, 10*660 = 6600.
I took those numbers from Sektor, I think 32340 is the highest multiple of 660 you represent with a COUNTER. In an older script he used 6600 like the comment says.
Also, have you guys figured out the struct structure that is 660 bytes in size? 660 bytes sounds very large for a character struct. Would be interesting to know what it contains.
See GTA2 memory addresses for some hints about the struct and that thread for some history :)

User avatar
Sektor
Boss
Boss
Posts: 1387
Joined: 04 Mar 2008, 06:51
GH nick: Sektor
Location: GTAMP.com
Contact:

Re: Code Snippets

Post by Sektor »

Yeah 10 x 660 was just an outdated comment in some old code but that code has spread around a bit with no one fixing it, so I went and changed it to 49 x 660. I don't think 49 was any magic number, I just figured 50 (1 player + 49 dummies) should be enough to control most of the peds. I'd prefer to set it to the exact number of peds that currently exist.

Jones
Psycho
Psycho
Posts: 51
Joined: 08 Aug 2012, 21:25

Re: Code Snippets

Post by Jones »

This shows a brief message only visible to a specific player:
[mis]
COUNTER static = 6206716
COUNTER myPlayer=0
COUNTER mainloop=1

LEVELSTART
SET in = (static+0)
CHANGE_GANG_CHAR_RESPECT (in,out,104)
SET in = (out+36)
CHANGE_GANG_CHAR_RESPECT (in,myPlayer,101)

WHILE_EXEC ( mainloop = 1 )

IF(myPlayer=1) //if me is player 2 (player 1 is 0)
DISPLAY_BRIEF ( 8001 )
ENDIF

IF(myPlayer=3) //if me is player 4 show another message
DISPLAY_BRIEF ( 8002)
ENDIF

ENDWHILE
LEVELEND
[/mis]

User avatar
Sektor
Boss
Boss
Posts: 1387
Joined: 04 Mar 2008, 06:51
GH nick: Sektor
Location: GTAMP.com
Contact:

Re: Code Snippets

Post by Sektor »

Nice. That should be useful. You could also use it for arrows. If you did something stupid like KILL_CHAR then it would go out of sync but that's to be expected.

Post Reply