Code Snippets

Anything to do with GTA1/GTA2 modding (tools, scripts and more).
User avatar
elypter
Immortal
Posts: 1120
Joined: 26 Dec 2009, 23:53
GH nick: elypter

Re: Code Snippets

Post by elypter »

for rocket maps with invisible roof for fast death you have to leave holes for respawn points. this script closes them when not needed

Code: Select all


COUNTER mainloop=1
COUNTER dsum=0

LEVELSTART
WHILE_EXEC(mainloop=1)
SET dsum = 0

IF (CHECK_CHARACTER_HEALTH(p1, 0))
	IF(HAS_CHARACTER_DIED(p1))
		SET dsum = 1
	ENDIF
ENDIF
IF (CHECK_CHARACTER_HEALTH(p2, 0))
	IF(HAS_CHARACTER_DIED(p2))
		SET dsum = 1
	ENDIF
ENDIF
IF (CHECK_CHARACTER_HEALTH(p3, 0))
	IF(HAS_CHARACTER_DIED(p3))
		SET dsum = 1
	ENDIF
ENDIF
IF (CHECK_CHARACTER_HEALTH(p4, 0))
	IF(HAS_CHARACTER_DIED(p4))
		SET dsum = 1
	ENDIF
ENDIF
IF (CHECK_CHARACTER_HEALTH(p5, 0))
	IF(HAS_CHARACTER_DIED(p5))
		SET dsum = 1
	ENDIF
ENDIF
IF (CHECK_CHARACTER_HEALTH(p6, 0))
	IF(HAS_CHARACTER_DIED(p6))
		SET dsum = 1
	ENDIF
ENDIF
IF (dsum = 0)
	CHANGE_BLOCK TYPE (26, 26, 1) FIELD 0
	CHANGE_BLOCK TYPE (26, 34, 1) FIELD 0
	CHANGE_BLOCK TYPE (34, 26, 1) FIELD 0
	CHANGE_BLOCK TYPE (34, 34, 1) FIELD 0
ELSE
	CHANGE_BLOCK TYPE (26, 26, 1) AIR 0
	CHANGE_BLOCK TYPE (26, 34, 1) AIR 0
	CHANGE_BLOCK TYPE (34, 26, 1) AIR 0
	CHANGE_BLOCK TYPE (34, 34, 1) AIR 0
ENDIF

ENDWHILE
LEVELEND
everything in while_exec
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 »

This solves the problem of script size limitation (almost completely because declarations can only be done in main script)
This can be done by running an external script from a subfolder. Usually that had the limitation that it is not executed with while_exec speed. By running through while_exec only once in an extra while_exec loop inside the external script this can be solved.

test.mis:

Code: Select all

COUNTER mainloop=1
COUNTER tmploop=0

LEVELSTART

   WHILE_EXEC(mainloop=1)
      DO_NOWT
      LAUNCH_MISSION (external1.mis)
   ENDWHILE

LEVELEND
test/external.mis:

Code: Select all

MISSIONSTART

   SET tmploop=1
   WHILE_EXEC(tmploop=1)
      DO_NOWT
      SET tmploop=0
   ENDWHILE

MISSIONEND
yur sa'nok ngeyä
User avatar
Pyro
Immortal
Posts: 414
Joined: 17 Mar 2010, 04:07
GH nick: Pyro
Location: Wales, UK

Re: Code Snippets

Post by Pyro »

As requested by Gustavob, here is code to make both remaps for the Rednecks appear in a map. In this case, the gang zone in the map editor is called "redngang" so make sure you have it.

Code: Select all

SET_GANG_INFO ( redngang , 5 , PISTOL , MACHINE_GUN , MOLOTOV , 4 , 47.5 , 29.5 , 2.0 , 1 , PICKUP , 3 )
Edit: JohnTooray is correct with his statement you only need remap 5 for both red head and yellow head gang members to appear! Updated the above code with new information.
Last edited by Pyro on 20 Jul 2011, 08:52, edited 2 times in total.
User avatar
JohnTooray
Mugger
Mugger
Posts: 19
Joined: 06 May 2011, 11:43
Location: Munster, Germany

Re: Code Snippets

Post by JohnTooray »

Pyro wrote:As requested by Gustavob, here is code to make both remaps for the Rednecks appear in a map. In this case, the gang zone in the map editor is called "redngang" so make sure you have it.

Code: Select all

SET_GANG_INFO ( redngang , 6 , PISTOL , MACHINE_GUN , MOLOTOV , 0 , 0.0 , 0.0 , 0.0 , 0 , PICKUP , 3 )
SET_GANG_INFO ( redngang , 5 , PISTOL , MACHINE_GUN , MOLOTOV , 4 , 47.5 , 29.5 , 2.0 , 1 , PICKUP , 3 )
Remap 6 always has to be put before remap 5 otherwise it will not work. Also make sure the co-ordinates etc for remap 6 (first line) are set to zero (0.0) otherwise you'll have two arrows!

At least in singleplayer mode you need only Remap 5. Red and blond headed Rednecks will appear. Dunno if it's different for multiplayer maps...
User avatar
JohnTooray
Mugger
Mugger
Posts: 19
Joined: 06 May 2011, 11:43
Location: Munster, Germany

Re: Code Snippets

Post by JohnTooray »

I recently added some kind of headhunter logic to my map project. This is how it works: If your respect for the corresponding gang gets lower than -3 the gang sends a killer to - well - kill you. If you kill him he will be respawned. To get rid of that killer respect must gain up to 0.
In my map I am using two of these guys. One with criminal_type1 for the first gang and one with criminal_type2 for the second gang.

OK. enough blurb, here's the code:

Code: Select all

CHAR_DATA zaib_killer
COUNTER loop = 1
COUNTER killer_alive = 0
COUNTER killer_brief = 0

LEVELSTART

