This is my speed code:
#1

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 GetPlayerVehicleSpeedplayerid )
{
    new
        
Float:x,
        
Float:y,
        
Float:z,
        
vel,
        
vehicleid;
    
vehicleid GetPlayerVehicleID(playerid);
    
GetVehicleVelocityvehicleidxy);
    
vel floatroundfloatsqrootx*y*z*) * 180 );           // KM/H
//  vel = floatround( floatsqroot( x*x + y*y + z*z ) * 180 / MPH_KMH ); // Mph
    
return vel;
}
new 
killtime1killtime2killtime3;
new 
Text:speed[MAX_PLAYERS];
new 
str[180];
new 
bool:speed2[MAX_PLAYERS];
public 
speedtime2(playerid)
{
    
TextDrawHideForPlayer(playeridspeed[playerid]);
    
TextDrawDestroy(speed[playerid]);
    
speed[playerid] = TextDrawCreate(500373"SPEED:");
    
TextDrawBoxColor(speed[playerid], 0x252826FF);
    
TextDrawFont(speed[playerid], 3);
    
format(strsizeof(str), "SPEED:~y~%i"GetPlayerVehicleSpeed(playerid));
    
TextDrawSetString(speed[playerid], str);
    
TextDrawShowForPlayer(playeridspeed[playerid]);
    
killtime3 SetTimer("speedtime"10000);
    
speed2[playerid] = true;
    
    return 
1;
}
forward speedtime2();
public 
speedtime(playerid)
{
    
TextDrawHideForPlayer(playeridspeed[playerid]);
    
TextDrawDestroy(speed[playerid]);
    
speed[playerid] = TextDrawCreate(500373"SPEED:");
    
TextDrawBoxColor(speed[playerid], 0x252826FF);
    
TextDrawFont(speed[playerid], 3);
    
format(strsizeof(str), "SPEED:~y~%i"GetPlayerVehicleSpeed(playerid));
    
TextDrawSetString(speed[playerid], str);
    
TextDrawShowForPlayer(playeridspeed[playerid]);
    
killtime1 SetTimer("speedtime2"10000);
    
speed2[playerid] = true;
    return 
1;
}
forward speedtime();
public 
OnPlayerEnterVehicle(playeridvehicleidispassenger)
{
    
TextDrawHideForPlayer(playeridspeed[playerid]);
    
TextDrawDestroy(speed[playerid]);
    
speed[playerid] = TextDrawCreate(500373"SPEED:");
    
TextDrawBoxColor(speed[playerid], 0x252826FF);
    
TextDrawFont(speed[playerid], 3);
    
format(strsizeof(str), "SPEED:~y~%i"GetPlayerVehicleSpeed(playerid));
    
TextDrawSetString(speed[playerid], str);
    
TextDrawShowForPlayer(playeridspeed[playerid]);
    
killtime2 SetTimer("speedtime",10000);
    
speed2[playerid] = true;
    
/////////////////////////////////////
    
return 1;
}
public 
OnPlayerExitVehicle(playeridvehicleid)
{
    
KillTimer(killtime1);
    
KillTimer(killtime2);
    
KillTimer(killtime3);
    
TextDrawDestroy(speed[playerid]);
    
TextDrawHideForPlayer(playeridspeed[playerid]);
    return 
1;

Reply
#2

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];
Reply
#3

Thx
!
Reply
#4

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)