I think switch statements dont work in your threat plugin?
proof:
pawn Код:
#if defined USE_MULTI_THREAD
enum gTpos
{
Float:X,
Float:Y,
Float:Z,
Float:Angle1,
Float:Angle2,
Points,
Timer
}
new GlobalPos[MAX_PLAYERS][gTpos];// USED ONLY IN THE THREAD except Timer and Points!
forward DriftingUpdate(threadid);
public DriftingUpdate(threadid)
{
for(new playerid; playerid < MAX_PLAYERS; playerid++)
{
if(IsPlayerConnected(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new PlayerVehicleID = GetPlayerVehicleID(playerid);
new PlayerVehicleModelID = GetVehicleModel(PlayerVehicleID);
new Float:floatdata[11];
//switch(PlayerVehicleModelID)
//{
// case 443,448,461 .. 463,521 .. 523,581,586,481,509,510,430,446,452 .. 454,472,473,484,493,595,417,425,447,465,469,487,488,497,501,548,563,406,444,556,557,573,460,464,476,511 .. 513,519,520,539,553,577,592,593,471:
// {
new Float:SpeedX, Float:SpeedY, Float:SpeedZ;
GetVehicleVelocity(PlayerVehicleID, SpeedX, SpeedY, SpeedZ);
floatdata[10] = floatmul(floatsqroot((floatpower(SpeedX, 2.0)+floatpower(SpeedY, 2.0)+floatpower(SpeedZ, 2.0))), 274.0);
GetVehicleZAngle(PlayerVehicleID, GlobalPos[playerid][Angle1]);
GetPlayerPos(playerid,floatdata[4],floatdata[5],floatdata[6]);
floatdata[1] = floatsqroot(floatpower(floatsub(floatdata[4],GlobalPos[playerid][X]),2)+floatpower(floatsub(floatdata[5],GlobalPos[playerid][Y]),2));
GetVehicleZAngle(PlayerVehicleID, floatdata[3]);
if(floatdata[4]>GlobalPos[playerid][X]){floatdata[7]=floatdata[4]-GlobalPos[playerid][X];}else{floatdata[7]=GlobalPos[playerid][X]-floatdata[4];}
if(floatdata[5]>GlobalPos[playerid][Y]){floatdata[8]=floatdata[5]-GlobalPos[playerid][Y];}else{floatdata[8]=GlobalPos[playerid][Y]-floatdata[5];}
if(GlobalPos[playerid][Y]>floatdata[5] && GlobalPos[playerid][X]>floatdata[4]){ //1
floatdata[0] = asin(floatdata[7]/floatdata[1]);
floatdata[9] = floatsub(floatsub(floatadd(floatdata[0], 90), floatmul(floatdata[0], 2)), -90.0);
}
if(GlobalPos[playerid][Y]<floatdata[5] && GlobalPos[playerid][X]>floatdata[4]){ //2
floatdata[0] = asin(floatdata[7]/floatdata[1]);
floatdata[9] = floatsub(floatadd(floatdata[0], 180), 180.0);
}
if(GlobalPos[playerid][Y]<floatdata[5] && GlobalPos[playerid][X]<floatdata[4]){ //3
floatdata[0] = acos(floatdata[8]/floatdata[1]);
floatdata[9] = floatsub(floatadd(floatdata[0], 360), floatmul(floatdata[0], 2));
}
if(GlobalPos[playerid][Y]>floatdata[5] && GlobalPos[playerid][X]<floatdata[4]){ //4
floatdata[0] = asin(floatdata[7]/floatdata[1]);
floatdata[9] = floatadd(floatdata[0], 180);
}
if(floatdata[9] == 0.0)
{
GlobalPos[playerid][Angle2] = floatdata[3];
} else {
GlobalPos[playerid][Angle2] = floatdata[9];
}
new Float:angle = floatabs(GlobalPos[playerid][Angle1]-GlobalPos[playerid][Angle2]);
if(90.0 > angle > 12.5 && floatdata[10] > 10.0)
{
if(GlobalPos[playerid][Timer] != -1)KillTimer(GlobalPos[playerid][Timer]);
GlobalPos[playerid][Timer] = -1;
GlobalPos[playerid][Points] += floatround(angle * floatdata[10] / 3);
GlobalPos[playerid][Timer] = SetTimerEx("DriftCancel", 2000, 0, "d", playerid);
}
//}
//}
GetPlayerPos(playerid,GlobalPos[playerid][X],GlobalPos[playerid][Y],GlobalPos[playerid][Z]);
}
}
SleepThread(100);
}
forward DriftCancel(playerid);
public DriftCancel(playerid)
{
//do something with the points
GameTextFormatForPlayer(playerid, "Drift ended with %d points!", 1500, 1, GlobalPos[playerid][Points]);
//
GlobalPos[playerid][Timer] = (-1);
GlobalPos[playerid][Points] = 0;
return 1;
}
#endif
I have commented it out to test if the script itself works,...
I try to look if something is wrong with my code and update my post.
BTW works nice! NO LAGS AT ALL!
and this randomly crashesh the server when you drift:
pawn Код:
#if defined USE_MULTI_THREAD
enum gTpos
{
Float:X,
Float:Y,
Float:Z,
Float:Angle1,
Float:Angle2,
Points,
Timer
}
new Text:PlayerTextDraw[MAX_PLAYERS];
forward DU_OnGameModeInit();
public DU_OnGameModeInit()
{
for(new x=0;x<MAX_PLAYERS;x++)
{
PlayerTextDraw[x] = Text:TextDrawCreate(7.0, 300.0, " ");
TextDrawColor(PlayerTextDraw[x], 0x3355FFFF);
TextDrawFont(PlayerTextDraw[x], 1);
TextDrawSetShadow(PlayerTextDraw[x], 0);
TextDrawSetOutline(PlayerTextDraw[x], 1);
TextDrawAlignment(PlayerTextDraw[x], 0);
TextDrawLetterSize(PlayerTextDraw[x], 0.4, 0.8);
}
return 1;
}
new GlobalPos[MAX_PLAYERS][gTpos];// USED ONLY IN THE THREAD , no exceptions!
forward DriftingUpdate(threadid);
public DriftingUpdate(threadid)
{
for(new playerid; playerid < MAX_PLAYERS; playerid++)
{
if(IsPlayerConnected(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new PlayerVehicleID = GetPlayerVehicleID(playerid);
//new PlayerVehicleModelID = GetVehicleModel(PlayerVehicleID);
new Float:floatdata[11];
//switch(PlayerVehicleModelID)
//{
// case 443,448,461 .. 463,521 .. 523,581,586,481,509,510,430,446,452 .. 454,472,473,484,493,595,417,425,447,465,469,487,488,497,501,548,563,406,444,556,557,573,460,464,476,511 .. 513,519,520,539,553,577,592,593,471:
// {
new Float:SpeedX, Float:SpeedY, Float:SpeedZ;
GetVehicleVelocity(PlayerVehicleID, SpeedX, SpeedY, SpeedZ);
floatdata[10] = floatmul(floatsqroot((floatpower(SpeedX, 2.0)+floatpower(SpeedY, 2.0)+floatpower(SpeedZ, 2.0))), 274.0);
GetVehicleZAngle(PlayerVehicleID, GlobalPos[playerid][Angle1]);
GetPlayerPos(playerid,floatdata[4],floatdata[5],floatdata[6]);
floatdata[1] = floatsqroot(floatpower(floatsub(floatdata[4],GlobalPos[playerid][X]),2)+floatpower(floatsub(floatdata[5],GlobalPos[playerid][Y]),2));
GetVehicleZAngle(PlayerVehicleID, floatdata[3]);
if(floatdata[4]>GlobalPos[playerid][X]){floatdata[7]=floatdata[4]-GlobalPos[playerid][X];}else{floatdata[7]=GlobalPos[playerid][X]-floatdata[4];}
if(floatdata[5]>GlobalPos[playerid][Y]){floatdata[8]=floatdata[5]-GlobalPos[playerid][Y];}else{floatdata[8]=GlobalPos[playerid][Y]-floatdata[5];}
if(GlobalPos[playerid][Y]>floatdata[5] && GlobalPos[playerid][X]>floatdata[4]){ //1
floatdata[0] = asin(floatdata[7]/floatdata[1]);
floatdata[9] = floatsub(floatsub(floatadd(floatdata[0], 90), floatmul(floatdata[0], 2)), -90.0);
}
if(GlobalPos[playerid][Y]<floatdata[5] && GlobalPos[playerid][X]>floatdata[4]){ //2
floatdata[0] = asin(floatdata[7]/floatdata[1]);
floatdata[9] = floatsub(floatadd(floatdata[0], 180), 180.0);
}
if(GlobalPos[playerid][Y]<floatdata[5] && GlobalPos[playerid][X]<floatdata[4]){ //3
floatdata[0] = acos(floatdata[8]/floatdata[1]);
floatdata[9] = floatsub(floatadd(floatdata[0], 360), floatmul(floatdata[0], 2));
}
if(GlobalPos[playerid][Y]>floatdata[5] && GlobalPos[playerid][X]<floatdata[4]){ //4
floatdata[0] = asin(floatdata[7]/floatdata[1]);
floatdata[9] = floatadd(floatdata[0], 180);
}
if(floatdata[9] == 0.0)
{
GlobalPos[playerid][Angle2] = floatdata[3];
} else {
GlobalPos[playerid][Angle2] = floatdata[9];
}
new Float:angle = floatabs(GlobalPos[playerid][Angle1]-GlobalPos[playerid][Angle2]);
if(90.0 > angle > 12.5 && floatdata[10] > 10.0)
{
if(GlobalPos[playerid][Timer] != -1)
{
new s[256];
format(s, 256, "~n~~n~~n~~w~_________________Drift!~n~___________________~p~Points: %d", GlobalPos[playerid][Points]);
TextDrawSetString(PlayerTextDraw[playerid], s);
}
else
{
TextDrawShowForPlayer(playerid,PlayerTextDraw[playerid]);
GameTextForPlayer(playerid, "Drift started!", 500, 1);
}
GlobalPos[playerid][Points] += floatround(angle * floatdata[10] / 3);
GlobalPos[playerid][Timer] = 20;
}
else
{
if(GlobalPos[playerid][Timer] != -1)
{
GlobalPos[playerid][Timer]--;
if(GlobalPos[playerid][Timer] == -1)
{
TextDrawHideForPlayer(playerid,PlayerTextDraw[playerid]);
GameTextFormatForPlayer(playerid, "Drift ended with %d points!", 750, 1, GlobalPos[playerid][Points]);
GlobalPos[playerid][Points] = 0;
}
}
}
//}
//}
GetPlayerPos(playerid,GlobalPos[playerid][X],GlobalPos[playerid][Y],GlobalPos[playerid][Z]);
}
}
SleepThread(100);
}
#endif
But when drifting the counter is incredible fast responsing!
I would like to have something crash free.
I wanted to make a drift counter In a plugin but I do not know how :P
PS: can somebody help me make this work without crash and WITH using TD? :P
also this seems to be non-crashing:
pawn Код:
forward DriftingUpdate(threadid);
public DriftingUpdate(threadid)
{
for(new playerid; playerid < MAX_PLAYERS; playerid++)
{
if(IsPlayerConnected(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new PlayerVehicleID = GetPlayerVehicleID(playerid);
//new PlayerVehicleModelID = GetVehicleModel(PlayerVehicleID);
new Float:floatdata[11];
//switch(PlayerVehicleModelID)
//{
// case 443,448,461 .. 463,521 .. 523,581,586,481,509,510,430,446,452 .. 454,472,473,484,493,595,417,425,447,465,469,487,488,497,501,548,563,406,444,556,557,573,460,464,476,511 .. 513,519,520,539,553,577,592,593,471:
// {
new Float:SpeedX, Float:SpeedY, Float:SpeedZ;
GetVehicleVelocity(PlayerVehicleID, SpeedX, SpeedY, SpeedZ);
floatdata[10] = floatmul(floatsqroot((floatpower(SpeedX, 2.0)+floatpower(SpeedY, 2.0)+floatpower(SpeedZ, 2.0))), 274.0);
GetVehicleZAngle(PlayerVehicleID, GlobalPos[playerid][Angle1]);
GetPlayerPos(playerid,floatdata[4],floatdata[5],floatdata[6]);
floatdata[1] = floatsqroot(floatpower(floatsub(floatdata[4],GlobalPos[playerid][X]),2)+floatpower(floatsub(floatdata[5],GlobalPos[playerid][Y]),2));
GetVehicleZAngle(PlayerVehicleID, floatdata[3]);
if(floatdata[4]>GlobalPos[playerid][X]){floatdata[7]=floatdata[4]-GlobalPos[playerid][X];}else{floatdata[7]=GlobalPos[playerid][X]-floatdata[4];}
if(floatdata[5]>GlobalPos[playerid][Y]){floatdata[8]=floatdata[5]-GlobalPos[playerid][Y];}else{floatdata[8]=GlobalPos[playerid][Y]-floatdata[5];}
if(GlobalPos[playerid][Y]>floatdata[5] && GlobalPos[playerid][X]>floatdata[4]){ //1
floatdata[0] = asin(floatdata[7]/floatdata[1]);
floatdata[9] = floatsub(floatsub(floatadd(floatdata[0], 90), floatmul(floatdata[0], 2)), -90.0);
}
if(GlobalPos[playerid][Y]<floatdata[5] && GlobalPos[playerid][X]>floatdata[4]){ //2
floatdata[0] = asin(floatdata[7]/floatdata[1]);
floatdata[9] = floatsub(floatadd(floatdata[0], 180), 180.0);
}
if(GlobalPos[playerid][Y]<floatdata[5] && GlobalPos[playerid][X]<floatdata[4]){ //3
floatdata[0] = acos(floatdata[8]/floatdata[1]);
floatdata[9] = floatsub(floatadd(floatdata[0], 360), floatmul(floatdata[0], 2));
}
if(GlobalPos[playerid][Y]>floatdata[5] && GlobalPos[playerid][X]<floatdata[4]){ //4
floatdata[0] = asin(floatdata[7]/floatdata[1]);
floatdata[9] = floatadd(floatdata[0], 180);
}
if(floatdata[9] == 0.0)
{
GlobalPos[playerid][Angle2] = floatdata[3];
} else {
GlobalPos[playerid][Angle2] = floatdata[9];
}
new Float:angle = floatabs(GlobalPos[playerid][Angle1]-GlobalPos[playerid][Angle2]);
if(90.0 > angle > 12.5 && floatdata[10] > 10.0)
{
if(GlobalPos[playerid][Timer] != -1)KillTimer(GlobalPos[playerid][Timer]);
else CallLocalFunction("OnDriftStart","i",playerid);
GlobalPos[playerid][Timer] = -1;
GlobalPos[playerid][Points] += floatround(angle * floatdata[10] / 3);
GlobalPos[playerid][Timer] = SetTimerEx("OnDriftEnd", 2000, 0, "d", playerid);
}
//}
//}
GetPlayerPos(playerid,GlobalPos[playerid][X],GlobalPos[playerid][Y],GlobalPos[playerid][Z]);
}
}
SleepThread(100);
}
forward OnDriftStart(playerid);
public OnDriftStart(playerid)
{
GameTextForPlayer(playerid, "Drift started!", 750, 1);
return 1;
}
forward OnDriftEnd(playerid);
public OnDriftEnd(playerid)
{
//do something with the points
GameTextFormatForPlayer(playerid, "Drift ended with %d points!", 750, 1, GlobalPos[playerid][Points]);
//
GlobalPos[playerid][Timer] = (-1);
GlobalPos[playerid][Points] = 0;
return 1;
}
But the game text's aren't really nice bleh.
EDIT:
this seems to be crash proof, fast and lag free:
pawn Код:
forward DriftingUpdate(threadid);
public DriftingUpdate(threadid)
{
for(new playerid; playerid < MAX_PLAYERS; playerid++)
{
if(IsPlayerConnected(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
new PlayerVehicleID = GetPlayerVehicleID(playerid);
//new PlayerVehicleModelID = GetVehicleModel(PlayerVehicleID);
new Float:floatdata[11];
//switch(PlayerVehicleModelID)
//{
// case 443,448,461 .. 463,521 .. 523,581,586,481,509,510,430,446,452 .. 454,472,473,484,493,595,417,425,447,465,469,487,488,497,501,548,563,406,444,556,557,573,460,464,476,511 .. 513,519,520,539,553,577,592,593,471:
// {
new Float:SpeedX, Float:SpeedY, Float:SpeedZ;
GetVehicleVelocity(PlayerVehicleID, SpeedX, SpeedY, SpeedZ);
floatdata[10] = floatmul(floatsqroot((floatpower(SpeedX, 2.0)+floatpower(SpeedY, 2.0)+floatpower(SpeedZ, 2.0))), 274.0);
GetVehicleZAngle(PlayerVehicleID, GlobalPos[playerid][Angle1]);
GetPlayerPos(playerid,floatdata[4],floatdata[5],floatdata[6]);
floatdata[1] = floatsqroot(floatpower(floatsub(floatdata[4],GlobalPos[playerid][X]),2)+floatpower(floatsub(floatdata[5],GlobalPos[playerid][Y]),2));
GetVehicleZAngle(PlayerVehicleID, floatdata[3]);
if(floatdata[4]>GlobalPos[playerid][X]){floatdata[7]=floatdata[4]-GlobalPos[playerid][X];}else{floatdata[7]=GlobalPos[playerid][X]-floatdata[4];}
if(floatdata[5]>GlobalPos[playerid][Y]){floatdata[8]=floatdata[5]-GlobalPos[playerid][Y];}else{floatdata[8]=GlobalPos[playerid][Y]-floatdata[5];}
if(GlobalPos[playerid][Y]>floatdata[5] && GlobalPos[playerid][X]>floatdata[4]){ //1
floatdata[0] = asin(floatdata[7]/floatdata[1]);
floatdata[9] = floatsub(floatsub(floatadd(floatdata[0], 90), floatmul(floatdata[0], 2)), -90.0);
}
if(GlobalPos[playerid][Y]<floatdata[5] && GlobalPos[playerid][X]>floatdata[4]){ //2
floatdata[0] = asin(floatdata[7]/floatdata[1]);
floatdata[9] = floatsub(floatadd(floatdata[0], 180), 180.0);
}
if(GlobalPos[playerid][Y]<floatdata[5] && GlobalPos[playerid][X]<floatdata[4]){ //3
floatdata[0] = acos(floatdata[8]/floatdata[1]);
floatdata[9] = floatsub(floatadd(floatdata[0], 360), floatmul(floatdata[0], 2));
}
if(GlobalPos[playerid][Y]>floatdata[5] && GlobalPos[playerid][X]<floatdata[4]){ //4
floatdata[0] = asin(floatdata[7]/floatdata[1]);
floatdata[9] = floatadd(floatdata[0], 180);
}
if(floatdata[9] == 0.0)
{
GlobalPos[playerid][Angle2] = floatdata[3];
} else {
GlobalPos[playerid][Angle2] = floatdata[9];
}
new Float:angle = floatabs(GlobalPos[playerid][Angle1]-GlobalPos[playerid][Angle2]);
if(90.0 > angle > 17.5 && floatdata[10] > 23.5)
{
GlobalPos[playerid][Points] += floatround(angle * floatdata[10] / 83);
if(GlobalPos[playerid][Timer] != -1)
{
GlobalPos[playerid][Combo] += 1;
new s[256];
format(s, 256, "~n~~n~~n~~w~_________________Drift!~n~___________________~r~Points:~w~_%d~n~___________________~r~Combo:~w~_x%d!",GlobalPos[playerid][Points],floatround(GlobalPos[playerid][Combo]/30,floatround_floor)+1);
TextDrawSetString(PlayerTextDraw[playerid], s);
}
else
{
TextDrawShowForPlayer(playerid,PlayerTextDraw[playerid]);
//GameTextForPlayer(playerid, "Drift started!", 500, 1);
}
GlobalPos[playerid][Timer] = 20;
}
else
{
if(GlobalPos[playerid][Timer] != -1)
{
GlobalPos[playerid][Timer]--;
if(GlobalPos[playerid][Timer] == -1)
{
TextDrawHideForPlayer(playerid,PlayerTextDraw[playerid]);
//GameTextFormatForPlayer(playerid, "Drift ended with %d points!", 750, 1, GlobalPos[playerid][Points]);
GlobalPos[playerid][Combo] = 0;
GlobalPos[playerid][Points] = 0;
}
}
}
//}
//}
GetPlayerPos(playerid,GlobalPos[playerid][X],GlobalPos[playerid][Y],GlobalPos[playerid][Z]);
}
}
SleepThread(100);
}
have fun drifting my dear (thread) racers!
EDIT2:
ah nevermind, it crashes -.-...
Cmon people help us out ! don't let such great plugin let fall apart! - performance is what we want today, people, yes? SO get your ass up and think with me how to make multi threading safer!