WHILE (loop = 1)
  IF ( ( killer_alive = 0 ) AND ( CHECK_RESPECT_LOWER ( player, zaib_gang, -3 )	) )
    IF ( killer_brief = 0 )
      DISPLAY_BRIEF (1031) // Something like "We warned ya! Don't Mess with the Z-Boys!"
      SET killer_brief = 1
    ENDIF
    zaib_killer = CREATE_CHAR (153.5, 195.0, 2.0) 8 0 CRIMINAL_TYPE1 END
    GIVE_WEAPON ( zaib_killer, machine_gun )
    ADD_CHAR_TO_GANG ( zaib_killer, zaibgang )
    SET_CHAR_THREAT_SEARCH ( zaib_killer, AREA_PLAYER_ONLY )
    SET_CHAR_THREAT_REACTION ( zaib_killer, REACT_AS_NORMAL )
    SET_CHAR_OBJECTIVE ( zaib_killer, KILL_CHAR_ANY_MEANS, player )
    SET_CHAR_SHOOTING_SKILL ( zaib_killer, CRACK_SHOT )
    SET killer_alive = 1
  ENDIF
  IF ( HAS_CHARACTER_DIED (zaib_killer) )
    IF ( CHECK_RESPECT_GREATER (player, zaibgang, 0) )
      SET killer_alive = 0
      SET killer_brief = 0
      DISPLAY_BRIEF (1032) // "I hope you learnt your lesson."
    ELSE
      DELETE_ITEM (zaib_killer)
      SET killer_alive = 0
      DISPLAY_BRIEF (1033) // "You don't think it's over now, do you?"
    ENDIF
  ENDIF
ENDWHILE
cheers,
JohnTooray
User avatar
Sektor
Boss
Boss
Posts: 1423
Joined: 04 Mar 2008, 06:51
GH nick: Sektor
Location: GTAMP.com
Contact:

Re: Code Snippets

Post by Sektor »

[syntax=mis]
// Control the turret of a wrecked tank:

PLAYER_PED p1 = (222.2, 175.2, 255.0) 10 90

PARKED_CAR_DATA tank = (246.0, 186.0) 19 180 TANK

LEVELSTART

EXPLODE_SMALL (tank)
TAKE_REMOTE_CONTROL_OF_CAR (p1, tank)

LEVELEND
[/syntax]
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: Code Snippets

Post by T.M. »

Who wants random car remap?! :D lool. ahahaha epic.

I had to use binary tree to speed it up around 3x compared to without it!

NOTE: you must call this subroutine after you had created a car named "auto" !

Note: its not actually a binary tree because MIS syntax doesnt support ELSE's at all. (lol). I also tried to optimize it by using GOSUB after CHANGE_CAR_REMAP, but it actually made it slower!

[mis]
random_car_remap:
if(randomizer < 16) // 0-15
if(randomizer < 8) // 0-7
if(randomizer < 4) // 0-3
if(randomizer < 2)
if(randomizer = 0)
CHANGE_CAR_REMAP(auto, 0)
ENDIF
if(randomizer = 1)
CHANGE_CAR_REMAP(auto, 1)
ENDIF
ENDIF
if(randomizer >= 2)
if(randomizer = 2)
CHANGE_CAR_REMAP(auto, 2)
ENDIF
if(randomizer = 3)
CHANGE_CAR_REMAP(auto, 3)
ENDIF
ENDIF
ENDIF
if(randomizer >= 4) // 4-7
if(randomizer < 6)
if(randomizer = 4)
CHANGE_CAR_REMAP(auto, 4)
ENDIF
if(randomizer = 5)
CHANGE_CAR_REMAP(auto, 5)
ENDIF
ENDIF
if(randomizer >= 6)
if(randomizer = 6)
CHANGE_CAR_REMAP(auto, 6)
ENDIF
if(randomizer = 7)
CHANGE_CAR_REMAP(auto, 7)
ENDIF
ENDIF
ENDIF
ENDIF
if(randomizer >= 8) // 8-15
if(randomizer < 12) // 8-11
if(randomizer < 10)
if(randomizer = 8)
CHANGE_CAR_REMAP(auto, 8)
ENDIF
if(randomizer = 9)
CHANGE_CAR_REMAP(auto, 9)
ENDIF
ENDIF
if(randomizer >= 10)
if(randomizer = 10)
CHANGE_CAR_REMAP(auto, 10)
ENDIF
if(randomizer = 11)
CHANGE_CAR_REMAP(auto, 11)
ENDIF
ENDIF
ENDIF
if(randomizer >= 12) // 12-15
if(randomizer < 14)
if(randomizer = 12)
CHANGE_CAR_REMAP(auto, 12)
ENDIF
if(randomizer = 13)
CHANGE_CAR_REMAP(auto, 13)
ENDIF
ENDIF
if(randomizer >= 14)
if(randomizer = 14)
CHANGE_CAR_REMAP(auto, 14)
ENDIF
if(randomizer = 15)
CHANGE_CAR_REMAP(auto, 15)
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
if(randomizer >= 16) // 16-31
if(randomizer < 24) // 16-23
if(randomizer < 20) // 16-19
if(randomizer < 18)
if(randomizer = 16)
CHANGE_CAR_REMAP(auto, 16)
ENDIF
if(randomizer = 17)
CHANGE_CAR_REMAP(auto, 17)
ENDIF
ENDIF
if(randomizer >= 18)
if(randomizer = 18)
CHANGE_CAR_REMAP(auto, 18)
ENDIF
if(randomizer = 19)
CHANGE_CAR_REMAP(auto, 19)
ENDIF
ENDIF
ENDIF
if(randomizer >= 20) // 20-23
if(randomizer < 22)
if(randomizer = 20)
CHANGE_CAR_REMAP(auto, 32) // different
ENDIF
if(randomizer = 21)
CHANGE_CAR_REMAP(auto, 21)
ENDIF
ENDIF
if(randomizer >= 22)
if(randomizer = 22)
CHANGE_CAR_REMAP(auto, 22)
ENDIF
if(randomizer = 23)
CHANGE_CAR_REMAP(auto, 23)
ENDIF
ENDIF
ENDIF
ENDIF
if(randomizer >= 24) // 24-31
if(randomizer < 28) // 24-27
if(randomizer < 26)
if(randomizer = 24)
CHANGE_CAR_REMAP(auto, 24)
ENDIF
if(randomizer = 25)
CHANGE_CAR_REMAP(auto, 25)
ENDIF
ENDIF
if(randomizer >= 26)
if(randomizer = 26)
CHANGE_CAR_REMAP(auto, 26)
ENDIF
if(randomizer = 27)
CHANGE_CAR_REMAP(auto, 27)
ENDIF
ENDIF
ENDIF
if(randomizer >= 28) // 28-31
if(randomizer < 30)
if(randomizer = 28)
CHANGE_CAR_REMAP(auto, 34) // different
ENDIF
if(randomizer = 29)
CHANGE_CAR_REMAP(auto, 29)
ENDIF
ENDIF
if(randomizer >= 30)
if(randomizer = 30)
CHANGE_CAR_REMAP(auto, 35) // different
ENDIF
if(randomizer = 31)
CHANGE_CAR_REMAP(auto, 31)
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
// make so sequential calls will have different remap too:
++randomizer
if(randomizer > 31)
SET randomizer = 0
ENDIF
RETURN
[/mis]


