Code Snippets

Anything to do with GTA1/GTA2 modding (tools, scripts and more).
Shazdeh
Psycho
Psycho
Posts: 60
Joined: 29 Jul 2009, 20:22
GH nick: Dont_have_yet

Code Snippets

Post by Shazdeh » 26 May 2010, 10:33

One script for one post, add full description please.

I love code snippets. It makes developing process easier. GTA2 scripting is not a hard task at all, the script is self-documented. But sometimes I see codes that are interesting, have something in them that I haven't seen before. It's a good idea to share these.

Kill people by punching them:
[syntax=mis]IF (CHECK_CHARACTER_HEALTH(p1, 0))
IF ( HAS_CHAR_PUNCHED_SOMEONE ( p1 ))
STORE_LAST_CHAR_PUNCHED ( p1 , p1punched )
KILL_CHAR ( p1punched )
ENDIF
ENDIF[/syntax]


Please post any worthy code snippet.
Happy coding!

User avatar
Gustavob
Immortal
Posts: 407
Joined: 18 May 2009, 21:40
GH nick: Gustavob
|Gustavob|
Location: Nowhere.
Contact:

Re: Code Snippets

Post by Gustavob » 26 May 2010, 15:51

No Cops:

Code: Select all

DECLARE_POLICELEVEL ( 0 )
MAP_ZONE map = ( 1000 , 600, 300 , 0 , 1000 , 20 , 20 , 200, 0 , 000 , 0 )
That will set maximum wanted level to zero and remove all cops and cop cars from the map (only setting max wanted to 0 will still let cops drive and walk around and you may still get a wanted level when a cop sees you doing something wrong, though it will disappear quicker than normal)
You just lost the game.

User avatar
Pyro
Immortal
Posts: 414
Joined: 17 Mar 2010, 04:07
GH nick: Pyro
Location: Wales, UK

Re: Code Snippets

Post by Pyro » 26 May 2010, 16:16

Useful little thing to add delays while inside a WHILE_EXEC or WHILE loop (by default they are skipped if they are inside these code bits), useful if you want timed explosions etc while still having proper IF functions...

Proper Delaying in WHILE/WHILE_EXEC Loops

Put this before LEVELSTART...

Code: Select all

wait_short:
DELAY_HERE ( 30 )
RETURN
Extremely short bit of code. The "wait_short:" is the label name (you must include the colon at the end of the name!) and then put anything you like inbetween the label name and the "RETURN". Adjust your "DELAY_HERE" count to whatever you need (30 "game ticks" is 1 second real time).

When you are ready to use it in your script simply do this...

Code: Select all

GOSUB wait_short:
Throw that in wherever you like, again, don't forget the colon at the end of the label name! 8-)

Razor
Lunatic
Lunatic
Posts: 453
Joined: 19 Jul 2008, 14:14
GH nick: Razor, R
Location: Poland / Szczecin
Contact:

Re: Code Snippets

Post by Razor » 26 May 2010, 16:55

Remote Mini Deadly Cars:
Allow each player to remotly drive a minicar with vechicleguns (or whatever) once per death. That service costs X$ ofcourse. Please test that script... I didn`t check it yet.

Code: Select all

PLAYER_PED playerx = (X.x , Y.y , Z.0) remap  angle // first spawn of that player also his remap and angle
CHAR_DATA uniquenamex 
COUNTER loop = 1 // basic loop
COUNTER playerxdeath = 1 // player x death counter
LEVELSTART 
WHILE_EXEC ( loop = 1 )
IF (CHECK_CHARACTER_HEALTH(playerx, 0)) // checks whether the player is in game
IF (playerxdeath = 1) // checks whether the player died before
IF (LOCATE_CHARACTER_ANY_MEANS ( playerx  ,  X.x  , Y.y , Z.0  , width , height )) // place in which the player must be by car or foot (you can change ANY_MEANS to BY_FOOT or BY_CAR - but check it I don`t rly rememer )
IF (CHECK_SCORE_GREATER (playerx, cash)) // Checks player`s score
ADD_SCORE (playerx, -cash) // takes player`s
uniquenamex = CREATE_CAR ( X.x , Y.y , Z.0 ) remap angle cartype MINI_CAR END // Creates mini car in specific place. Also declares car`s remap and angle and type. If you want to have remote car (not mini) so you have to remove MINI_CAR
GIVE_WEAPON (uniquenamex , wepontype, ammount) // gives car weapon to your car
TAKE_REMOTE_CONTROL_OF_CAR (playerx, uniquenamex) // gives you power to remotly control car
SET playerxdeath = 0
ENDIF
ENDIF
ENDIF
ENDIF
IF ( HAS_CHARACTER_DIED (playerx ) ) // check whether the player has died
DELETE_ITEM ( p1g ) // if he did it script sets couter to 1
SET playerxdeath = 1
ENDIF
ENDWHILE
LEVELEND
And example:

Code: Select all

PLAYER_PED p1 = (176.5 , 147.5 , 2.0) 10  0
CAR_DATA remdem1
COUNTER loop = 1
COUNTER p1d = 0
LEVELSTART 
WHILE_EXEC ( loop = 1 )
IF (CHECK_CHARACTER_HEALTH(p1, 0)) 
IF (p1d = 1)
IF (LOCATE_CHARACTER_ANY_MEANS ( p1  ,  197.5  , 203.5 , 2.0  , 1.0 , 1.0 ))
IF (CHECK_SCORE_GREATER (p1, 5999))
ADD_SCORE (p1, -6000)
remdem1 = CREATE_CAR ( 169.5 , 155.5 , 2.0 ) 2 180 ISETTA MINI_CAR END
GIVE_WEAPON (remdem1, CAR_MACHINE_GUN, 50)
TAKE_REMOTE_CONTROL_OF_CAR (p1, remdem1)
SET p1d = 0
ENDIF
ENDIF
ENDIF
ENDIF
IF ( HAS_CHARACTER_DIED ( p1 ) )
SET p1d = 1
ENDIF
ENDWHILE
LEVELEND

Razor
Lunatic
Lunatic
Posts: 453
Joined: 19 Jul 2008, 14:14
GH nick: Razor, R
Location: Poland / Szczecin
Contact:

Re: Code Snippets

Post by Razor » 26 May 2010, 17:03

Shazdeh wrote:Do something with cars that player gets in:

Code: Select all

IF (CHECK_CHARACTER_HEALTH(p1, 0))
	IF (IS_CHARACTER_IN_ANY_CAR  ( p1  ) )
		STORE_CAR_CHARACTER_IS_IN ( p1  ,  bum1  ) 
		// do something with bum1. like: EXPLODE_SMALL (bum1)
	ENDIF
ENDIF

Shazdeh
Psycho
Psycho
Posts: 60
Joined: 29 Jul 2009, 20:22
GH nick: Dont_have_yet

Re: Code Snippets

Post by Shazdeh » 26 May 2010, 20:54

No Cops, the other method:
It doesn't removes the cops or cop cars, they simply ignore the player.
Use this inside the loop.

Code: Select all

IF (CHECK_HEADS_GREATER(p1, 0) )
	CLEAR_WANTED_LEVEL(p1)
ENDIF

User avatar
Pyro
Immortal
Posts: 414
Joined: 17 Mar 2010, 04:07
GH nick: Pyro
Location: Wales, UK

Re: Code Snippets

Post by Pyro » 27 May 2010, 17:20

Player passengers in cars...

Put inside WHILE/WHILE_EXEC loop... this constantly updates whatever car the player is in and saves it for future use and then checks to see if player 2 is holding an electro baton while player 1 is pressing the car horn. If both are true then orders player 2 to the back door of player 1's current car. This will stop if player 2 switches weapons and/or player 1 stops pressing the horn. Set up multiple ones for different players and you you can have multiple players as passengers!

Code: Select all

STORE_CAR_CHARACTER_IS_IN ( p1 , p1_current_car )

