[Ayuda] Buenas necesito saber hacer una cosa
#1

Buenas estoy creando un server y tengo aсadido un sistema de drift que segun vayas derrapando vas haciendo unos puntos que se multiplican por el bonus y ganas algo de dinero derrapando. La cuestion es que quiero que solo se muestre o funcione este sistema cuando se utilize el comando /drift que activara y desactivara el sistema drift y como no entiendo el sistema de drift nose como hacerlo.

Aquн os muestro el codigo del sistema:

Код:
/* SISTEMA DE DRIFT */
#define DRIFT_MINKAT 10.0
#define DRIFT_MAXKAT 90.0
#define DRIFT_SPEED 30.0
#define COLOR_Label 0xFFFFFFFF
#define COLOR_LabelOut 0x00000040
#define COLOR_ValueOut 0xFFFFFF40
#define COLOR_Value 0x000000FF

/* SISTEMA DE DRIFT */
new DriftTimer[MAX_PLAYERS];
new DriftPointsNow[MAX_PLAYERS];
new PlayerDriftCancellation[MAX_PLAYERS];
new Float:ppos[MAX_PLAYERS][3];
enum Float:Pos{ Float:sX,Float:sY,Float:sZ };
new Float:SavedPos[MAX_PLAYERS][Pos];
new bool:DriftMode[MAX_PLAYERS]=false;
new DriftBonus[MAX_PLAYERS]=1;
new Float:HealthInit[MAX_PLAYERS]=1000.0;
new bool:AutoFixBool[MAX_PLAYERS]=true;
new Text:TDLabels[10];
new Text:TDValueDrift[MAX_PLAYERS];
new Text:TDValueBonus[MAX_PLAYERS];
new Text:TDValueCash[MAX_PLAYERS];

forward Drift();
forward AngleUpdate();
forward DriftExit(playerid);
forward CheckPlayerState();
forward AutoFix();