[mis]
// Usage:

COUNTER randomizer = 0
FORWARD random_car_remap:

COUNTER done = 0

LEVELSTART

WHILE_EXEC(done = 0)
/////////////////////
// put this if you want to make it even more random:
++randomizer
if(randomizer > 31)
SET randomizer = 0
ENDIF

////
// rest of your code here
////
ENDWHILE

LEVELEND

// you can paste random_car_remap: subroutine here

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

Re: Code Snippets

Post by Pyro »

Proper Looking Police Characters

Old stuff this I know, but here's how to make your police officers actually look like them instead of the weird big looking ones like gang members.

[syntax=mis]CHAR_DATA cop01 = (127.5,127.5,2.0) 0 180 POLICE // police officer
CHAR_DATA swat01 = (127.5,128.5,2.0) 0 180 SWAT // swat officer
...
LEVELSTART
...
SET_CHAR_GRAPHIC_TYPE (cop01,EMERG_GRAPHIC,0)
SET_CHAR_GRAPHIC_TYPE (swat01,EMERG_GRAPHIC,-1)[/syntax]

First guy (remap 0) is a normal police remap, and the second guy uses the -1 remap to get SWAT outfit.

Also interesting to know that setting a characters occupation type to POLICE, SWAT, FBI or ARMY will get you a wanted level when you hit/shoot them or kill them. Unfortunately, you can't seem to make them like real SWAT/FBI who take more shots to kill than normal police (as if they are wearing armour) and will still die pretty quickly like normal characters.

edit by Sektor: I deleted some posts that weren't code and then remembered there was a code snippets discussion topic, so I moved the rest of the posts there.
Last edited by Pyro on 27 Nov 2011, 06:11, edited 1 time in total.
User avatar
Pyro
Immortal
Posts: 414
Joined: 17 Mar 2010, 04:07
GH nick: Pyro
Location: Wales, UK

Re: Code Snippets

Post by Pyro »

Full Remote Control Car Script Example

Here's some example code on how to remote control a car by picking up a remote control powerup (looks like this: [remote] ).

[syntax=mis]PLAYER_PED p1 = (127.5,126.5,2.0) 25 180 // player

OBJ_DATA remote01 = (127.5,127.5,2.0) 0 REMOTE // remote control object

CAR_DATA remote_car01 = (128.5,127.5,2.0) 13 180 VTYPE // car that will be remote controlled

COUNTER loop = 1 // general loop for WHILE_EXEC
COUNTER got_remote = 0 // counter check to see if remote has been collected
...
LEVELSTART
...
WHILE_EXEC (loop = 1)
...
IF ((LOCATE_CHARACTER_ON_FOOT(p1,127.5,127.5,2.0,1.0,1.0)) // wait for p1 at the same coordinates as remote control object
AND (got_remote = 0))
SET got_remote = 1 // remote has been picked up
DELETE_ITEM (remote01) // delete the remote control object
TAKE_REMOTE_CONTROL_OF_CAR (p1,remote_car01) // take remote control of the car
ENDIF
...
ENDWHILE
...
LEVELEND[/syntax]

A few tips:
  • You should put the IF statement inside a WHILE_EXEC loop so it can keep checking if the player is at specified coordinates.
  • The remote control item looks like it can be picked up, but it's actually an object and not a true powerup. This is why the object gets deleted to make it look like it's been picked up.
  • Ideally the remote control object should be somewhere safe for the player, generally on top of buildings you have to jump across to. As you can guess, you lose control of your player and take control of the car, meaning the player can still be shot/killed without knowing it!
  • The only way to regain control over your player is to destroy the remote control car.
  • Remote control mini cars (use the MINI_CAR command on any car declare at the end) to make it similar to GTA1 style!
Enjoy 8-)
User avatar
Pyro
Immortal
Posts: 414
Joined: 17 Mar 2010, 04:07
GH nick: Pyro
Location: Wales, UK

Re: Code Snippets

Post by Pyro »

Basic Phone System

Some code for a working basic phone (the blue information phones). This example only displays messages but it can be re-configured to do a lot of other things. All this is done before the LEVELSTART command.

[syntax=mis]PLAYER_PED p1 = (127.5,127.5,2.0) 25 180 // the player

OBJ_DATA test_phone = (128.5,127.5,2.0) 270 PHONE // the basic blue info phone - note that phone angles are different to other angles!

FORWARD answer_phone: // prepare the phone for answering - don't forget the colon (:) at the end of the line!

THREAD_TRIGGER thr_answer_phone = THREAD_WAIT_FOR_ANSWER_PHONE (p1,test_phone,answer_phone:) // wait for p1 to answer the phone named 'test_phone' and run the function 'answer_phone:' - again, don't forget colon (:) here
answer_phone: // start function
DISPLAY_BRIEF (2902) // text message - "We are the Rednecks!"
DISPLAY_BRIEF (2903) // text message - "Kill Scientists for our respect!"
RETURN // end function and carry on with rest of script[/syntax]

Always remember you have to do your FORWARD commands before the actual THREAD_TRIGGER command, and don't forget to add the colon (:) at the end of function names or it won't work! Since this is just a very basic phone, you can change it to do multiple things instead of the DISPLAY_BRIEF and you can put IF statements in there too so you could make, for example, a phone that gives weapons to a player only if they have X amount of cash.
User avatar
elypter
Immortal
Posts: 1120
Joined: 26 Dec 2009, 23:53
GH nick: elypter

Re: Code Snippets