IF ( ( CHECK_CHAR_CURR_WEAPON ( p2 , ELECTRO_BATON ) )
AND ( IS_CHAR_PRESSING_HORN ( p1 ) ) )
SET_CHAR_OBJECTIVE ( p2 , ENTER_CAR_AS_PASSENGER , p1_current_car )
ENDIF
Edit: Don't forget you need a CAR_DATA command elsewhere to use this! In this case it'd be "CAR_DATA p1_current_car".
Last edited by Pyro on 27 May 2010, 22:09, edited 1 time in total.

Shazdeh
Psycho
Psycho
Posts: 60
Joined: 29 Jul 2009, 20:22
GH nick: Dont_have_yet

Suicide!

Post by Shazdeh » 10 Jun 2010, 11:37

Suicide!
Your dummy bot gets in a car and will explode itself when it gets to the player. This snippet has been taken from Harbor Town.
Use this inside 'the loop'.

Code: Select all

IF ( LOCATE_ANOTHER_CHARACTER_BY_CAR ( Bot1 , Player1 , 2.0 , 2.0 ) )
IF ( NOT ( HAS_CHARACTER_DIED ( Bot1 ) ) )
EXPLODE_LARGE ( Bot1 )
ENDIF
ENDIF

Shazdeh
Psycho
Psycho
Posts: 60
Joined: 29 Jul 2009, 20:22
GH nick: Dont_have_yet

Make NPC's use car weapons

Post by Shazdeh » 10 Jun 2010, 11:41

Make NPC's use car weapons (Tanks, FireTrucks, Jeeps, ...)

Code: Select all

SET_CHAR_TO_USE_CAR_WEAPON ( x , ON )
SET_FAVOURITE_MODEL ( x, GUNJEEP )
x is the NPC's name.

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

Re: Code Snippets

Post by Sektor » 12 Jun 2010, 12:55

A boss ped that takes 3 rocket hits to kill:

[mis]// bil.sty bil.gmp bossman.scr

PLAYER_PED player = (49.5, 46.5, 5.0) 1 0
PARKED_CAR_DATA player_car = (52.5, 46.5, 5.0) 0 0 GT24640
CHAR_DATA bossman = ( 50.5 , 46.5 , 5.0 ) 0 180 MUGGER

COUNTER true = 1
COUNTER bosslife = 3 // bossman needs to be hit this number of times to die

LEVELSTART

WHILE ( true = 1 ) // the basic loop

SET_CHAR_GRAPHIC_TYPE (player, DUMMY_GRAPHIC , 26)
GIVE_WEAPON ( player_car, CAR_MINE )
SET_CHAR_INVINCIBLE ( bossman , ON )
SET_CHAR_INVINCIBLE ( player , ON )
GIVE_WEAPON ( player , ROCKET_LAUNCHER )

//checks if bossman is hit with a rocket
IF ( CHECK_WEAPON_TYPE_HIT_CHAR ( bossman , BY_ROCKET_LAUNCHER ))
ADD_SCORE ( player , 1 )
--bosslife
ENDIF

IF ( bosslife < 1 )
KILL_CHAR ( bossman)
SET bosslife = 3
ENDIF

ENDWHILE // basic loop

LEVELEND

/*
Damage Types
BY_EXPLOSION
BY_DROWNING
BY_PUNCH
BY_GUN
BY_CAR_BOMB
BY_FIRE
BY_FLAMETHROWER
BY_GRENADE
BY_MOLOTOV
BY_ROCKET_LAUNCHER
BY_ELECTRO_WEAPON
BY_SHOTGUN
BY_WATER_CANNON
BY_ANY_WEAPON
BY_ANY_FOOT_WEAPON
*/[/mis]
You could create a boss that can only be killed by water cannon, some kind of super villain with a weakness. Electrogun will always kill so you'd have to remove that.

User avatar
Pyro
Immortal
Posts: 414
Joined: 17 Mar 2010, 04:07
GH nick: Pyro
Location: Wales, UK

Re: Code Snippets

Post by Pyro » 23 Jun 2010, 16:41

Scripted Instant-Gang

This code let's you have a custom instant gang that will also replace the missing members if they are dead. This example is done by using a phone but can be changed to whatever you like, and also you can add more members if needs be.

[mis]CHAR_DATA p1_group_member01
CHAR_DATA p1_group_member02
OBJ_DATA phone_1 = ( 191.7 , 51.5 , 255.0 ) 000 PHONE

