All pastes #408778 Raw Edit

tutorial 3 part 2

public cpp v1 · immutable
#408778 ·published 2007-03-25 02:37 UTC
rendered paste body
#include <a_samp>main(){	print("\n----------------------------------");	print(" My first deathmatch mode by NAME");	print("----------------------------------\n");}#define POCKET_MONEY 500#define START_WEAPON 27#define START_AMMO 200public OnGameModeInit(){	SetGameModeText("Deathmatch");	AddPlayerClass(1, -1643.2673, -2245.1335, 31.4766, 1.2814, 7, 1, 22, 100, 0, 0); // my first character	AddPlayerClass(2, -1360.4752, -2112.6875, 30.2348, 224.2845, 6, 1, 23, 50, 0, 0); //	AddPlayerClass(121, -1740.3165, -2090.4006, 39.7106, 256.3793, 5, 1, 24, 30, 0, 0); //	AddStaticVehicle(401, -1764.6294, -2086.7019, 47.1236, 257.8369, 113, 113); // my first car	AddStaticVehicle(401, -1633.3375, -2251.4619, 28.7141, 89.0023, 113, 113); // This vehicle is parked under a roof so was dropped a bit	AddStaticVehicle(403, -1303.2861, -2121.0093, 25.5832, 176.7224, 28, 1); //	AddStaticPickup(362, 2, -1673.1672, -2165.0496, 35.7388);	return 1;}public OnPlayerRequestClass(playerid, classid){	SetPlayerPos(playerid, -1798.7191, -2270.0239, 67.1363);	SetPlayerFacingAngle(playerid, 130.0296);	SetPlayerCameraPos(playerid, -1801.9762, -2272.5999, 67.8387);	SetPlayerCameraLookAt(playerid, -1798.7191, -2270.0239, 67.1363);	return 1;}public OnPlayerRequestSpawn(playerid){	return 1;}public OnGameModeExit(){	return 1;}public OnPlayerConnect(playerid){	return 1;}public OnPlayerDisconnect(playerid){	return 1;}public OnPlayerSpawn(playerid){	// Moved in here as it's the only place it's ever used so there's no point	// having it global.	static const		Float:scSpawnPoints[][4] =		{			{-1643.2673, -2245.1335, 31.4766, 1.2814},			{-1360.4752, -2112.6875, 30.2348, 224.2845},			{-1740.3165, -2090.4006, 39.7106, 256.3793}		};	// random has problems with low numbers (lot's of sticking) so these are	// two possible solutions.  The first is useful in the order of 10, second	// is useful in the order 100 as above starts getting predictable.	new		spawn = random(sizeof (scSpawnPoints) * 1000) / 1000, // More variable		spawn2 = GetTickCount() % sizeof (scSpawnPoints); // Easy but flawed	// spawn2 is just an example so tell the compiler not to warn you about it	#pragma unused spawn2	SetPlayerPos(playerid, scSpawnPoints[spawn][0], scSpawnPoints[spawn][1], scSpawnPoints[spawn][2]);	SetPlayerFacingAngle(playerid, scSpawnPoints[spawn][3]);	GivePlayerMoney(playerid, POCKET_MONEY);	GivePlayerWeapon(playerid, START_WEAPON, 200);	// Reset the player's current checkpoint	UpdatePlayerCheckpoint(playerid, 1);	return 1;}public OnPlayerDeath(playerid, killerid, reason){	if (killerid != INVALID_PLAYER_ID)	{		GivePlayerMoney(killerid, GetPlayerMoney(playerid));	}	ResetPlayerMoney(playerid);	SendDeathMessage(killerid, playerid, reason);	return 1;}public OnVehicleSpawn(vehicleid){	return 1;}public OnVehicleDeath(vehicleid, killerid){	return 1;}public OnPlayerText(playerid, text[]){	return 1;}public OnPlayerPrivmsg(playerid, senderid, text[]){	return 1;}public OnPlayerCommandText(playerid, cmdtext[]){	return 0;}public OnPlayerInfoChange(playerid){	return 1;}public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger){	return 1;}public OnPlayerExitVehicle(playerid, vehicleid){	return 1;}public OnPlayerStateChange(playerid, newstate, oldstate){	// If they get out a car, reset their checkpoint	if (oldstate == PLAYER_STATE_DRIVER) UpdatePlayerCheckpoint(playerid, 1);	return 1;}public OnPlayerEnterCheckpoint(playerid){	// Save the players current state, more accurate than vehicle checking	new		playerState = GetPlayerState(playerid);	/*	This variable was originally called state, however that caused errors state	is a reserved keyword, you can't have varibale names the same as keywords.	*/	if (playerState == PLAYER_STATE_DRIVER) // They drove into the checkpoint	{		// Update the checkpoint and check if they've finished		if (UpdatePlayerCheckpoint(playerid))		{			GameTextForPlayer(playerid, "~b~You finished the course!", 5000, 3);			GivePlayerMoney(playerid, 2000);		}	}	else if (playerState != PLAYER_STATE_PASSENGER) // They weren't driven in	{		GameTextForPlayer(playerid, "~r~You need a vehicle for this course!", 5000, 3);	}	return 1;}public OnPlayerLeaveCheckpoint(playerid){	return 1;}UpdatePlayerCheckpoint(playerid, reset = 0){	// These variables are only needed here so only put them here	// 'static' don't change between calls	static		sPlayerCheckpoint[MAX_PLAYERS] = {0, ...};	// 'static const' don't change ever	static const		Float:scCheckpoints[][3] =		{			{-1499.4589,-2155.8435,2.5238}, // CP 1			{-1218.0668,-2341.6157,17.1324}, // CP 2			{-937.3643,-2362.1619,58.8598}, // CP 3			{-747.3038,-2411.3000,60.3993}, // CP 4			{-583.2695,-2360.5864,27.0174}, // CP 5			{-746.1542,-2665.6497,84.7455}, // CP 6			{-1175.4751,-2639.3894,11.5374}, // CP 7			{-1474.6631,-2635.9446,43.2859}, // CP 8			{-1894.4139,-2420.4565,32.2340}, // CP 9			{-1685.5549,-2292.6499,41.8054} // CP 10		};	// 'new' are reset every call	new		retval = 0,		checkpoint; // Defaults to 0	// Save the players current checkpoint to a variable for speed	// arrays take at least twice as long to process as variables	checkpoint = sPlayerCheckpoint[playerid];		// if (reset) is equivalent to if (reset == 1) but faster and more flexible	if (reset) checkpoint = 0; // They want their checkpoint resetting, reset it	else checkpoint++; // They don't so move on to the next one		if (checkpoint >= sizeof (scCheckpoints)) // If they're at the end	{		retval = 1; // Set the return value to 1 so the calling function knows		checkpoint = 0; // Reset their checkpoinr	}		// Display the new checkpoint	SetPlayerCheckpoint(playerid, scCheckpoints[checkpoint][0], scCheckpoints[checkpoint][1], scCheckpoints[checkpoint][2], 5.0);		// Save their current checkpoint to the static so it doesn't get lost	sPlayerCheckpoint[playerid] = checkpoint;		// return whether or not they've completed the course	return retval;}