Post by elypter »

all original gangs with correct remaps and weapons:

[mis]
//XXXXgang must exist in GMP file or crash and it has to have a name like in that form or gangs wont show up):
//redngang must have that name for 2 hair color peds to work

SET_GANG_INFO (einsgang, 11, PISTOL, PISTOL, PISTOL, 1, 128.5, 128.5, 2.0, 10, ISETTA, 16) //Loonies
SET_GANG_INFO (zweigang, 13, PISTOL, PISTOL, PISTOL, 2, 128.5, 128.5, 2.0, 10, MIURA, 15) //Yakuza
SET_GANG_INFO (dreigang, 8, PISTOL, SILENCED_MACHINE_GUN, ROCKET_LAUNCHER, 3, 128.5, 129.5, 2.0, 10, VTYPE, 2) //Zaibatsu
SET_GANG_INFO (redngang, 5, PISTOL, MACHINE_GUN, MOLOTOV, 4, 129.5, 128.5, 2.0, 10, PICKUP, 3) //Rednecks (palettes might be different in other sty file)
SET_GANG_INFO (funfgang, 7, PISTOL, MACHINE_GUN, FLAME_THROWER, 5, 128.5, 130.5, 2.0, 10, STRATOSB, 10) //SRS Scientists
SET_GANG_INFO (sechgang, 9, PISTOL, MOLOTOV, FLAME_THROWER, 6, 130.5, 128.5, 2.0, 10, KRSNABUS, -1) //Hare Krishna
SET_GANG_INFO (siebgang, 10, PISTOL, SHOTGUN, MACHINE_GUN, 7, 128.5, 131.5, 2.0, 10, BUICK, 28) //Russian Mafia
[/mis]

respect is set to 10 for all of them which should be reasonable for multiplayer.
yur sa'nok ngeyä
BenMillard
Immortal
Posts: 889
Joined: 16 May 2009, 06:14
GH nick: BenMillard
Location: London, UK
Contact:

Upward Timer

Post by BenMillard »

(See the Upward Timers tutorial for up-to-date code and explanation.)

Faking an upward timer is possible by using ADD_TIME_TO_TIMER once per second in a WHILE_EXEC loop. Normally, a timer will lose 1 second per second. Simply add 2 seconds during each second and it will count upwards!

You might see a slight flicker as the timer counts down a moment before it counts up again. Starting the COUNTER at 3 instead of 1 removes this. Seems to take 2 frames for a THREAD_TRIGGER to initialise and the WHILE_EXEC to begin.

This code runs in a separate thread, so you can add it to any level. Check for naming conflicts, then adjust the coordinates for the PLAYER_PED. Make sure the THREAD_TRIGGER covers the start point for the first player, as that's the only player who will definitely be in the level.

You can see it working in Army Base.

[mis]// Your objects go here...

// Player:
PLAYER_PED p1 = (202.5,240.0,2.0) 07 000 // Yellow

// Upward Timer
FORWARD upward_timer:
COUNTER stage = 1 // mission is active from the start
COUNTER timer = 3 // count frames 1-30 every second
// Note: Takes 2 frames to trigger this code so we start at 3 instead of 1.
TIMER_DATA time_taken // display the time taken
THREAD_TRIGGER upward_trigger = THREAD_WAIT_FOR_CHAR_IN_AREA_ANY_MEANS(
p1, 202.0,242.0,2.0, 4.0,4.0, upward_timer:)
upward_timer:
// Setup
DELAY_HERE (360) // wait for Time Limit to go away
DISPLAY_TIMER (time_taken, 12) // 330 frames = 12 seconds

// Remove
WHILE_EXEC (stage = 0) // don't want it any more
CLEAR_TIMER (time_taken)
ENDWHILE

// Display and Update
WHILE_EXEC (stage = 1) // until JOB COMPLETE
IF (timer = 30) // once per second
SET timer = 1 // reset interval
ADD_TIME_TO_TIMER (time_taken, 2)
ELSE
++timer // increment by 1 frame
ENDIF
ENDWHILE

// Pause Timer
// Note: Lets players see how long they took to complete.
WHILE_EXEC (stage = 2)
IF (timer = 30) // once per second
SET timer = 1 // reset interval
ADD_TIME_TO_TIMER (time_taken, 1)
ELSE
++timer // increment by 1 frame
ENDIF
ENDWHILE
RETURN


LEVELSTART


// Your other commands go here...


LEVELEND[/mis]
This timer starts as soon as the level begins. It pauses if any part of your script does SET stage = 2. You can remove the timer with SET stage = 0 anywhere in your code. Feel free to integrate it however you like, though.

Why the DELAY_HERE?
In multiplayer games, you can set a Time Limit. GTA2 displays this when the game starts but it will delete any mission script timer. You have to wait 11 seconds for it to go away. That was discovered by Elypter, IIRC.

Time Limit reminders later on in the game will not delete your timers.
User avatar
Pyro
Immortal
Posts: 414
Joined: 17 Mar 2010, 04:07
GH nick: Pyro
Location: Wales, UK

Re: Code Snippets

Post by Pyro »

Working Garage Example

Below is an example of a fully working garage system that checks a certain car (a limo) has entered a garage with double doors and will pay the player $5,000 for it. Once the car is parked, the player is automatically teleported out. You will need to create a garage area in your map for this to work which is deep and wide enough to accept a vehicle. Of course, change your co-ordinates of these items to fit your map and script.

This is copied from my new/updated tutorial thread which is also listed there and copyied here for reference, updated again to make it simpler without needing UPDATE_DOOR_TARGET command.

[syntax=mis]PLAYER_DATA p1 = (127.5,127.5,2.0) 25 180 // the player

PARKED_CAR_DATA limo01 = (130.5,127.5,2.0) 02 180 LIMO // the limousine

DECLARE_DOOR_INFO (969,976,2) // tile numbers in STY file with start tile, end tile and animation speed

DOOR_DATA garage_door = DOUBLE (101,113,2) (101.0,114.0,2.0,2.0,4.0 ) BOTTOM 0 ANY_PLAYER_ONE_CAR CLOSE_WHEN_OPEN_RULE_FAILS 0 FLIP_RIGHT NOT_REVERSED limo01 // double door on garage, will only open for 'limo01' car