COUNTER loop = 1
COUNTER p1_group_member01_died = 1
COUNTER p1_group_member02_died = 1

FORWARD p1_group:

THREAD_TRIGGER thr_p1_group = THREAD_WAIT_FOR_ANSWER_PHONE(p1, phone_1, p1_group:)
p1_group:
// 1st Inmate:
IF (p1_group_member01_died = 1)
SET p1_group_member01_died = 0
p1_group_member01 = CREATE_CHAR (188.3,51.2,255.0) 2 180 CRIMINAL END
ADD_EXISTING_CHAR_TO_GROUP(p1, p1_group_member01)
GIVE_WEAPON (p1_group_member01, PISTOL)
ENDIF
// 2nd Inmate:
IF (p1_group_member02_died = 1)
SET p1_group_member02_died = 0
p1_group_member02 = CREATE_CHAR (188.5,51.8,255.0) 2 180 CRIMINAL END
ADD_EXISTING_CHAR_TO_GROUP (p1, p1_group_member02)
GIVE_WEAPON (p1_group_member02, PISTOL)
ENDIF
RETURN

LEVELSTART

ADD_GROUP_TO_CHARACTER(p1, 0)

WHILE_EXEC (loop = 1)
// Inmate Gang Death Check:
IF ( HAS_CHARACTER_DIED(p1_group_member01) )
SET p1_group_member01_died = 1
ENDIF
IF ( HAS_CHARACTER_DIED(p1_group_member02) )
SET p1_group_member02_died = 1
ENDIF
ENDWHILE

LEVELEND[/mis]

Original code by myself with modifications by Ben 8-)

(This is released as unstable until we have a fix - it will currently not work properly if you die and answer the phone again)

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

Re: Code Snippets

Post by Sektor » 04 Aug 2010, 12:06

Create 16 bots that try to kill player1:

[mis]
PLAYER_PED player1 = (90.0, 93.5, 255.0) 10 0
counter bots = 0
counter loop = 1
char_data botgroup

LEVELSTART

botgroup = CREATE_CHAR ( 92.0 , 91.5 , 3.0 ) 7 90 CRIMINAL_TYPE1 END

WHILE_EXEC ( loop = 1 )

IF ( bots < 16 )
IF ( NOT ( delay (10) ))
++bots
botgroup = CREATE_CHAR ( 92.0 , 91.5 , 4.0 ) 7 90 CRIMINAL_TYPE1 END
SET_CHAR_GRAPHIC_TYPE ( botgroup , DUMMY_GRAPHIC , 26 )
GIVE_WEAPON ( botgroup , ROCKET_LAUNCHER )
SET_CHAR_BRAVERY_LEVEL ( botgroup , LOONY )
SET_CHAR_SHOOTING_SKILL ( botgroup , CRACK_SHOT )
SET_CHAR_THREAT_REACTION ( botgroup , NO_REACTION )
SET_CHAR_INVINCIBLE ( botgroup , ON )
SET_FAVOURITE_MODEL ( botgroup , GUNJEEP )
SET_CHAR_TO_USE_CAR_WEAPON ( botgroup , ON )
SET_CHAR_OBJECTIVE ( botgroup, KILL_CHAR_ANY_MEANS , player1 )
ENDIF
ENDIF

ENDWHILE

LEVELEND[/mis]
If you want them to drive cars then it becomes unstable with more than 16 bots but on foot you can have more than 70 bots after you. This script was quickly tested with bil.sty and bil.gmp. I haven't tested it multiplayer.

User avatar
elypter
Immortal
Posts: 1120
Joined: 26 Dec 2009, 23:53
GH nick: elypter

Re: Code Snippets

Post by elypter » 18 Aug 2010, 21:35

I think, like me, many of you have once tried this function:
SET_CAR_NO_COLLIDE ()
but did not see an effect.
It is used for the the car at the Residential start point.
This car cannot be pushed and can move shove even the heaviest vehicle away.

The trick: put it in the while loop

Code: Select all

PLAYER_PED p1 = ( 104.5, 100.7, 255.0 ) 10 0
PARKED_CAR_DATA car = (124.5, 131.5) 31 90 STRIPETB
COUNTER loop = 1

