[help]Drag Racing
#1

I want to allow players to challenge each other to a quatermile race on wich they can bet money (or even pink slips!).
I try to set a command "/drag" to create a check point 400m in front of the player's car.

Here is the script I know there's is alot missing but this is the core of the command when i try it it set the checpoint at 0,0,0. Also I need to figure out how adjust the Z coordinate of the checkpoint so it won't be underground or in the sky and if anyone as a betting system (ex: /dice [playerid][amount]) that would be great because it's script should the info I need to complete this.

Quote:

public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/drag", cmdtext, true, 10) == 0)
{
new float:A;
new float:deltaX;
new float:deltaY;
new float:deltaZ;
new float, float:y, float:z;
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, A);
deltaX=(floatsin(A)*400);
deltaY=(floatcos(A)*400);
SetPlayerRaceCheckpoint(playerid, 2, x+deltaX, y+deltaY, z, x+deltaX, y+deltaY, z,5);
return 1;
}
return 0;
}

Reply
#2

Ok I got it to work but only when i'm out of the car when I try it from onside the checkpoint appears at the right distance but always north of me, it's like the getplayerfacingangle doesn't register when in a car.

Here are my new codes
Код:
//GET X Y IN FRONT OR BEHIND----------------------------------------------------
stock GetXYInFrontOfPlayer(playerid,&Float:x,&Float:y,Float:dis)
{
new float:pos[3];
new float:A;
GetPlayerPos(playerid,pos[0],pos[1],pos[2]);
GetPlayerFacingAngle(playerid,A);
GetXYInFrontOfPoint(pos[0],pos[1],x,y,A,dis);
}

stock GetXYBehindPlayer(playerid,&Float:x,&Float:y,Float:dis)
{
new float:pos[3];
new float:A;
GetPlayerPos(playerid,pos[0],pos[1],pos[2]);
GetPlayerFacingAngle(playerid,A);
GetXYBehindPoint(pos[0],pos[1],x,y,A,dis);
}

stock GetXYInFrontOfPoint(Float:x,Float:y,&Float:x2,&Float:y2,Float:A,Float:distance)
{
x2 = x + (distance * floatsin(-A,degrees));
y2 = y + (distance * floatcos(-A,degrees));
}

stock GetXYBehindPoint(Float:x,Float:y,&Float:x2,&Float:y2,Float:A,Float:distance)
{
x2 = x - (distance * floatsin(-A,degrees));
y2 = y - (distance * floatcos(-A,degrees));
}
//------------------------------------------------------------------------------
Код:
if (strcmp("/drag", cmdtext, true, 5) == 0)//this should set a checkpoint 400m in front of player vehicle
	{
	new float:x, float:y, float:z, float:X, float:Y;
	GetXYInFrontOfPlayer(playerid,X,Y,400);
	GetPlayerPos(playerid,x,y,z);
	SetPlayerCheckpoint(playerid,X,Y,z,5);
	return 1;
	}
Reply
#3

edit
Код:
stock GetXYInFrontOfPlayer(playerid,&Float:x,&Float:y,Float:dis)
{ new float:pos[3];
new float:A;
GetPlayerPos(playerid,pos[0],pos[1],pos[2]);
GetPlayerFacingAngle(playerid,A);
GetXYInFrontOfPoint(pos[0],pos[1],x,y,A,dis);
}
to
Код:
stock GetXYInFrontOfPlayer(playerid,&Float:x,&Float:y,Float:dis)
{ new float:pos[3];
new float:A;
GetPlayerPos(playerid,pos[0],pos[1],pos[2]);
if(GetPlayerVehicleID(playerid))
GetVehicleAngelZ(GetPlayerVehicleID(playerid),A);
else
GetPlayerFacingAngle(playerid,A);
GetXYInFrontOfPoint(pos[0],pos[1],x,y,A,dis);
}
Reply
#4

Thx yezizhu your script is very good(compact & effective), but I fixed it by creating a custom function wich I'll be able to use at any time for other commands.

