Hallo!
Ich habe mein eigenes Tacho System erstellt und habe nun folgendes Problem:
Ab und zu stirbt der Motor einfach so unter dem Fahren ab.
Ist ja ganz realistisch aber leider nicht Absicht^^
Vermute der Fehler liegt bei : OnPlayerUpdate
Bitte um Hilfe!!
public OnFilterScriptInit()
{
SetTimer("BenzinVerlust",VERLUST,true);
print("\n--------------------------------------");
print("Tacho/Motorscript by Schmonk");
print("--------------------------------------\n");
ManualVehicleEngineAndLights();
for(new i = 0; i < MAX_PLAYERS; i++)
{
new veh=GetPlayerVehicleID(i);
GetVehicleParamsEx(veh,engine,lights,alarm,doors,bonnet,boot,objective);
SetVehicleParamsEx(veh,VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);
Motor[veh]=false;
Tank[i]=150;
}
for(new i=0;i<MAX_PLAYERS;i++)
{
//Fahrzeug:
Tacho[i]=TextDrawCreate(420.000000,370.000000,"");
TextDrawLetterSize(Tacho[i],0.4,1.1);
TextDrawFont(Tacho[i],1);
TextDrawSetShadow(Tacho[i],2);
TextDrawSetOutline(Tacho[i],1);
//Speed:
Tacho1[i]=TextDrawCreate(420.000000,385.000000,"");
TextDrawLetterSize(Tacho1[i],0.4,1.1);
TextDrawFont(Tacho1[i],1);
TextDrawSetShadow(Tacho1[i],2);
TextDrawSetOutline(Tacho1[i],1);
//Zustand:
Tacho2[i]=TextDrawCreate(420.000000,400.000000,"");
TextDrawLetterSize(Tacho2[i],0.4,1.1);
TextDrawFont(Tacho2[i],1);
TextDrawSetShadow(Tacho2[i],2);
TextDrawSetOutline(Tacho2[i],1);
//Motor:
Tacho3[i]=TextDrawCreate(420.000000,415.000000,"");
TextDrawLetterSize(Tacho3[i],0.4,1.1);
TextDrawFont(Tacho3[i],1);
TextDrawSetShadow(Tacho3[i],2);
TextDrawSetOutline(Tacho3[i],1);
//Tank:
Tacho4[i]=TextDrawCreate(420.000000,430.000000,"");
TextDrawLetterSize(Tacho4[i],0.4,1.1);
TextDrawFont(Tacho4[i],1);
TextDrawSetShadow(Tacho4[i],2);
TextDrawSetOutline(Tacho4[i],1);
}
SetTimer("UpdateTacho",TACHOTIMER,1);
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
public OnVehicleSpawn(vehicleid)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
new veh=GetPlayerVehicleID(i);
GetVehicleParamsEx(veh,engine,lights,alarm,doors,bonnet,boot,objective);
SetVehicleParamsEx(veh,VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);
Motor[veh]=false;
}
return 1;
}
public OnVehicleDeath(vehicleid, killerid)
{
Motor[vehicleid]=false;
return 1;
}
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
if(GetVehicleModel(vehicleid) == 509 || GetVehicleModel(vehicleid) == 481 || GetVehicleModel(vehicleid) == 510)
{
GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
SetVehicleParamsEx(vehicleid,VEHICLE_PARAMS_ON,lights,alarm,doors,bonnet,boot,objective);
Motor[vehicleid] =true;
}
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
{
new veh=GetPlayerVehicleID(playerid);
if(Motor[veh] ==false)
{
SendClientMessage(playerid,-1,"{CCCCFF}Mit {FF0000}/motor {CCCCFF}kannst du dein Fahrzeug starten.");
}
}
return 1;
}
ocmd:fill(playerid,params[])
{
if(IsPlayerInRangeOfPoint(playerid,10.0,TankstelleLSPD1) || IsPlayerInRangeOfPoint(playerid,10.0,TankstelleMechaniker1) || IsPlayerInRangeOfPoint(playerid,10.0,TankstelleSFBahnhof1))
{
#pragma unused params
if(!IsPlayerInAnyVehicle(playerid))return SendClientMessage(playerid,COLOR_GREY,"Du sitzt in keinem Fahrzeug.");
new veh=GetPlayerVehicleID(playerid);
if(GetPlayerState(playerid)!=PLAYER_STATE_DRIVER)return SendClientMessage(playerid,COLOR_GREY,"Du sitzt nicht auf dem Fahrersitz.");
if(GetVehicleModel(veh) == 509 || GetVehicleModel(veh) == 481 || GetVehicleModel(veh) == 510)return SendClientMessage(playerid,COLOR_GREY,"Du kannst keine Fahrräder tanken.");
if(TanktGerade[veh]==true)return SendClientMessage(playerid,COLOR_GREY,"Du tankst gerade.");
Motor[veh]=false;
GetVehicleParamsEx(veh,engine,lights,alarm,doors,bonnet,boot,objective);
SetVehicleParamsEx(veh,VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);
new ZuTanken=150-Tank[veh];
new Preis=ZuTanken*BENZINPREIS;
if(GetPlayerMoney(playerid)<Preis)return SendClientMessage(playerid,COLOR_GREY,"Du hast nicht genügend Geld.");
GivePlayerMoney(playerid,-Preis);
SendClientMessage(playerid,COLOR_GREY,"Fahrzeug wird getankt... Bitte warten.");
TogglePlayerControllable(playerid,0);
SetCameraBehindPlayer(playerid);
TanktGerade[veh]=true;
Tanktimer[playerid]=SetTimerEx("Auftanken",500,true,"i",playerid);
}
else if(IsPlayerInRangeOfPoint(playerid,10.0,TankstelleSFPD1) || IsPlayerInRangeOfPoint(playerid,10.0,TankstelleLCN2) || IsPlayerInRangeOfPoint(playerid,10.0,TankstelleLCN1))
{
#pragma unused params
if(!IsPlayerInAnyVehicle(playerid))return SendClientMessage(playerid,COLOR_GREY,"Du sitzt in keinem Fahrzeug.");
new veh=GetPlayerVehicleID(playerid);
if(GetPlayerState(playerid)!=PLAYER_STATE_DRIVER)return SendClientMessage(playerid,COLOR_GREY,"Du sitzt nicht auf dem Fahrersitz.");
if(GetVehicleModel(veh) == 509 || GetVehicleModel(veh) == 481 || GetVehicleModel(veh) == 510)return SendClientMessage(playerid,COLOR_GREY,"Du kannst keine Fahrräder tanken.");
if(TanktGerade[veh]==true)return SendClientMessage(playerid,COLOR_GREY,"Du tankst gerade.");
Motor[veh]=false;
GetVehicleParamsEx(veh,engine,lights,alarm,doors,bonnet,boot,objective);
SetVehicleParamsEx(veh,VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);
new ZuTanken=150-Tank[veh];
new Preis=ZuTanken*BENZINPREIS;
if(GetPlayerMoney(playerid)<Preis)return SendClientMessage(playerid,COLOR_GREY,"Du hast nicht genügend Geld.");
GivePlayerMoney(playerid,-Preis);
SendClientMessage(playerid,COLOR_GREY,"Fahrzeug wird getankt... Bitte warten.");
TogglePlayerControllable(playerid,0);
SetCameraBehindPlayer(playerid);
TanktGerade[veh]=true;
Tanktimer[playerid]=SetTimerEx("Auftanken",500,true,"i",playerid);
}
else
{
SendClientMessage(playerid,COLOR_GREY,"Du bist nicht bei einer Tankstelle.");
}
return 1;
}
ocmd:motor(playerid,params[])
{
if(!IsPlayerInAnyVehicle(playerid))return 1;
if(GetPlayerState(playerid)==PLAYER_STATE_DRIVER)
{
new veh=GetPlayerVehicleID(playerid);
if(GetVehicleModel(veh) == 509 || GetVehicleModel(veh) == 481 || GetVehicleModel(veh) == 510)
{
Motor[veh]=false;
}
else if(Motor[veh]==false)
{
GetVehicleParamsEx(veh,engine,lights,alarm,doors,bonnet,boot,objective);
SetVehicleParamsEx(veh,VEHICLE_PARAMS_ON,lights,alarm,doors,bonnet,boot,objective);
Motor[veh]=true;
SendClientMessage(playerid,-1,"{CCCCFF}Du hast den Motor gestartet. Mit {FF0000}/motor {CCCCFF}kannst du ihn wieder abstellen.");
}
else if(Tank[veh]<=1)
{
SendClientMessage(playerid,-1,"{FF0000}Dein Tank ist leer.");
Tank[veh]=0;
GetVehicleParamsEx(veh,engine,lights,alarm,doors,bonnet,boot,objective);
SetVehicleParamsEx(veh,VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);
Motor[veh]=false;
return 0;
}
else if(TanktGerade[veh]==true)
{
Motor[veh]=false;
SendClientMessage(playerid,COLOR_GREY,"Der Motor muss beim Tanken ausgeschalten sein.");
}
else if(Motor[veh]==true)
{
GetVehicleParamsEx(veh,engine,lights,alarm,doors,bonnet,boot,objective);
SetVehicleParamsEx(veh,VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);
Motor[veh]=false;
SendClientMessage(playerid,COLOR_GREY,"{CCCCFF}Du hast den Motor abgeschaltet. Mit {FF0000}/motor {CCCCFF}kannst du ihn wieder anstellen.");
}
}
return 1;
}
//Mechaniker:
ocmd:refill(playerid,params[])
{
if(GetPVarInt(playerid,"Beruf")==4)
{
new pID;
new string[128],string2[128];
if(sscanf(params,"u",pID))return SendClientMessage(playerid,COLOR_GREY,"Benutzung: /refill [playerid/Spielername]");
if(!IsPlayerInAnyVehicle(pID))return SendClientMessage(playerid,COLOR_GREY,"Dieser Spieler sitzt in keinem Fahrzeug.");
if(!IsPlayerInAnyVehicle(playerid))return SendClientMessage(playerid,COLOR_GREY,"Du sitzt in keinem Mechanikercar.");
new Float:PlayerPos[3];
new veh=GetPlayerVehicleID(pID);
new tankdifferenz = 150-Tank[veh];
new preis=tankdifferenz*3;
GetPlayerPos(pID, PlayerPos[0], PlayerPos[1], PlayerPos[2]); //Zeile 154
if(!IsPlayerInRangeOfPoint(playerid, 15, PlayerPos[0], PlayerPos[1], PlayerPos[2]))return SendClientMessage(playerid, COLOR_GREY, "Du bist zu weit entfernt");
format(string,sizeof(string),"Mechaniker %s hat dir angeboten dein Fahrzeug für %d$ zu tanken.",SpielerName(playerid),preis);
format(string2,sizeof(string2),"Du hast %s angeboten sein Fahrzeug für %d$ zu tanken.",SpielerName(pID),preis);
SendClientMessage(pID,COLOR_LIGHTBLUE,string);
SendClientMessage(pID,COLOR_GREY,"Benutze: /acceptrefill [playerid/Spielername] um das Angebot anzunehmen.");
SendClientMessage(playerid,COLOR_LIGHTBLUE,string2);
Mechanikertankangebot[playerid]=1;
SpielerSpeichern(playerid);
SpielerSpeichern(pID);
}
else
{
SendClientMessage(playerid,COLOR_GREY,"Du bist kein Mechaniker.");
}
return 1;
}
ocmd:acceptrefill(playerid,params[])
{
new pID;
new vehi=GetPlayerVehicleID(pID);
new vehicle=GetPlayerVehicleID(playerid);
new tankdifferenz=150-Tank[vehicle];
new preis=tankdifferenz*3;
if(sscanf(params,"u",pID))return SendClientMessage(playerid,COLOR_GREY,"Benutzung: /acceptrefill [playerid/Spielername]");
if(GetPlayerMoney(playerid) < preis)return SendClientMessage(playerid,COLOR_GREY,"Du hast nicht genügend Geld bei dir.");
if(Mechanikertankangebot[pID]==0)return SendClientMessage(playerid,COLOR_GREY,"Dieser Spieler hat dir kein Auftanken angeboten.");
GivePlayerMoney(playerid,-preis);
GivePlayerMoney(pID,preis);
new string[128],string2[128];
format(string,sizeof(string),"Mechaniker %s hat dein Fahrzeug für %i$ getankt.",SpielerName(pID),preis);
format(string2,sizeof(string2),"Du hast das Fahrzeug von %s für %i$ getankt.",SpielerName(playerid),preis);
SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
SendClientMessage(pID,COLOR_LIGHTBLUE,string2);
Motor[vehi]=false;
GetVehicleParamsEx(vehi,engine,lights,alarm,doors,bonnet,boot,objective);
SetVehicleParamsEx(vehi,VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);
SendClientMessage(playerid,COLOR_GREY,"Fahrzeug wird getankt... Bitte warten.");
TogglePlayerControllable(playerid,0);
SetCameraBehindPlayer(playerid);
TanktGerade[vehi]=true;
Tanktimer[playerid]=SetTimerEx("Auftanken",500,true,"i",playerid);
Mechanikertankangebot[pID]=0;
GetVehicleParamsEx(vehicle,engine,lights,alarm,doors,bonnet,boot,objective);
SetVehicleParamsEx(vehicle,VEHICLE_PARAMS_ON,lights,alarm,doors,bonnet,boot,objective);
Motor[vehicle]=true;
SpielerSpeichern(playerid);
SpielerSpeichern(pID);
return 1;
}
public BenzinVerlust()
{
for(new i = 0; i < MAX_VEHICLES; i++)
{
if(Motor[i]==true)
{
Tank[i]=Tank[i]-1;
if(Tank[i]<=0)
{
new veh=GetPlayerVehicleID(i);
if(Tank[veh]<=0)
Tank[veh]=0;
GetVehicleParamsEx(veh,engine,lights,alarm,doors,bonnet,boot,objective);
SetVehicleParamsEx(veh,VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);
Motor[veh]=false;
}
}
}
return 1;
}
public Auftanken(playerid)
{
new veh=GetPlayerVehicleID(playerid);
Tank[veh]=Tank[veh]+1;
if(Tank[veh]>=150)
{
TanktGerade[veh]=false;
Tank[veh]=150;
SendClientMessage(playerid,COLOR_GREY,"Dein Fahrzeug ist nun voll aufgetankt.");
Motor[veh]=true;
GetVehicleParamsEx(veh,engine,lights,alarm,doors,bonnet,boot,objective);
SetVehicleParamsEx(veh,VEHICLE_PARAMS_ON,lights,alarm,doors,bonnet,boot,objective);
TogglePlayerControllable(playerid,1);
KillTimer(Tanktimer[playerid]);
}
}
forward UpdateTacho();
public UpdateTacho()
{
for(new i=0;i<MAX_PLAYERS;i++)
{
if(IsPlayerConnected(i) && GetPlayerState(i) == PLAYER_STATE_DRIVER && !IsPlayerNPC(i))
{
new Float:Strecke,Float:Geschwindigkeit;
new Float:vehiclehealth;
new vehicle = GetPlayerVehicleID(i);
GetVehicleHealth(vehicle,vehiclehealth);
GetVehiclePos(GetPlayerVehicleID(i),x1[i],y1[i],z1[i]);
Strecke=floatsqroot(floatpower(floatabs(floatsub(x1[i],x2[i])),2)+floatpower(floatabs(floatsub(y1[i],y2[i])),2)+floatpower(floatabs(floatsub(z1[i],z2[i])),2));
Geschwindigkeit=(Strecke/(TACHOTIMER/1000))*3.6;
new string[56],string2[128],string3[128];
format(string,sizeof(string),"%sFahrzeug: %s%s",blau,weiss,Fahrzeug[GetVehicleModel(GetPlayerVehicleID(i))-400]);
TextDrawSetString(Tacho[i],string);
format(string2,sizeof(string2),"%sGeschwindigkeit: %s%d KM/H",blau,weiss,floatround(Geschwindigkeit));
TextDrawSetString(Tacho1[i],string2);
format(string3,sizeof(string3),"%sZustand: %s%.0f/1000",blau,weiss,vehiclehealth);
TextDrawSetString(Tacho2[i],string3);
new veh=GetPlayerVehicleID(i);
if(GetVehicleModel(veh) == 509 || GetVehicleModel(veh) == 481 || GetVehicleModel(veh) == 510)
{
TextDrawShowForPlayer(i,Tacho[i]);
TextDrawShowForPlayer(i,Tacho1[i]);
TextDrawShowForPlayer(i,Tacho2[i]);
TextDrawHideForPlayer(i,Tacho3[i]);
TextDrawHideForPlayer(i,Tacho4[i]);
}
else
{
if(Motor[veh]==false)
{
new string4[128];
format(string4,sizeof(string4),"%sMotor: %sAus",blau,weiss);
TextDrawSetString(Tacho3[i],string4);
}
else
{
new string4[128];
format(string4,sizeof(string4),"%sMotor: %sAn",blau,weiss);
TextDrawSetString(Tacho3[i],string4);
}
GetVehiclePos(GetPlayerVehicleID(i),x2[i],y2[i],z2[i]);
TextDrawShowForPlayer(i,Tacho[i]);
TextDrawShowForPlayer(i,Tacho1[i]);
TextDrawShowForPlayer(i,Tacho2[i]);
TextDrawShowForPlayer(i,Tacho3[i]);
TextDrawShowForPlayer(i,Tacho4[i]);
}
}
else
{
TextDrawHideForPlayer(i,Tacho[i]);
TextDrawHideForPlayer(i,Tacho1[i]);
TextDrawHideForPlayer(i,Tacho2[i]);
TextDrawHideForPlayer(i,Tacho3[i]);
TextDrawHideForPlayer(i,Tacho4[i]);
}
}
return 1;
}
public OnPlayerUpdate(playerid)
{
new string[128];
if(GetPlayerState(playerid)==PLAYER_STATE_DRIVER)
{
new veh=GetPlayerVehicleID(playerid);
if(GetVehicleModel(veh) != 509 && GetVehicleModel(veh) != 481 && GetVehicleModel(veh) != 510)
{
if(Tank[veh]<=0)
{
Motor[veh]=false;
GetVehicleParamsEx(veh,engine,lights,alarm,doors,bonnet,boot,objective);
SetVehicleParamsEx(veh,VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);
format(string,sizeof(string),"%sTank: %s%d/150 L",blau,rot,Tank[veh]);
SendClientMessage(playerid,-1,"{FF0000}Dein Tank ist leer.");
return 1;
}
else if(Tank[veh]<=10)format(string,sizeof(string),"%sTank: %s%d/150 L",blau,rot,Tank[veh]);
else if(Tank[veh]<=30)format(string,sizeof(string),"%sTank: %s%d/150 L",blau,gelb,Tank[veh]);
else if(Tank[veh]<=150)format(string,sizeof(string),"%sTank: %s%d/150 L",blau,gruen,Tank[veh]);
TextDrawSetString(Tacho4[playerid],string);
}
}
else
{
TextDrawHideForPlayer(playerid,Tacho4[playerid]);
}
return 1;
}
Danke für eure Hilfe!
lg
Schmonk