LEVELSTART
WHILE ( loop = 1 )

SET_CAR_NO_COLLIDE (car)

ENDWHILE
LEVELEND
yur sa'nok ngeyä

User avatar
elypter
Immortal
Posts: 1120
Joined: 26 Dec 2009, 23:53
GH nick: elypter

Re: Code Snippets

Post by elypter » 23 Aug 2010, 20:28

Army script:

the maximum wanted level is 6 and at the beginning and after death it is set to 4.

Code: Select all

// Players
PLAYER_PED p1 = (57.5, 129.5, 255.0) 10 0
PLAYER_PED p2 = (73.5, 120.5, 255.0) 13 90
PLAYER_PED p3 = (93.5, 114.5, 255.0) 7 270
PLAYER_PED p4 = (52.5, 111.5, 255.0) 11 0
PLAYER_PED p5 = (67.5, 114.5, 255.0) 9 90
PLAYER_PED p6 = (70.5, 131.5, 255.0) 0 270

COUNTER loop = 1
DECLARE_POLICELEVEL (6)


LEVELSTART

SET_AMBIENT_LEVEL (1.0, 0)

IF (CHECK_CHARACTER_HEALTH(p1, 0)) // dummy check to avoid crash
ALTER_WANTED_LEVEL  (  p1  ,  4  ) // SWAT
ENDIF

IF (CHECK_CHARACTER_HEALTH(p2, 0))
ALTER_WANTED_LEVEL  (  p2  ,  4  )
ENDIF
IF (CHECK_CHARACTER_HEALTH(p3, 0))
ALTER_WANTED_LEVEL  (  p3  ,  4  )
ENDIF
IF (CHECK_CHARACTER_HEALTH(p4, 0))
ALTER_WANTED_LEVEL  (  p4  ,  4  )
ENDIF
IF (CHECK_CHARACTER_HEALTH(p5, 0))
ALTER_WANTED_LEVEL  (  p5  ,  4  )
ENDIF
IF (CHECK_CHARACTER_HEALTH(p6, 0))
ALTER_WANTED_LEVEL  (  p6  ,  4  )
ENDIF

WHILE ( loop = 1 )

IF (HAS_CHARACTER_DIED(p1))
DELAY_HERE ( 150 ) //needed to get wanted level reliably
ALTER_WANTED_LEVEL (p1, 4) //SWAT
ENDIF

IF (HAS_CHARACTER_DIED(p2))
DELAY_HERE ( 150 )
ALTER_WANTED_LEVEL (p2, 4)
ENDIF
IF (HAS_CHARACTER_DIED(p3))
DELAY_HERE ( 150 )
ALTER_WANTED_LEVEL (p3, 4)
ENDIF
IF (HAS_CHARACTER_DIED(p4))
DELAY_HERE ( 150 )
ALTER_WANTED_LEVEL (p4, 4)
ENDIF
IF (HAS_CHARACTER_DIED(p5))
DELAY_HERE ( 150 )
ALTER_WANTED_LEVEL (p5, 4)
ENDIF
IF (HAS_CHARACTER_DIED(p6))
DELAY_HERE ( 150 )
ALTER_WANTED_LEVEL (p6, 4)
ENDIF

ENDWHILE

LEVELEND


yur sa'nok ngeyä

BenMillard
Immortal
Posts: 889
Joined: 16 May 2009, 06:14
GH nick: BenMillard
Location: London, UK
Contact:

Re: Code Snippets

Post by BenMillard » 11 Nov 2010, 23:27

All of the GTA2 radio station codes, with the locations found using TM's script decompiler which is available through his Epic Map Editor. Strangely missing krez though?

Code: Select all

// Radio Stations
// Downtown (wil.*)
RADIO_STATION rockstar = STATION_DOWNTOWN    (212.5,022.5)
RADIO_STATION futuro   = STATION_ZAIBATSU    (155.5,004.5)
RADIO_STATION funami   = STATION_YAKUZA      (247.5,027.5)
RADIO_STATION lithium  = STATION_LOONIE      (150.5,039.5)