I searched the forum and tutorials for 2 days to figure how to put something in front of a player and I've realized that this is something every new scripter will strugle with. So, here's how I did it. Now I should thx every one that helped by sharing info but at the moment I need to sort out the bits of code and where they came from. I will give credits to the people that helped later on.

Put this somewhere at the bottom of your script, make sure it's not in any callback or function ( between two: [])
Код:
//GET X Y IN FRONT OR BEHIND PLAYER---------------------------------------------
stock GetXYInFrontOfPlayer(playerid,&Float:x,&Float:y,Float:dis)
{
new float:pos[3];
new float:A;
GetPlayerPos(playerid,pos[0],pos[1],pos[2]);
GetPlayerFacingAngle(playerid,A);
GetXYInFrontOfPoint(pos[0],pos[1],x,y,A,dis);
}

stock GetXYBehindPlayer(playerid,&Float:x,&Float:y,Float:dis)
{
new float:pos[3];
new float:A;
GetPlayerPos(playerid,pos[0],pos[1],pos[2]);
GetPlayerFacingAngle(playerid,A);
GetXYBehindPoint(pos[0],pos[1],x,y,A,dis);
}

//GET X Y IN FRONT/BEHIND/LEFT/RIGHT OF POINT-----------------------------------

stock GetXYInFrontOfPoint(Float:x,Float:y,&Float:x2,&Float:y2,Float:A,Float:distance)
{
x2 = x + (distance * floatsin(-A,degrees));
y2 = y + (distance * floatcos(-A,degrees));
}

stock GetXYBehindPoint(Float:x,Float:y,&Float:x2,&Float:y2,Float:A,Float:distance)
{
x2 = x - (distance * floatsin(-A,degrees));
y2 = y - (distance * floatcos(-A,degrees));
}

stock GetXYLeftOfPoint(Float:x,Float:y,&Float:x2,&Float:y2,Float:A,Float:distance)
{
x2 = x - (distance * floatsin(-A-90.0,degrees));
y2 = y - (distance * floatcos(-A-90.0,degrees));
}

stock GetXYRightOfPoint(Float:x,Float:y,&Float:x2,&Float:y2,Float:A,Float:distance)
{
x2 = x - (distance * floatsin(-A+90.0,degrees));
y2 = y - (distance * floatcos(-A+90.0,degrees));
}

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

//GET X Y IN FRONT OR BEHIND OF VEHICLE-----------------------------------------
stock GetXYInFrontOfVehicle(playerid,&Float:x,&Float:y,Float:dis)
{
new currentveh;
new float:pos[3];
new float:A;
currentveh = GetPlayerVehicleID(playerid);
GetVehiclePos(currentveh,pos[0],pos[1],pos[2]);
GetVehicleZAngle(currentveh,A);
GetXYInFrontOfPoint(pos[0],pos[1],x,y,A,dis);
}

stock GetXYBehindVehicle(playerid,&Float:x,&Float:y,Float:dis)
{
new currentveh;
new float:pos[3];
new float:A;
currentveh = GetPlayerVehicleID(playerid);
GetVehiclePos(currentveh,pos[0],pos[1],pos[2]);
GetVehicleZAngle(currentveh,A);
GetXYBehindPoint(pos[0],pos[1],x,y,A,dis);
}
//------------------------------------------------------------------------------
To spawn something in front, behind, on the left or on the right you can now use the GetXY...OfPlayer() or GetXY...OfVehicle() functions just choose the distance between the player and the spawn point and use these coordinate in the code, like this:
Код:
{
	new currentveh;
	new float:x, float:y, float:z, float:X, float:Y;
	currentveh = GetPlayerVehicleID(playerid);
	GetXYInFrontOfVehicle(playerid,X,Y,400);
	GetVehiclePos(currentveh,x,y,z);
	SetPlayerCheckpoint(playerid,X,Y,z,10);
	return 1;
}
Enjoy!! & keep me posted :P
Reply
#5

bahaaa, post in useful function.
You done the job, nice!
Reply
#6

