Missions

Anything to do with GTA1/GTA2 modding (tools, scripts and more).
Post Reply
User avatar
Gustavob
Immortal
Posts: 407
Joined: 18 May 2009, 21:40
GH nick: Gustavob
|Gustavob|
Location: Nowhere.
Contact:

Missions

Post by Gustavob »

Can someone tell me how do I start a mission on script? I started working again on an old multiplayer map in wich I got stuck (and lost the newer .GMP, .MIS and .SCR files D:) and I decided it will be a singleplayer map, and I want to put missions on it. I know I need subroutines and THREAD_TRIGGERS but I need help with them. I dont have some ideas for missions yet, but I just want a model of the codes wich I need to use to start the mission.
You just lost the game.
Razor
Lunatic
Lunatic
Posts: 456
Joined: 19 Jul 2008, 14:14
GH nick: Razor, R
Location: Poland / Szczecin
Contact:

Re: Missions

Post by Razor »

This is a detailed GTA2script example of the structure & contents of a simple mission from beginning to end, with comments detailing what is happening.

Source here:
GTA2 Scripting.rar
(114.76 KiB) Downloaded 570 times

Code: Select all

// player 

PLAYER_PED player = ( 113.5 , 124.7 , 255.0 ) 25 1

//cars for mission

CAR_DATA armoured_car_zh1

CAR_DATA car1_zh1

//characters for mission

CHAR_DATA dealer_leader1

CHAR_DATA dealer_leader2

//objects for the mission

OBJ_DATA gun_zh1

//counters

COUNTER flag_both_cars_destroyed = 0

COUNTER flag_armoured_car_zh1_destroyed = 0

COUNTER flag_car1_zh1_destroyed = 0

COUNTER counter_timer_zh1 = 10799  

TIMER_DATA timer_zh1

//start of mission

do_zaibatsugang_hard_phone_m1:
	
	SET flag_on_mission = 1
	SET flag_on_zaibatsugang_mission = 1
	SET flag_failed_zaibatsugang_hard_phone_m1 = 0
	DISPLAY_MESSAGE ( 1987 )  //"ARMOURED CARS"
	
	DISPLAY_BRIEF ( 1701 )  //"Zack has been kidnapped by the Yakuza, He knows too much, and soon will crack under torture, we need you to get rid of him!"
  	POINT_ARROW_AT ( arrow , armoured_car_zh1 )   
	POINT_ARROW_AT ( arrow1 , car1_zh1 )
	DISPLAY_TIMER ( timer_zh1 , 360 )
			
	WHILE_EXEC ( NOT ( flag_both_cars_destroyed = 2 ) )
			
		-- counter_timer_zh1
		IF ( ( IS_CAR_WRECKED ( armoured_car_zh1 ) )
		AND ( NOT ( flag_armoured_car_zh1_destroyed = 1 ) ) )
			DISPLAY_BRIEF_NOW ( 1703 )  //"That's one of the cars now get the other!"
			REMOVE_ARROW ( arrow )
			++ flag_both_cars_destroyed
			SET flag_armoured_car_zh1_destroyed = 1
			-- counter_timer_zh1
		ENDIF
		
		IF ( ( IS_CAR_WRECKED ( car1_zh1 ) )
		AND ( NOT ( flag_car1_zh1_destroyed = 1 ) ) )
			DISPLAY_BRIEF_NOW ( 1703 )  //"That's one of the cars now get the other!"
			REMOVE_ARROW ( arrow1 )
			++ flag_both_cars_destroyed
			SET flag_car1_zh1_destroyed = 1
			-- counter_timer_zh1
		ENDIF
		
		IF ( counter_timer_zh1 = 0 )
			CLEAR_ALL_BRIEFS ( )
			DISPLAY_BRIEF_NOW ( 1705 )  //"You took too long and Zack spilled his guts. Mission Failed!"
			DISPLAY_MESSAGE ( 1125 )
			SET flag_mission_state = 1
			SET flag_failed_zaibatsugang_hard_phone_m1 = 1
			-- counter_timer_zh1
			RETURN
		ENDIF   
	ENDWHILE
	
	IF ( ( flag_mission_state = 0 )
	AND ( NOT ( counter_timer_zh1 = 0 ) ) )
		CLEAR_ALL_BRIEFS ( )
	 	DISPLAY_BRIEF ( 1702 )  //"Well Done! Its a pity about Zack but he should not have been so stupid as to get caught in the first place. Mission Complete!"
		DISPLAY_MESSAGE ( 1124 )
		ADD_SCORE ( player , 60000 )
		ADD_MULTIPLIER ( player , 1 )
		CLEAR_WANTED_LEVEL ( player )
		CHANGE_GANG_CHAR_RESPECT_AND_UPDATE ( zaibatsugang , player , 1 )
		SET flag_passed_zaibatsugang_hard_phone_m1 = 1
	ENDIF 		