// Residential (ste.*)
RADIO_STATION krez     = STATION_RESIDENTIAL (166.5,103.5)
RADIO_STATION futuro   = STATION_ZAIBATSU    (247.5,067.5)
RADIO_STATION rebel    = STATION_REDNECK     (041.5,048.5)
RADIO_STATION osmosis  = STATION_SCIENTIST   (211.5,229.5)

// Industrial (bil.*)
RADIO_STATION lofi     = STATION_INDUSTRIAL  (110.5,108.5)
RADIO_STATION heavenly = STATION_KRISHNA     (242.5,214.5)
RADIO_STATION kgbh     = STATION_RUSSIAN     (201.5,021.5)
RADIO_STATION futuro   = STATION_ZAIBATSU    (020.5,230.5)
Radio Stations on GTA2 Wiki documents which stations are on which single-player levels, along with their in-game logo. Lantyz figured out the original multiplayer level radio station codes. My sample is copied from Lantyz's work.

(EDIT) It seems only the first four you declare will be used in-game. All levels get Head Radio - you can't declare that specifically and can't prevent it being available.

(EDIT) Tutorial with sample code and references now available:
Last edited by BenMillard on 29 Jan 2012, 19:57, edited 4 times in total.

User avatar
elypter
Immortal
Posts: 1120
Joined: 26 Dec 2009, 23:53
GH nick: elypter

Re: Code Snippets

Post by elypter » 02 Dec 2010, 00:38

race respawn checkpoint
-all respwan zones must be in the teleporter range
-the respawn zones should be in the middle of the checkpoints to reduce camera time
-the commented lines get rid of the camera flights but only once
-Edit: added messages and teleport works almost instantly now

Code: Select all

  
PLAYER_PED p1 = (125.0, 129.5, 255.0) 5 270

COUNTER  game = 0
COUNTER sz11=1
COUNTER sz12=1
CAR_DATA startcar1

COUNTER display11=1
COUNTER display21=1
COUNTER display31=1

LEVELSTART
WHILE (game = 0)

IF (CHECK_CHARACTER_HEALTH(p1, 0))	
	IF ((runonce=1) OR (IS_CAR_WRECKED ( startcar1 )))
		startcar1 = CREATE_CAR (125.0, 128.5) 28 180 WBTWIN END
	ENDIF
	IF ( LOCATE_CHARACTER_ANY_MEANS ( p1 , 126.5 , 136.5 , 2.0 , 5.0 , 5.0 ))
		IF (display31=1)
			SET display31=0
			DISPLAY_MESSAGE ( 5501 )
		ENDIF
		ADD_SCORE  ( p1 , 999999 )
	ELSE
		SET display31=1
	ENDIF
	
	//Respawnpoints
	IF ( LOCATE_CHARACTER_ANY_MEANS ( p1, 111.5, 104.5, 1.0, 2.0, 2.0))
		IF (sz11=1)
			IF (display11=1)
				SET display11=0
				DISPLAY_MESSAGE ( 5504 )
			ENDIF
			IF (NOT(HAS_CHARACTER_DIED(p1)))
				WARP_FROM_CAR_TO_POINT ( p1, 125.0, 129.5, 2.0, 180 )
				SET display11=1				
			ENDIF
		ENDIF
		IF (sz21=1)
			IF (NOT(HAS_CHARACTER_DIED(p1)))
				WARP_FROM_CAR_TO_POINT ( p1, 76.0, 42.5, 4.0, 180 )
			ENDIF
		ENDIF
	ENDIF
	IF ( LOCATE_CHARACTER_ANY_MEANS ( p1, 76.0, 40.5, 4.0, 5.0, 3.0))
		IF (display21=1)
			SET display21=0
			DISPLAY_MESSAGE ( 5503 )
		ENDIF
		SET sz11=0
		SET sz21=1	
	ELSE
		SET display21=1
	ENDIF
ENDIF

ENDWHILE
LEVELEND
yur sa'nok ngeyä

User avatar
Welcome
Ped
Ped
Posts: 4
Joined: 16 Dec 2010, 11:57
GH nick: Fedaykin

Re: Code Snippets

