This is my speed code: -
Osamakurdi - 08.02.2018
I know my code is dump something but help me to make more professional.
So How I can remove timers with any thing else ?
Or How I can use timers with another way ?
Code:
PHP код:
// This is a comment
// uncomment the line below if you want to write a filterscript
#define FILTERSCRIPT
#include <a_samp>
#define MPH_KMH 1.609344
stock GetPlayerVehicleSpeed( playerid )
{
new
Float:x,
Float:y,
Float:z,
vel,
vehicleid;
vehicleid = GetPlayerVehicleID(playerid);
GetVehicleVelocity( vehicleid, x, y, z );
vel = floatround( floatsqroot( x*x + y*y + z*z ) * 180 ); // KM/H
// vel = floatround( floatsqroot( x*x + y*y + z*z ) * 180 / MPH_KMH ); // Mph
return vel;
}
new killtime1, killtime2, killtime3;
new Text:speed[MAX_PLAYERS];
new str[180];
new bool:speed2[MAX_PLAYERS];
public speedtime2(playerid)
{
TextDrawHideForPlayer(playerid, speed[playerid]);
TextDrawDestroy(speed[playerid]);
speed[playerid] = TextDrawCreate(500, 373, "SPEED:");
TextDrawBoxColor(speed[playerid], 0x252826FF);
TextDrawFont(speed[playerid], 3);
format(str, sizeof(str), "SPEED:~y~%i", GetPlayerVehicleSpeed(playerid));
TextDrawSetString(speed[playerid], str);
TextDrawShowForPlayer(playerid, speed[playerid]);
killtime3 = SetTimer("speedtime", 1000, 0);
speed2[playerid] = true;
return 1;
}
forward speedtime2();
public speedtime(playerid)
{
TextDrawHideForPlayer(playerid, speed[playerid]);
TextDrawDestroy(speed[playerid]);
speed[playerid] = TextDrawCreate(500, 373, "SPEED:");
TextDrawBoxColor(speed[playerid], 0x252826FF);
TextDrawFont(speed[playerid], 3);
format(str, sizeof(str), "SPEED:~y~%i", GetPlayerVehicleSpeed(playerid));
TextDrawSetString(speed[playerid], str);
TextDrawShowForPlayer(playerid, speed[playerid]);
killtime1 = SetTimer("speedtime2", 1000, 0);
speed2[playerid] = true;
return 1;
}
forward speedtime();
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
TextDrawHideForPlayer(playerid, speed[playerid]);
TextDrawDestroy(speed[playerid]);
speed[playerid] = TextDrawCreate(500, 373, "SPEED:");
TextDrawBoxColor(speed[playerid], 0x252826FF);
TextDrawFont(speed[playerid], 3);
format(str, sizeof(str), "SPEED:~y~%i", GetPlayerVehicleSpeed(playerid));
TextDrawSetString(speed[playerid], str);
TextDrawShowForPlayer(playerid, speed[playerid]);
killtime2 = SetTimer("speedtime",1000, 0);
speed2[playerid] = true;
/////////////////////////////////////
return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
KillTimer(killtime1);
KillTimer(killtime2);
KillTimer(killtime3);
TextDrawDestroy(speed[playerid]);
TextDrawHideForPlayer(playerid, speed[playerid]);
return 1;
}
Re: This is my speed code: -
Mugala - 08.02.2018
okay I dont understand what u want but, u're using 2 same script, but why idk
by the way, edit this
new killtime1, killtime2, killtime3;
into this.
new killtime1[MAX_PLAYERS], killtime2[MAX_PLAYERS], killtime3[MAX_PLAYERS];
Re: This is my speed code: -
Osamakurdi - 08.02.2018
Thx
!
Re: This is my speed code: -
AmigaBlizzard - 08.02.2018
I don't get why you need 3 timers, which have the exact same code inside them, and why they destroy the textdraw and recreate it again every second.
All you need is 1 timer which is started when the player enters a vehicle and gets killed when he exits the vehicle.
This timer runs every second with the flag set to true instead of false to make it repeatable, and you need to supply the timer with the playerid as parameter.
The code you posted won't work because of the lack of the playerid parameter. Your timer-functions accept it, but you don't supply it anywhere using SetTimer,
therefore it's always 0 and will only work for playerid 0.
Less timers = less code = less debug-time and less chance for errors in that code.
Create the textdraw when the player connects and destroy it when he disconnects.
Or better yet, use player textdraws instead of global textdraws.
Those get destroyed automatically when the player disconnects, that's even less code.