RETURN
		
//------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------

//mission cleanup

	clean_up_zaibatsugang_hard_phone_m1:
	
	SET flag_on_mission = 0
	SET flag_on_zaibatsugang_mission = 0
	SET flag_mission_state = 0
	REMOVE_ARROW ( arrow )
	REMOVE_ARROW ( arrow1 )
	CLEAR_TIMER ( timer_zh1 )
	CLEAR_WANTED_LEVEL ( player )
	MISSION_HAS_FINISHED ( )
			
	IF ( flag_passed_zaibatsugang_hard_phone_m1 = 1 )
		++ counter_number_of_missions_passed
		++ counter_number_of_zaibatsugang_missions_passed
	ENDIF
		
	IF ( flag_failed_zaibatsugang_hard_phone_m1 = 1 )
		++ counter_number_of_missions_failed
		++ counter_number_of_zaibatsugang_missions_failed
		CLEAR_WANTED_LEVEL ( player )
		CHANGE_GANG_CHAR_RESPECT_AND_UPDATE ( zaibatsugang , player , -1 )
	ENDIF
RETURN

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

LEVELSTART
	EXEC
		armoured_car_zh1 = CREATE_GANG_CAR ( 124.5 , 104.5 , 2.0 )  15 0 miura END
		SET_CAR_BULLETPROOF ( armoured_car_zh1 , on )
		SET_CAR_ROCKETPROOF ( armoured_car_zh1 , on )
		SET_CAR_FLAMEPROOF ( armoured_car_zh1 , on )
		car1_zh1 = CREATE_GANG_CAR ( 124.5 , 100.5 , 2.0 ) 15 0 miura END
		SET_CAR_BULLETPROOF ( car1_zh1 , on )
		SET_CAR_ROCKETPROOF ( car1_zh1 , on )
		SET_CAR_FLAMEPROOF ( car1_zh1 , on )
		dealer_leader1 = CREATE_CHAR_INSIDE_CAR ( armoured_car_zh1 ) 13 criminal END
		SET_CHAR_DRIVE_AGGRESSION ( dealer_leader1 , on )
		SET_CHAR_THREAT_REACTION ( dealer_leader1 , no_reaction )
		SET_CHAR_THREAT_SEARCH ( dealer_leader1 , no_threats )
		dealer_leader2 = CREATE_CHAR_INSIDE_CAR ( car1_zh1 ) 13 criminal END
		SET_CHAR_DRIVE_AGGRESSION ( dealer_leader2 , on )
		SET_CHAR_THREAT_SEARCH ( dealer_leader2 , no_threats )
		SET_CHAR_THREAT_REACTION ( dealer_leader2 , no_reaction )
		GIVE_WEAPON ( dealer_leader2 , pistol )
	  	CHANGE_CAR_LOCK ( armoured_car_zh1 , locked )
		CHANGE_CAR_LOCK ( car1_zh1 , locked )
  	ENDEXEC
 	  		
	GOSUB do_zaibatsugang_hard_phone_m1:
	
	GOSUB clean_up_zaibatsugang_hard_phone_m1:
	
LEVELEND// Example script
// waits for played ped to cross a ‘trigger point’ & then sends a  ‘dummy’ ped to a point, and the player // has to kill him before his arrival at the destination.


// data - these are ‘read through’ when the script is loaded & ped under player control is created. 

PLAYER_PED 	player = (90.5 , 133.5 , 255.0 ) 180  0
PED_DATA	target_ped		// ped for the player to kill
LOC_DATA	target_location		// where we’re going to send target_ped
THREAD_DATA threadinfo		// for storing new thread info

// trigger data - coords, width + height of trigger, and the function it ‘starts’ 
TRIGGER	triggerpoint = (95.5 , 133.5 , 2.0 ) 1 1 assasin_mission: 

// this is where we’ll store the length of time it takes for ped to arrive
COUNTER	timer = 0