Post by Welcome » 26 Dec 2010, 23:37

To make flamethrower less strong ( stop char burning )

Code: Select all

IF ( IS_CHAR_ON_FIRE ( p1 )) 
       DELAY_HERE ( put here how long will be the char on fire )
       SET_CHAR_INVINCIBLE ( p1 , ON )
       SET_CHAR_INVINCIBLE ( p1 , OFF )
      ENDIF 
work PERFECT ON WHILE CYCLE if u put this to WHILE_EXEC it will not work its little bit complicated to set it on while_exec :(

User avatar
elypter
Immortal
Posts: 1120
Joined: 26 Dec 2009, 23:53
GH nick: elypter

Re: Code Snippets

Post by elypter » 27 Dec 2010, 18:19

lock out a bot:
doors are another candidate for "it's not a bug, it's a feature".
Bots cannot walk or drive through doors, even when they are already open. Although this is stupid it can be an advantage because there is no other way to lock out non player characters.

Just create a door with invisible tiles that is always open and bots wont get through it (99% of them). bots can still be pushed through by explosions.

Code: Select all

DECLARE_DOOR_INFO ( 360 , 367 , 2 )
DOOR_DATA door_1 = DOUBLE (58, 66, 4) (59.0, 66.5, 4.0, 2.0, 1.0) TOP 0 ANY_PLAYER CLOSE_WHEN_OPEN_RULE_FAILS 0 FLIP_RIGHT NOT_REVERSED
LEVELSTART
MAKE_DOOR_MANUAL(door_1)
OPEN_DOOR(door_1)
yur sa'nok ngeyä

BenMillard
Immortal
Posts: 889
Joined: 16 May 2009, 06:14
GH nick: BenMillard
Location: London, UK
Contact:

Re: Code Snippets

Post by BenMillard » 04 Jan 2011, 23:06

From the DOOR_DATA section of DMA's documentation:
DMA Scripting Document wrote:If you give the door a <code>close never</code> type, it will stay permanently open & will let anything go through. All other types will only let the 'type' that opened it through, e.g the player, a particular car.
In your code, ANY_PLAYER is the 'type' that opened it. So only they can get through, I guess. There is an ANY_CAR door opening type but there's no ANY_MEANS one.

Setting the door closing type to CLOSE_NEVER would be worth a try, given the quote above.

(EDIT) Welcome, your code be run by a THREAD_TRIGGER at each player's start location. It would contain a WHILE_EXEC which checked the player still existed, then checked if they were on fire, then shortened the flame duration.

Industrial has like 30 threads, for Kill Frenzy and phones and so on. 6 threads plus your main loop should be fine. (Maybe I should give an example, oops.)

User avatar
elypter
Immortal
Posts: 1120
Joined: 26 Dec 2009, 23:53
GH nick: elypter

Re: Code Snippets

Post by elypter » 17 Feb 2011, 19:15

Custom death message

Code: Select all

IF ( HAS_CHARACTER_DIED ( p1 )  ) //Player died
	IF ((p1_trg_arena=1) OR (p1_noraceon=1)) //you died in the arena in your car or before getting back in
		SET msg_hurt=3
	ENDIF
ENDIF
//DEATH MESSAGE
IF (msg_hurt>1)
	SET msg_hurt = ( msg_hurt - 1 )
ENDIF
IF (msg_hurt=1)
	SET temp = ( rand / 4 )
	SET temp = ( temp * 4 )
	SET temp= ( rand - temp )
	IF (temp=0)
		DISPLAY_MESSAGE ( 5053 )
	ENDIF
	IF (temp=1)
		DISPLAY_MESSAGE ( 5058 )
	ENDIF
	IF (temp=2)
		DISPLAY_MESSAGE ( 5059 )
	ENDIF
	IF (temp=3)
		DISPLAY_MESSAGE ( 5031 )
	ENDIF
	SET msg_hurt = 0
ENDIF
-everything in while_exec
-rand must be a counter that is increased every cycle and reset on pseudo random situations for seed
Last edited by elypter on 19 Feb 2011, 13:04, edited 2 times in total.
yur sa'nok ngeyä

Post Reply