public OnGameModeInit()
{
SetTimer("AngleUpdate", 200, true);
SetTimer("AutoFix", 500, true);
SetTimer("CheckPlayerState", 100, true);

for(new i; i < GetMaxPlayers(); i ++)
{
TDLabels[0] = TextDrawCreate(38.000000, 178.000000, " ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ");
TextDrawBackgroundColor(TDLabels[0], 255);
TextDrawFont(TDLabels[0], 3);
TextDrawLetterSize(TDLabels[0], 0.389999, 1.000000);
TextDrawColor(TDLabels[0], -1);
TextDrawSetOutline(TDLabels[0], 1);
TextDrawSetProportional(TDLabels[0], 1);
TextDrawUseBox(TDLabels[0], 1);
TextDrawBoxColor(TDLabels[0], 99);
TextDrawTextSize(TDLabels[0], 141.000000, 40.000000);

TDLabels[1] = TextDrawCreate(42.000000, 184.000000, " ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ~n~ ");
TextDrawBackgroundColor(TDLabels[1], 255);
TextDrawFont(TDLabels[1], 3);
TextDrawLetterSize(TDLabels[1], 0.389999, 1.000000);
TextDrawColor(TDLabels[1], -1);
TextDrawSetOutline(TDLabels[1], 1);
TextDrawSetProportional(TDLabels[1], 1);
TextDrawUseBox(TDLabels[1], 1);
TextDrawBoxColor(TDLabels[1], 99);
TextDrawTextSize(TDLabels[1], 137.000000, 38.000000);

TDLabels[2] = TextDrawCreate(41.000000, 169.000000, "~p~Drifting");
TextDrawBackgroundColor(TDLabels[2], 255);
TextDrawFont(TDLabels[2], 3);
TextDrawLetterSize(TDLabels[2], 0.699999, 2.000000);
TextDrawColor(TDLabels[2], -1);
TextDrawSetOutline(TDLabels[2], 1);
TextDrawSetProportional(TDLabels[2], 1);

TDLabels[3] = TextDrawCreate(48.000000, 190.000000, "~w~---------------------");
TextDrawBackgroundColor(TDLabels[3], 255);
TextDrawFont(TDLabels[3], 2);
TextDrawLetterSize(TDLabels[3], 0.300000, 1.000000);
TextDrawColor(TDLabels[3], -1);
TextDrawSetOutline(TDLabels[3], 1);
TextDrawSetProportional(TDLabels[3], 1);

TDLabels[4] = TextDrawCreate(42.000000, 201.000000, "~r~Puntos Drift:");
TextDrawBackgroundColor(TDLabels[4], 255);
TextDrawFont(TDLabels[4], 2);
TextDrawLetterSize(TDLabels[4], 0.310000, 1.200000);
TextDrawColor(TDLabels[4], -1);// asdasd
TextDrawSetOutline(TDLabels[4], 1);
TextDrawSetProportional(TDLabels[4], 1);

TDLabels[5] = TextDrawCreate(48.000000, 230.000000, "~w~---------------------");
TextDrawBackgroundColor(TDLabels[5], 255);
TextDrawFont(TDLabels[5], 2);
TextDrawLetterSize(TDLabels[5], 0.300000, 1.000000);
TextDrawColor(TDLabels[5], -1);
TextDrawSetOutline(TDLabels[5], 1);
TextDrawSetProportional(TDLabels[5], 1);

TDLabels[6] = TextDrawCreate(46.000000, 241.000000, "~b~Bonus Drift:");
TextDrawBackgroundColor(TDLabels[6], 255);
TextDrawFont(TDLabels[6], 2);
TextDrawLetterSize(TDLabels[6], 0.310000, 1.200000);
TextDrawColor(TDLabels[6], -1);
TextDrawSetOutline(TDLabels[6], 1);
TextDrawSetProportional(TDLabels[6], 1);

TDLabels[7] = TextDrawCreate(48.000000, 271.000000, "~w~---------------------");
TextDrawBackgroundColor(TDLabels[7], 255);
TextDrawFont(TDLabels[7], 2);
TextDrawLetterSize(TDLabels[7], 0.300000, 1.000000);
TextDrawColor(TDLabels[7], -1);
TextDrawSetOutline(TDLabels[7], 1);
TextDrawSetProportional(TDLabels[7], 1);

TDLabels[8] = TextDrawCreate(49.000000, 282.000000, "~g~Valor Drift:");
TextDrawBackgroundColor(TDLabels[8], 255);
TextDrawFont(TDLabels[8], 2);
TextDrawLetterSize(TDLabels[8], 0.310000, 1.200000);
TextDrawColor(TDLabels[8], -1);
TextDrawSetOutline(TDLabels[8], 1);
TextDrawSetProportional(TDLabels[8], 1);

TDLabels[9] = TextDrawCreate(48.000000, 312.000000, "---------------------");
TextDrawBackgroundColor(TDLabels[9], 255);
TextDrawFont(TDLabels[9], 2);
TextDrawLetterSize(TDLabels[9], 0.300000, 1.000000);
TextDrawColor(TDLabels[9], -1);
TextDrawSetOutline(TDLabels[9], 1);
TextDrawSetProportional(TDLabels[9], 1);

TDValueDrift[i]=TextDrawCreate(68.000000, 217.000000," ~w~0");
TextDrawColor(TDValueDrift[i],255);
TextDrawSetShadow(TDValueDrift[i],0);
TextDrawSetOutline(TDValueDrift[i],1);
TextDrawLetterSize(TDValueDrift[i],0.500000, 1.199998);
TextDrawBackgroundColor(TDValueDrift[i],COLOR_ValueOut);
TextDrawFont(TDValueDrift[i],3);

TDValueBonus[i]=TextDrawCreate(68.000000, 257.000000," ~w~X1");
TextDrawColor(TDValueBonus[i],255);
TextDrawSetShadow(TDValueBonus[i],0);
TextDrawSetOutline(TDValueBonus[i],1);
TextDrawLetterSize(TDValueBonus[i],0.500000, 1.199998);
TextDrawBackgroundColor(TDValueBonus[i],COLOR_ValueOut);
TextDrawFont(TDValueBonus[i],3);

TDValueCash[i]=TextDrawCreate(68.000000,298.000000,"~w~$0");
TextDrawColor(TDValueCash[i],255);
TextDrawSetShadow(TDValueCash[i],0);
TextDrawSetOutline(TDValueCash[i],1);
TextDrawLetterSize(TDValueCash[i],0.500000, 1.199998);
TextDrawBackgroundColor(TDValueCash[i],COLOR_ValueOut);
TextDrawFont(TDValueCash[i],3);

return 1;
}

public DriftExit(playerid)
{ // By Luby
PlayerDriftCancellation[playerid] = 0;
new Float:h;
GetVehicleHealth(GetPlayerVehicleID(playerid),h);
if(DriftPointsNow[playerid]>50 && DriftPointsNow[playerid]<99000 && h==HealthInit[playerid]) GivePlayerCash(playerid,DriftPointsNow[playerid]*DriftBonus[playerid]);
TextDrawHideForPlayer(playerid,TDLabels[0]);
TextDrawHideForPlayer(playerid,TDLabels[1]);
TextDrawHideForPlayer(playerid,TDLabels[2]);
TextDrawHideForPlayer(playerid,TDLabels[3]);
TextDrawHideForPlayer(playerid,TDLabels[4]);
TextDrawHideForPlayer(playerid,TDLabels[5]);
TextDrawHideForPlayer(playerid,TDLabels[6]);
TextDrawHideForPlayer(playerid,TDLabels[7]);
TextDrawHideForPlayer(playerid,TDLabels[8]);
TextDrawHideForPlayer(playerid,TDLabels[9]);
TextDrawHideForPlayer(playerid,TDValueDrift[playerid]);
TextDrawHideForPlayer(playerid,TDValueBonus[playerid]);
TextDrawHideForPlayer(playerid,TDValueCash[playerid]);
DriftBonus[playerid]=1;
AutoFixBool[playerid]=true;
SetVehicleHealth(GetPlayerVehicleID(playerid),HealthInit[playerid]);
DriftPointsNow[playerid] = 0;
}

Float:ReturnPlayerAngle(playerid)
{
new Float:Ang;
if(IsPlayerInAnyVehicle(playerid))GetVehicleZAngle(GetPlayerVehicleID(playerid), Ang); else GetPlayerFacingAngle(playerid, Ang);
return Ang;
}

public Drift()
{
new Float:Angle1, Float:Angle2, Float:BySpeed;
new Float:Z;
new Float:X;
new Float:Y;
new Float:SpeedX;
for(new g=0;g<200;g++)
{
GetPlayerPos(g, X, Y, Z);
SpeedX = floatsqroot(floatadd(floatadd(floatpower(floatabs(floatsub(X,SavedPos[ g ][ sX ])),2),floatpower(floatabs(floatsub(Y,SavedPos[ g ][ sY ])),2)),floatpower(floatabs(floatsub(Z,SavedPos[ g ][ sZ ])),2)));
Angle1 = ReturnPlayerAngle(g);
Angle2 = GetPlayerTheoreticAngle(g);
BySpeed = floatmul(SpeedX, 12);
if(IsPlayerInAnyVehicle(g) && GetVType(GetPlayerVehicleID(g)) && floatabs(floatsub(Angle1, Angle2)) > DRIFT_MINKAT && floatabs(floatsub(Angle1, Angle2)) < DRIFT_MAXKAT && BySpeed > DRIFT_SPEED){
if(PlayerDriftCancellation[g] > 0)KillTimer(PlayerDriftCancellation[g]);
PlayerDriftCancellation[g] = 0;
DriftPointsNow[g] += floatval( floatabs(floatsub(Angle1, Angle2)) * 3 * (BySpeed*0.1) )/25;
PlayerDriftCancellation[g] = SetTimerEx("DriftExit", 3000, 0, "d", g);
if(DriftPointsNow[g] > 70 && DriftPointsNow[g]<10000)
{
if(DriftPointsNow[g]<500)
{
DriftBonus[g]=1;
}
if(DriftPointsNow[g]>=500 && DriftPointsNow[g]<1000)
{
DriftBonus[g]=2;
}
if(DriftPointsNow[g]>=1000 && DriftPointsNow[g]<1700)
{
DriftBonus[g]=3;
}
if(DriftPointsNow[g]>=1700 && DriftPointsNow[g]<2500)
{
DriftBonus[g]=4;
}
if(DriftPointsNow[g]>=2500)
{
DriftBonus[g]=5;
}
TextDrawShowForPlayer(g,TDLabels[0]);
TextDrawShowForPlayer(g,TDLabels[1]);
TextDrawShowForPlayer(g,TDLabels[2]);
TextDrawShowForPlayer(g,TDLabels[3]);
TextDrawShowForPlayer(g,TDLabels[4]);
TextDrawShowForPlayer(g,TDLabels[5]);
TextDrawShowForPlayer(g,TDLabels[6]);
TextDrawShowForPlayer(g,TDLabels[7]);
TextDrawShowForPlayer(g,TDLabels[8]);
TextDrawShowForPlayer(g,TDLabels[9]);
TextDrawShowForPlayer(g,TDValueDrift[g]);
TextDrawShowForPlayer(g,TDValueBonus[g]);
TextDrawShowForPlayer(g,TDValueCash[g]);
new DPs[128],DBn[128],Cash[128],csh;
valstr(DPs,DriftPointsNow[g],false);
format(DBn,sizeof(DBn),"X%i",DriftBonus[g]);
csh=DriftPointsNow[g]*DriftBonus[g];
format(Cash,sizeof(Cash),"$%i",csh);
TextDrawSetString(TDValueDrift[g],DPs);
TextDrawSetString(TDValueBonus[g],DBn);
TextDrawSetString(TDValueCash[g],Cash);
}
SavedPos[ g ][ sX ] = X;
SavedPos[ g ][ sY ] = Y;
SavedPos[ g ][ sZ ] = Z;
}
}
}

public AngleUpdate()
{
for(new g=0;g<=MAX_PLAYERS;g++)
{
new Float:x, Float:y, Float:z;
if(IsPlayerInAnyVehicle(g))GetVehiclePos(GetPlayerVehicleID(g), x, y, z); else GetPlayerPos(g, x, y, z);
ppos[g][0] = x;
ppos[g][1] = y;
ppos[g][2] = z;
}
}

floatval(Float:val)
{
new str[256];
format(str, 256, "%.0f", val);
return todec(str);
}

todec(str[])
{
return strval(str);
}

public CheckPlayerState()
{
new i,cs;
for(i=0;i<=MAX_PLAYERS;i++)
{
cs=GetPlayerState(i);
if(DriftMode[i] && cs==PLAYER_STATE_DRIVER && DriftPointsNow[i]>70)
{
new Float:h;
GetVehicleHealth(GetPlayerVehicleID(i),h);
if(h<HealthInit[i]){
KillTimer(DriftTimer[i]);
DriftExit(i);
GameTextForPlayer(i,"~n~~n~~n~~n~~n~~r~Chocaste!!!",800,5);
DriftMode[i]=false;
}
}
if(cs==PLAYER_STATE_DRIVER && DriftMode[i]==false)
{
if(GetVType(GetPlayerVehicleID(i)))
{
DriftMode[i]=true;
GetVehicleHealth(GetPlayerVehicleID(i),HealthInit[i]);
AutoFixBool[i]=false;
DriftTimer[i]=SetTimerEx("Drift", 200, true, "i", i);
}
}
else if(cs!=PLAYER_STATE_DRIVER && DriftMode[i]==true)
{
KillTimer(DriftTimer[i]);
DriftMode[i]=false;
AutoFixBool[i]=true;// true
}
else
{
}
}
return 1;
}

public AutoFix()
{
new i;
for(i=0;i<=MAX_PLAYERS;i++)
{
if(AutoFixBool[i] && IsPlayerInAnyVehicle(i))
{
SetVehicleHealth(GetPlayerVehicleID(i),HealthInit[i]);
}
}
}

GetVType(vid)
{
new Convertibles[4]={480, 533, 439, 555};
new Industrial[26]={499, 422, 482, 498, 609, 524, 578, 455, 403, 414, 582, 443, 514, 413, 515, 440, 543, 605, 459, 531, 408, 552, 478, 456, 554};
new LowRider[8]={536, 575, 534, 567, 535, 566, 576, 412};
new OffRoad[13]={568, 424, 573, 579, 400, 500, 444, 556, 557, 470, 489, 505, 595};
new Service[19]={416, 433, 431, 438, 437, 523, 427, 490, 528, 407, 544, 596, 596, 597, 598, 599, 432, 601, 420};
new Saloon[35]={445, 504, 401, 518, 527, 542, 507, 562, 585, 419, 526, 604, 466, 492, 474, 546, 517, 410, 551, 516, 467, 600, 426, 436, 547, 405, 580, 560, 550, 549, 540, 491, 529, 421};
new Sports[20]={602, 429, 496, 402, 541, 415, 589, 587, 565, 494, 502, 503, 411, 559, 603, 475, 506, 451, 558, 477};
new Wagons[5]={418, 404, 479, 458, 561};
new modelid=GetVehicleModel(vid);
new i;
for(i=0;i<3;i++)
{
if(Convertibles[i]==modelid) return 1;
}
for(i=0;i<25;i++)
{
if(Industrial[i]==modelid) return 1;
}
for(i=0;i<7;i++)
{
if(LowRider[i]==modelid) return 1;
}
for(i=0;i<12;i++){
if(OffRoad[i]==modelid) return 1;
}
for(i=0;i<19;i++)
{
if(Service[i]==modelid) return 1;
}
for(i=0;i<35;i++)
{
if(Saloon[i]==modelid) return 1;
}
for(i=0;i<20;i++)
{
if(Sports[i]==modelid) return 1;
}
for(i=0;i<5;i++)
{
if(Wagons[i]==modelid) return 1;
}
return 0;
}
Eso es todo el codigo me gustaria activarlo y desactivarlo con este comando.

Код:
CMD:drift(playerid, params[])
{
if(Jugador[playerid][jGod] == 1) return SendClientMessage(playerid,Rojo, "Necesitas tener el modo dios para activar el modo drift.");
if(ModoDerrape[playerid] == false)
{
GameTextForPlayer(playerid, "~g~~h~modo drift~n~activado", 3500, 5);
SendClientMessage(playerid,Blanco,"Has activado el modo drift, ahora puntuaras derrapando.");
ModoDerrape[playerid] = true;
}
else
{
GameTextForPlayer(playerid, "~g~~h~modo drift~n~desactivado", 3500, 5);
SendClientMessage(playerid,Blanco,"Has desactivado el modo drift, ahora no puntuaras derrapando.");
ModoDerrape[playerid] = false;
}
return 1;
}
Gracias y Saludos
Reply
#2

te doy una explicaciуn ya que se me hace dificil leer ese codigo puesto de una manera muy mal ordenada, te recomiendo que uses tabulaciones para poder comprender el cуdigo mejor o procura que cuando muestres el codigo en el foro se vea con tabulaciones si es que las tenнas en el cуdigo de tu editor, bien..

he visto que haz creado una variable "ModoDerrape[MAX_PLAYERS]" y este hace de interrecutor, entonces estarнa fбcil, solo tendrнas que hacer una condicional en el momento en que la funciуn del Drift se pone en marcha...

Edit: (Me he tomado el tiempo xD de ver tu codigo) serнa en esta parte..
Код:
public Drift()
{
	new Float:Angle1, Float:Angle2, Float:BySpeed;
	new Float:Z;
	new Float:X;
	new Float:Y;
	new Float:SpeedX;
	for(new g=0;g<200;g++)
	{
		if(IsPlayerConnected(g) && ModoDerrape[g]) //<--- esta lнnea aсadida
		{
			GetPlayerPos(g, X, Y, Z);
			..///// ETC CODIGO
Reply
#3

lo siento mucho por lo de mal ordenado tengo todo el gm asн xd, gracias te lo agradesco mucho mucho mucho el tiempo que le has dedicado y eh de decirte que funciona muy bien gracias por tu ayuda
Reply
#4

Quote:
Originally Posted by punkserver
Посмотреть сообщение
lo siento mucho por lo de mal ordenado tengo todo el gm asн xd, gracias te lo agradesco mucho mucho mucho el tiempo que le has dedicado y eh de decirte que funciona muy bien gracias por tu ayuda
fueron 5 segundos asн que de nada xDD (solo que vi el cуdigo asн y me dio pereza al principio)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)