// general purpose ‘flag’
COUNTER 	flag = 0

/* send_and_wait_for_ped
 * ------------------------------
 * function 	:	send target_ped to target_location & wait for his arrival
* 			Will store the number of cycles it took in timer
*
*/

send_and_wait_for_ped:
	// send ped to block - travels by any means necessary to get there
	SEND_PED_TO_BLOCK( target_ped , target_location)
	// if ped hasn’t arrived at target yet, inc counter + try again next cycle
	WHILE(NOT(IS_PED_IN_BLOCK(target_ped, target_location)))
		INC(timer)
	ENDWHILE
return


//
// assasin_mission
// --------------------
// function	:	Player has to go kill a ped before ped reaches a target
//

assasin_mission:
	// order played to kill ped
	MESSAGE ( 23 )
	// create second thread that will deal with sending the target_ped to target
	// while we continue working, checking for deaths etc
	threadinfo = CREATE_THREAD send_and_wait_for_ped:

	// while ped hasn’t arrived - do this block. EXEC means it runs through ALL
	// the checks each cycle, rather than one line at a time
	WHILE_EXEC(finish == 0)
	{
		// check if target_ped has died
		IF(IS_PED_DEAD(target_ped))
			// check if player managed to kill him
			IF(DID_PLAYER_KILL_PED(target_ped))
				// congratulate player!
				MESSAGE (25)		// “Well done, you’ve killed the target”
				ADD_SCORE(10000)
				MISSION_SUCCESS	// store that we’ve succeeded a mission
				finish = 1
			ELSE
				// player didn’t kill ped, so mission failed
				MESSAGE (26)		// “You screwed up.. Still, he’s dead.”
				MISSION_FAIL		// store that we’ve failed…
				finish = 1
			ENDIF
		ENDIF

// if second thread has finished, ped reached target
IF(NOT(CHECK_THREAD_ALIVE(threadinfo)))
		// failed!
		MESSAGE(27)		// “He’s reached the base! You’ve failed”
		MISSION_FAIL
		finish = 1
ENDIF
	ENDWHILE_EXEC

	// finished mission, do clear up

	// make sure thread is killed
IF(CHECK_THREAD_ALIVE(threadinfo))
	KILL_THREAD(threadinfo)
ENDIF
return

// main game loop 
// 
// there should only ever be one ‘level_start …. Level_end’ loop in the scriptfile, and GBH will 
// automatically start the program from this line. 

level_start
	// first off, create dummy ped & target location
	target_ped = CREATE_PED ( 80.5 , 55.5 , 255.0 ) 90 4
	target_loc = CREATE_LOC (200.5 , 33.5 , 2.0 ) 1 1

	// switch on trigger - after this point, if player crosses this block, the
	// assasin_mission is started
	SWITCH_ON_TRIGGER(triggerpoint)

	// this is the main game ‘loop’ doing any basic work that needs done each cycle, or
	// general work. 
	
	// here, as an example, the level keeps running until the player runs out of lives
	WHILE ( GET_PLAYER_LIVES > 0 )
		// empty clause
	ENDWHILE
level_end
Razor
Lunatic
Lunatic
Posts: 456
Joined: 19 Jul 2008, 14:14
GH nick: Razor, R
Location: Poland / Szczecin
Contact:

Re: Missions

Post by Razor »

Hmm something is wrong here.... (scrip) but you have manual to read :)
User avatar
Gustavob
Immortal
Posts: 407
Joined: 18 May 2009, 21:40
GH nick: Gustavob
|Gustavob|
Location: Nowhere.
Contact:

Re: Missions

Post by Gustavob »

Thanks Razor but as you said there are some problems with script. I tried to fix all of them (looking for errors whithin compilation) but I couldnt fix the "Symbol zaibatsugang wasnt declared on script" error D:. BTW do you think its the Armored Car Clash! wil/Downtown mission? And also, I just wanted to know how to start the mission, I mean, the commands I need, subroutines, THREAD_TRIGGERs etc :roll: I am not sure how to use them to do this, thats just what I need for now ;p
You just lost the game.
Razor
Lunatic
Lunatic
Posts: 456
Joined: 19 Jul 2008, 14:14
GH nick: Razor, R
Location: Poland / Szczecin
Contact:

Re: Missions

Post by Razor »

ask heri he is quite good at id. i never tried to do missons before :)
Post Reply