COUNTER loop = 1 // general game loop
COUNTER limo_parked = 0 // has the limo been parked yet?

LEVELSTART // start the level!

WHILE_EXEC (loop=1) // game loop

// check if limo is in front of garage door and park car if it is close enough
IF ((IS_CAR_IN_BLOCK(limo01 , 101.0 , 112.0 , 2.0 , 2.0 , 3.0 ) )
AND (limo_parked = 0))
PARK (limo01,garage_door ) // automatically 'pull' the car in to garage and teleport player out
SET limo_parked = 1
ENDIF

// check if parking procedure has finished then give $5,000 to player
IF ((limo_parked=1)
AND (HAS_PARK_FINISHED()))
SET limo_parked = 0
ADD_SCORE (p1,5000)
ENDIF

ENDWHILE

LEVELEND[/syntax]
CarThief
Hitman
Hitman
Posts: 108
Joined: 19 May 2012, 18:12
GH nick: CarThief
Location: Holland, AKA The Netherlands

Re: Code Snippets

Post by CarThief »

Cause explosion on Player when pressing Car Horn:
Long time ago i made a short script that would cause explosions when the Player presses his car horn, which resulted in, depending how fast he was driving from suicide to boosting the car forward, or if explosion-proof but slow or stationary; spazzing out all over the place.
It has the unfortunate side-effect of crashing the game after exess use though. As if there was some hardcoded (script-created only?) explosion limit...

Works best in a WHILE_EXEC loop for a full fledged sea of flames effect. Should work on any area if you change the coordinates a little.
The sounds being used can be replaced with another notification of any kind. It toggles between no, small normal and large explosions when going in and out of the target zone.
I recomment sticking to small exposions for (mostly) safe usage, you'll need really fast cars for EXPLODE_LARGE. :P

Code: Select all

IF ( ( ( LOCATE_CHARACTER_ANY_MEANS (Player1, 129.5, 125.5, 2.0, 2.0, 2.0) ) AND ( Togglemechanic = 0 ) ) AND ( HornExplode = 0 ) )
SET Togglemechanic = 1
SET Hornexplode = 1
HornToggleSound = CREATE_SOUND (129.5, 124.5, 2.0) ROCKET_FAIL_LAUGH PLAY_INSTANT END
ENDIF

IF ( ( ( LOCATE_CHARACTER_ANY_MEANS (Player1, 129.5, 125.5, 2.0, 2.0, 2.0) ) AND ( Togglemechanic = 0 ) ) AND ( HornExplode = 1 ) )
SET Togglemechanic = 1
SET Hornexplode = 2
HornToggleSound = CREATE_SOUND (129.5, 124.5, 2.0) SCREAM PLAY_INSTANT END
ENDIF

IF ( ( ( LOCATE_CHARACTER_ANY_MEANS (Player1, 129.5, 125.5, 2.0, 2.0, 2.0) ) AND ( Togglemechanic = 0 ) ) AND ( HornExplode = 2 ) )
SET Togglemechanic = 1
SET Hornexplode = 3
HornToggleSound = CREATE_SOUND (129.5, 124.5, 2.0) CRYING PLAY_INSTANT END
ENDIF

IF ( ( ( LOCATE_CHARACTER_ANY_MEANS (Player1, 129.5, 125.5, 2.0, 2.0, 2.0) ) AND ( Togglemechanic = 0 ) ) AND ( HornExplode = 3 ) )
SET Togglemechanic = 1
SET Hornexplode = 0
HornToggleSound = CREATE_SOUND (129.5, 124.5, 2.0) YEEHA_BOMB PLAY_INSTANT END
ENDIF

//-----------------

IF ( NOT ( ( LOCATE_CHARACTER_ANY_MEANS (Player1, 129.5, 125.5, 2.0, 2.0, 2.0) ) AND ( Togglemechanic = 1) ) )
SET Togglemechanic = 0
ENDIF

IF ( ( Hornexplode = 1 ) AND ( IS_CHAR_PRESSING_HORN ( Player1 ) ) )
EXPLODE_SMALL (Player1)
ENDIF
IF ( ( Hornexplode = 2 ) AND ( IS_CHAR_PRESSING_HORN ( Player1 ) ) )
EXPLODE (Player1)
ENDIF
IF ( ( Hornexplode = 3 ) AND ( IS_CHAR_PRESSING_HORN ( Player1 ) ) )
EXPLODE_LARGE (Player1)
ENDIF
CarThief
Hitman
Hitman
Posts: 108
Joined: 19 May 2012, 18:12
GH nick: CarThief
Location: Holland, AKA The Netherlands

Re: Code Snippets

Post by CarThief »

Moonwalking Peds
Was messing with SET_CHAR_MAX_RUNSPEED and got curious if it accepted negative numbers as well, and apparently that works pretty well! Turns out any KILL_CHAR_ON_FOOT/ANY_MEANS ped with this will moonwalk towards their target in an attemp to get closer, and always display the walking animation even at default running speed and above.

They do however have trouble turning around and attacking when getting close but not close enough to get into punching range and then keep circling their position constantly, if they DO get into punching range or the player gets too close they stop moving and start shooting instantly.
[mis]SET_CHAR_MAX_RUNSPEED(character, -0.06)//Normal speed, backwards.[/mis]

Best use i can think of so far is using this as a get-away tactic to be implemented mid-script. Might be usefull for making even smarter bots, hehe...
If i find more uses i´ll just add em here. So far it didnt crash on me, atleast.
BenMillard
Immortal
Posts: 889
Joined: 16 May 2009, 06:14
GH nick: BenMillard
Location: London, UK
Contact:

Re: Vike's enhanced GTA2

Post by BenMillard »

BenMillard wrote:WARP_FROM_CAR_TO_POINT could be used to create team-specific respawn points?
I've done this in Unreal: Mazon Assault.

You cannot use 255.0 as the z value for the WARP command. It crashes the game which means no automatic z-axis position! The height the player respawns at must be set with a normal number.

There are 4 respawn points all together in a 2x2 grid, high on a rocky pillar. The only way to get there is to die and respawn there. This script detects when a player appears on the pillar and immediately sends them to their original start location.