My first script is almost done! but I get 3 errors when I try to compile can some1 help plz
The Errors:
C:\Program Files\Rockstar Games\GTA San Andreas\samp02Xserver.win32\gamemodes\test1.pwn(17 9) : error 055: start of function body without function header
C:\Program Files\Rockstar Games\GTA San Andreas\samp02Xserver.win32\gamemodes\test1.pwn(18 0) : error 010: invalid function or declaration
C:\Program Files\Rockstar Games\GTA San Andreas\samp02Xserver.win32\gamemodes\test1.pwn(18 1) : error 010: invalid function or declaration
C:\Program Files\Rockstar Games\GTA San Andreas\samp02Xserver.win32\gamemodes\test1.pwn(56 5) : warning 203: symbol is never used: "dcmd_drag0"

The Code:
Код:
public OnPlayerCommandText(playerid, cmdtext[])
//DRAG RACE---------------------------------------------------------------------
//******************************************************************************
{
  dcmd(drag,4, cmdtext);
  return 0;
}

dcmd_drag (playerid, params[]) //line 137
{
	new targetid, bet;
	if (sscanf(params, "ui", targetid,bet)) SendClientMessage(playerid, COLOR_RED, "Usage: /drag <playerid> <bet>");
	else if (targetid == INVALID_PLAYER_ID) SendClientMessage(playerid, COLOR_RED, "Player not found");
  else if (bet > GetPlayerMoney(playerid)) SendClientMessage(playerid, COLOR_RED, "Insufficient Funds");
	else
	{
		new str[128];
		new name[32];
		GetPlayerName(playerid,name,32);
		format(str,sizeof(str),"%s has challenged you to a 1/4 mile race betting %i$! Do you accept?(/drag0)",name,bet);
		SendClientMessage(targetid,COLOR_YELLOW,str);
		SetChallengerValue(playerid);
		SetChallengerVehValue(playerid);
		SetStakesValue(playerid);
	}
		
	return 1;
}
//DRAG ACCEPT-------------------------------------------------------------------
{//line 179
  dcmd(drag0,5,cmdtext);//line 180
  return 0;//line 181
}

dcmd_drag0 (playerid, params[])
	{
	  #pragma unused params
		new currentveh;
		new float:x, float:y, float:z, float:X, float:Y, float:a, float:b, float:c, float:d;
		currentveh = GetPlayerVehicleID(playerid);
		GetXYInFrontOfVehicle(challenger,X,Y,400);
    GetXYLeftOfVehicle(challenger[playerid],a,b,3);
    GetXYLeftOfVehicle(challenger[playerid],c,d,3);
		GetVehiclePos(challengerveh,x,y,z);
		SetPlayerRaceCheckpoint(challenger[playerid],1,X,Y,z,X,Y,z,10);
		SetPlayerRaceCheckpoint(playerid,1,X,Y,z,X,Y,z,10);
		SetVehiclePos(challengerveh[playerid],a,b,z);
		SetVehiclePos(currentveh,c,d,z);
 	}
Reply
#7

Код:
dcmd(drag0,5,cmdtext)
should add in OnPlayerCommandText
Reply
#8

Thx now it compile but when I tested it with my friend it kinda worked the first time but when he tried to challenge me he spawned without his car then he crashed

I think it has something to do with how I indexed my arrays
Код:
//PUBLIC ARRAYS & VARS----------------------------------------------------------

new targetid, bet;

new challenger[MAX_PLAYERS];
SetChallengerValue(playerid, value)
{
	challenger[targetid] = playerid;
}

new challengerveh[MAX_PLAYERS];
SetChallengerVehValue(playerid, value)
{
	challengerveh[targetid] = GetPlayerVehicleID(playerid);
}

new stakes[MAX_PLAYERS];
SetStakesValue(playerid, value)
{
	stakes[targetid] = bet;
}
Reply
#9

It seems no problem here, are you sure player crashed when using the command?
Reply
#10

Yes I"m sure it crashed when he used the command but since then I've edited the script so it reset the arrays after a race. Is there anything like a checkpoint id so that when I use the OnPlayerEnterRaceCheckpoint callback to declare the winner it doesn't conflict with other races going on?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)