[mis]WHILE_EXEC (loop=1)
// Respawn each player where they started:
/*
PLAYER_PED p1 = (028.5,203.5,255.0) 13 120 // Dark Blue
PLAYER_PED p2 = (029.5,182.5,255.0) 09 295 // Orange
PLAYER_PED p3 = (029.5,182.0,255.0) 09 305 // Orange
PLAYER_PED p4 = (029.5,203.5,255.0) 13 135 // Dark Blue
PLAYER_PED p5 = (029.0,182.0,255.0) 09 315 // Orange
PLAYER_PED p6 = (028.5,202.5,255.0) 13 100 // Dark Blue
*/

// Respawn Attackers at landing site:
IF (CHECK_CHARACTER_HEALTH(p1, 0))
IF (LOCATE_CHARACTER_ANY_MEANS(p1, 021.0,189.0,4.0, 2.0,2.0))
WARP_FROM_CAR_TO_POINT(p1, 028.5,203.5,1.0, 120)
ENDIF
ENDIF
IF (CHECK_CHARACTER_HEALTH(p4, 0))
IF (LOCATE_CHARACTER_ANY_MEANS(p4, 021.0,189.0,4.0, 2.0,2.0))
WARP_FROM_CAR_TO_POINT(p4, 029.5,203.5,1.0, 135)
ENDIF
ENDIF
IF (CHECK_CHARACTER_HEALTH(p6, 0))
IF (LOCATE_CHARACTER_ANY_MEANS(p6, 021.0,189.0,4.0, 2.0,2.0))
WARP_FROM_CAR_TO_POINT(p6, 028.5,202.5,1.0, 100)
ENDIF
ENDIF

// Respawn Defenders in base:
IF (CHECK_CHARACTER_HEALTH(p2, 0))
IF (LOCATE_CHARACTER_ANY_MEANS(p2, 021.0,189.0,4.0, 2.0,2.0))
WARP_FROM_CAR_TO_POINT(p2, 029.0,185.5,1.0, 245)
ENDIF
ENDIF
IF (CHECK_CHARACTER_HEALTH(p3, 0))
IF (LOCATE_CHARACTER_ANY_MEANS(p3, 021.0,189.0,4.0, 2.0,2.0))
WARP_FROM_CAR_TO_POINT(p3, 029.0,186.0,1.0, 225)
ENDIF
ENDIF
IF (CHECK_CHARACTER_HEALTH(p5, 0))
IF (LOCATE_CHARACTER_ANY_MEANS(p5, 021.0,189.0,4.0, 2.0,2.0))
WARP_FROM_CAR_TO_POINT(p5, 028.5,186.0,1.0, 205)
ENDIF
ENDIF

ENDWHILE[/mis]
Other Uses
You could use this to set a specific angle for players to respawn at. By default, they always face South and that can be a disadvantage for some locations.

You could use increment a COUNTER each cycle to randomise the places they WARP to. You'd reset the COUNTER when you reached the total number of alternative respawn points.

You could use much more advanced logic to control respawning now. You could use map zones to choose a respawn point one of their team-mates was in. Or choose a zone none of their enemies are in!
Galactic Boy
Immortal
Posts: 334
Joined: 15 Apr 2012, 08:26

Re: Code Snippets

Post by Galactic Boy »

Explode people by punching.

Code: Select all

IF ( ( HAS_CHAR_PUNCHED_SOMEONE ( p1 ) ) AND ( p1_trg_punched = 0 ) )
		STORE_LAST_CHAR_PUNCHED ( p1 , p1_punched )
		SET p1_trg_punched = 1
	ENDIF
	IF (( p1_trg_punched = 1 ) AND ( p1_explode_punch = 1))
		IF ( NOT ( DELAY ( 60 ) ) )
			EXPLODE_SMALL (p1_punched)
			SET p1_trg_punched = 0
	ENDIF
ENDIF
Blitz_9100
Ped
Ped
Posts: 4
Joined: 12 Mar 2013, 00:33
GH nick: Blitz_9100

Re: Code Snippets

Post by Blitz_9100 »

Expanding on the snippet located on the first page by Pyro, I implemented a way for multiple users to enter vehicles and allow users to enter their vehicle using it. I came across a few weird bugs which I can't pinpoint on whats causing it. The script itself may need to be optimized, but it works non the less.

Some of the bugs of the script are wanted players being a passenger in the car causes the police to pull the driver out, Then the police get in a crash the game, Some random weirdness of players randomly getting into ped driven cars, and the various crashes from entering a single user car which vary to game crashing to my computer freezing.

[syntax=mis]
COUNTER p1_driving=0
COUNTER p2_driving=0
COUNTER p3_driving=0
COUNTER p4_driving=0
COUNTER p5_driving=0
COUNTER p6_driving=0

COUNTER p1_signal=0
COUNTER p2_signal=0
COUNTER p3_signal=0
COUNTER p4_signal=0
COUNTER p5_signal=0
COUNTER p6_signal=0

COUNTER p1_calling=0
COUNTER p2_calling=0
COUNTER p3_calling=0
COUNTER p4_calling=0
COUNTER p5_calling=0
COUNTER p6_calling=0

COUNTER riding=1

WHILE_EXEC(riding=1)
IF ( CHECK_CHARACTER_HEALTH(p1, 0) )
GIVE_WEAPON ( p1, ELECTRO_BATON )

IF ( IS_CHARACTER_IN_ANY_CAR(p1) )
STORE_CAR_CHARACTER_IS_IN(p1, p1_car)

IF ( IS_CHAR_PRESSING_HORN(p1) )
SET p1_calling=1
ELSE
SET p1_calling=0
ENDIF

SET p1_driving=1
ELSE
IF ( CHECK_CHAR_CURR_WEAPON(p1 , ELECTRO_BATON) )
SET p1_signal=1
ELSE
SET p1_signal=0
ENDIF

SET p1_driving=0
ENDIF
ENDIF

IF ( CHECK_CHARACTER_HEALTH(p2, 0) )
GIVE_WEAPON ( p2, ELECTRO_BATON )

IF ( IS_CHARACTER_IN_ANY_CAR(p2) )
STORE_CAR_CHARACTER_IS_IN(p2, p2_car)

IF ( IS_CHAR_PRESSING_HORN(p2) )
SET p2_calling=1
ELSE
SET p2_calling=0
ENDIF

SET p2_driving=1
ELSE
IF ( CHECK_CHAR_CURR_WEAPON(p2 , ELECTRO_BATON) )
SET p2_signal=1
ELSE
SET p2_signal=0
ENDIF

SET p2_driving=0
ENDIF
ENDIF

IF ( CHECK_CHARACTER_HEALTH(p3, 0) )
GIVE_WEAPON ( p3, ELECTRO_BATON )

IF ( IS_CHARACTER_IN_ANY_CAR(p3) )
STORE_CAR_CHARACTER_IS_IN(p3, p3_car)

IF ( IS_CHAR_PRESSING_HORN(p3) )
SET p3_calling=1
ELSE
SET p3_calling=0
ENDIF

SET p3_driving=1
ELSE
IF ( CHECK_CHAR_CURR_WEAPON(p3 , ELECTRO_BATON) )
SET p3_signal=1
ELSE
SET p3_signal=0
ENDIF

SET p3_driving=0
ENDIF
ENDIF

IF ( CHECK_CHARACTER_HEALTH(p4, 0) )
GIVE_WEAPON ( p4, ELECTRO_BATON )

IF ( IS_CHARACTER_IN_ANY_CAR(p4) )
STORE_CAR_CHARACTER_IS_IN(p4, p4_car)

IF ( IS_CHAR_PRESSING_HORN(p4) )
SET p4_calling=1
ELSE
SET p4_calling=0
ENDIF

SET p4_driving=1
ELSE
IF ( CHECK_CHAR_CURR_WEAPON(p4 , ELECTRO_BATON) )
SET p4_signal=1
ELSE
SET p4_signal=0
ENDIF

SET p4_driving=0
ENDIF
ENDIF

IF ( CHECK_CHARACTER_HEALTH(p5, 0) )
GIVE_WEAPON ( p5, ELECTRO_BATON )

IF ( IS_CHARACTER_IN_ANY_CAR(p5) )
STORE_CAR_CHARACTER_IS_IN(p5, p5_car)

IF ( IS_CHAR_PRESSING_HORN(p5) )
SET p5_calling=1
ELSE
SET p5_calling=0
ENDIF

SET p5_driving=1
ELSE
IF ( CHECK_CHAR_CURR_WEAPON(p5 , ELECTRO_BATON) )
SET p5_signal=1
ELSE
SET p5_signal=0
ENDIF

SET p5_driving=0
ENDIF
ENDIF

IF ( CHECK_CHARACTER_HEALTH(p6, 0) )
GIVE_WEAPON ( p6, ELECTRO_BATON )

IF ( IS_CHARACTER_IN_ANY_CAR(p6) )
STORE_CAR_CHARACTER_IS_IN(p6, p6_car)

IF ( IS_CHAR_PRESSING_HORN(p6) )
SET p6_calling=1
ELSE
SET p6_calling=0
ENDIF

SET p6_driving=1
ELSE
IF ( CHECK_CHAR_CURR_WEAPON(p6 , ELECTRO_BATON) )
SET p6_signal=1
ELSE
SET p6_signal=0
ENDIF

SET p6_driving=0
ENDIF
ENDIF

IF ( ( p1_driving = 1 ) AND ( p1_calling = 1 ) )
if ( (p1_signal = 1) and (p1_driving=0) )
SET_CHAR_OBJECTIVE ( p1 , ENTER_CAR_AS_PASSENGER , p1_car )
SET p1_driving=1
ENDIF

if ( (p2_signal = 1) and (p2_driving=0) )
SET_CHAR_OBJECTIVE ( p2 , ENTER_CAR_AS_PASSENGER , p1_car )
SET p2_driving=1
ENDIF

if ( (p3_signal = 1) and (p3_driving=0) )
SET_CHAR_OBJECTIVE ( p3 , ENTER_CAR_AS_PASSENGER , p1_car )
SET p3_driving=1
ENDIF

if ( (p4_signal = 1) and (p4_driving=0) )
SET_CHAR_OBJECTIVE ( p4 , ENTER_CAR_AS_PASSENGER , p1_car )
SET p4_driving=1
ENDIF

if ( (p5_signal = 1) and (p5_driving=0) )
SET_CHAR_OBJECTIVE ( p5 , ENTER_CAR_AS_PASSENGER , p1_car )
SET p5_driving=1
ENDIF

if ( (p6_signal = 1) and (p6_driving=0) )
SET_CHAR_OBJECTIVE ( p6 , ENTER_CAR_AS_PASSENGER , p1_car )
SET p6_driving=1
ENDIF
ENDIF

IF ( ( p2_driving = 1 ) AND ( p2_calling = 1 ) )
if ( (p1_signal = 1) and (p1_driving=0) )
SET_CHAR_OBJECTIVE ( p1 , ENTER_CAR_AS_PASSENGER , p2_car )
SET p1_driving=1
ENDIF

if ( (p2_signal = 1) and (p2_driving=0) )
SET_CHAR_OBJECTIVE ( p2 , ENTER_CAR_AS_PASSENGER , p2_car )
SET p2_driving=1
ENDIF

if ( (p3_signal = 1) and (p3_driving=0) )
SET_CHAR_OBJECTIVE ( p3 , ENTER_CAR_AS_PASSENGER , p2_car )
SET p3_driving=1
ENDIF

if ( (p4_signal = 1) and (p4_driving=0) )
SET_CHAR_OBJECTIVE ( p4 , ENTER_CAR_AS_PASSENGER , p2_car )
SET p4_driving=1
ENDIF

if ( (p5_signal = 1) and (p5_driving=0) )
SET_CHAR_OBJECTIVE ( p5 , ENTER_CAR_AS_PASSENGER , p2_car )
SET p5_driving=1
ENDIF

if ( (p6_signal = 1) and (p6_driving=0) )
SET_CHAR_OBJECTIVE ( p6 , ENTER_CAR_AS_PASSENGER , p2_car )
SET p6_driving=1
ENDIF
ENDIF

IF ( ( p3_driving = 1 ) AND ( p3_calling = 1 ) )
if ( (p1_signal = 1) and (p1_driving=0) )
SET_CHAR_OBJECTIVE ( p1 , ENTER_CAR_AS_PASSENGER , p3_car )
SET p1_driving=1
ENDIF

if ( (p2_signal = 1) and (p2_driving=0) )
SET_CHAR_OBJECTIVE ( p2 , ENTER_CAR_AS_PASSENGER , p3_car )
SET p2_driving=1
ENDIF

if ( (p3_signal = 1) and (p3_driving=0) )
SET_CHAR_OBJECTIVE ( p3 , ENTER_CAR_AS_PASSENGER , p3_car )
SET p3_driving=1
ENDIF

if ( (p4_signal = 1) and (p4_driving=0) )
SET_CHAR_OBJECTIVE ( p4 , ENTER_CAR_AS_PASSENGER , p3_car )
SET p4_driving=1
ENDIF

if ( (p5_signal = 1) and (p5_driving=0) )
SET_CHAR_OBJECTIVE ( p5 , ENTER_CAR_AS_PASSENGER , p3_car )
SET p5_driving=1
ENDIF

if ( (p6_signal = 1) and (p6_driving=0) )
SET_CHAR_OBJECTIVE ( p6 , ENTER_CAR_AS_PASSENGER , p3_car )
SET p6_driving=1
ENDIF
ENDIF

IF ( ( p4_driving = 1 ) AND ( p4_calling = 1 ) )
if ( (p1_signal = 1) and (p1_driving=0) )
SET_CHAR_OBJECTIVE ( p1 , ENTER_CAR_AS_PASSENGER , p4_car )
SET p1_driving=1
ENDIF

if ( (p2_signal = 1) and (p2_driving=0) )
SET_CHAR_OBJECTIVE ( p2 , ENTER_CAR_AS_PASSENGER , p4_car )
SET p2_driving=1
ENDIF

if ( (p3_signal = 1) and (p3_driving=0) )
SET_CHAR_OBJECTIVE ( p3 , ENTER_CAR_AS_PASSENGER , p4_car )
SET p3_driving=1
ENDIF

if ( (p4_signal = 1) and (p4_driving=0) )
SET_CHAR_OBJECTIVE ( p4 , ENTER_CAR_AS_PASSENGER , p4_car )
SET p4_driving=1
ENDIF

if ( (p5_signal = 1) and (p5_driving=0) )
SET_CHAR_OBJECTIVE ( p5 , ENTER_CAR_AS_PASSENGER , p4_car )
SET p5_driving=1
ENDIF

if ( (p6_signal = 1) and (p6_driving=0) )
SET_CHAR_OBJECTIVE ( p6 , ENTER_CAR_AS_PASSENGER , p4_car )
SET p6_driving=1
ENDIF
ENDIF

IF ( ( p5_driving = 1 ) AND ( p5_calling = 1 ) )
if ( (p1_signal = 1) and (p1_driving=0) )
SET_CHAR_OBJECTIVE ( p1 , ENTER_CAR_AS_PASSENGER , p5_car )
SET p1_driving=1
ENDIF

if ( (p2_signal = 1) and (p2_driving=0) )
SET_CHAR_OBJECTIVE ( p2 , ENTER_CAR_AS_PASSENGER , p5_car )
SET p2_driving=1
ENDIF

if ( (p3_signal = 1) and (p3_driving=0) )
SET_CHAR_OBJECTIVE ( p3 , ENTER_CAR_AS_PASSENGER , p5_car )
SET p3_driving=1
ENDIF

if ( (p4_signal = 1) and (p4_driving=0) )
SET_CHAR_OBJECTIVE ( p4 , ENTER_CAR_AS_PASSENGER , p5_car )
SET p4_driving=1
ENDIF

if ( (p5_signal = 1) and (p5_driving=0) )
SET_CHAR_OBJECTIVE ( p5 , ENTER_CAR_AS_PASSENGER , p5_car )
SET p5_driving=1
ENDIF

if ( (p6_signal = 1) and (p6_driving=0) )
SET_CHAR_OBJECTIVE ( p6 , ENTER_CAR_AS_PASSENGER , p5_car )
SET p6_driving=1
ENDIF
ENDIF

IF ( ( p6_driving = 1 ) AND ( p6_calling = 1 ) )
if ( (p1_signal = 1) and (p1_driving=0) )
SET_CHAR_OBJECTIVE ( p1 , ENTER_CAR_AS_PASSENGER , p6_car )
SET p1_driving=1
ENDIF

if ( (p2_signal = 1) and (p2_driving=0) )
SET_CHAR_OBJECTIVE ( p2 , ENTER_CAR_AS_PASSENGER , p6_car )
SET p2_driving=1
ENDIF

if ( (p3_signal = 1) and (p3_driving=0) )
SET_CHAR_OBJECTIVE ( p3 , ENTER_CAR_AS_PASSENGER , p6_car )
SET p3_driving=1
ENDIF

if ( (p4_signal = 1) and (p4_driving=0) )
SET_CHAR_OBJECTIVE ( p4 , ENTER_CAR_AS_PASSENGER , p6_car )
SET p4_driving=1
ENDIF

if ( (p5_signal = 1) and (p5_driving=0) )
SET_CHAR_OBJECTIVE ( p5 , ENTER_CAR_AS_PASSENGER , p6_car )
SET p5_driving=1
ENDIF

if ( (p6_signal = 1) and (p6_driving=0) )
SET_CHAR_OBJECTIVE ( p6 , ENTER_CAR_AS_PASSENGER , p6_car )
SET p6_driving=1
ENDIF
ENDIF

SET riding=0
ENDWHILE
[/syntax]
User avatar
Cuban-Pete
Immortal
Posts: 909
Joined: 29 Jan 2010, 15:03
GH nick: Cuban-Pete

Re: Code Snippets

Post by Cuban-Pete »

Looks interesting. And welcome to the forum. :)
"Mmmm, your eyes are so beautiful."
Razor
Lunatic
Lunatic
Posts: 456
Joined: 19 Jul 2008, 14:14
GH nick: Razor, R
Location: Poland / Szczecin
Contact:

Re: Code Snippets

Post by Razor »

there is code like this. We used it in hs ranked mode :D you and your teammate can be in 1 vech by using a horn :)
Post Reply