Small script problem
#1

I have this /vfixveh script, which works fine apart from the last timer not working.
here is the code:
Код:
CMD:vfixveh(playerid, params[])
{
	new vip[MAX_PLAYER_NAME], string[128], Float:health;
	
	new FVTime = tickcount() - 180000;
	
	FixvehTimer[playerid] = GetTickCount();
	TimerInfo[playerid][CMD_vfixveh] = tickcount();
	
	if(Player[playerid][pVip] < 2)
	{
		SCM(pid, ADMIN_COLOR, ADMIN_MESSAGE);
		return 1;
	}
	
	new vehicleid = GetPlayerVehicleID(playerid);
	new vehicleHp = GetVehicleHealth(playerid, health);
	
	GetPlayerName(playerid, vip, sizeof(vip));
	
	if(vehicleHp == 1000)
	{
		SCM(pid, ADMIN_COLOR, " Your vehicle is already at full hp!");
		return 1;
	}
	
	if(!IsPlayerInAnyVehicle(playerid))
	{
		SCM(pid, ADMIN_COLOR, " You are not in any vehicle.");
		FVTime = tickcount() - 180000;
		return 1;
	}
	if( GetTickCount() - FixvehTimer[playerid] < 180000 )
	{
		RepairVehicle(vehicleid);
		SCM(pid, -1, " {74FF5C}You have fixed your vehicle! You'll be able to use this command again after 3 minutes.");
		format(string, sizeof(string), "{EB4255}[VIP CMD] VIP Player %s has repaired his vehicle.", vip);
		SendManagerMessage(-1, string);
		SetTimerEx("EndFixvehTimer", 180000, false, "i", playerid);	
		return 1;
	}
	else
	{	
		if(FVTime < TimerInfo[playerid][CMD_vfixveh])  
		{
			SCM(pid, -1, "{F71B9C} You can only use this command every 3 minutes.");
			return 1;
		}	
	}
	return 1;
}
the red part of the code does not work - the timer never shows.
Reply
#2

Example:
Код:
CMD:test(playerid)
{
    if(TimerInfo[playerid][CMD_vfixveh] < gettime())
    {
        SCM(pid, -1, "{F71B9C} Command executed!");
        TimerInfo[playerid][CMD_vfixveh] = gettime() + 180;
    }
    else
    {
         SCM(pid, -1, "{F71B9C} You can only use this command every 3 minutes.");
    }

    return 1;
}
Reply
#3

try this
PHP код:
    if(( GetTickCount() - FixvehTimer[playerid] ) < 180000 )
    {
        
RepairVehicle(vehicleid);
        
SCM(pid, -1" {74FF5C}You have fixed your vehicle! You'll be able to use this command again after 3 minutes.");
        
format(stringsizeof(string), "{EB4255}[VIP CMD] VIP Player %s has repaired his vehicle."vip);
        
SendManagerMessage(-1string);
        
SetTimerEx("EndFixvehTimer"180000false"i"playerid);    
        return 
1;
    }
    else
    {    
        if(
FVTime TimerInfo[playerid][CMD_vfixveh])  
        {
            
SCM(pid, -1"{F71B9C} You can only use this command every 3 minutes.");
            return 
1;
        }    
    }
    return 
1;

if I am not wrong this code:
PHP код:
if( GetTickCount() - FixvehTimer[playerid] < 180000 
saying:
PHP код:
if( FixvehTimer[playerid] < 180000 
Reply
#4

Neither of these solutions work. The timer is still not shown.
the vehicleHp == 1000 message is not shown either ...
Reply
#5

try this

PHP код:
CMD:vfixveh(playeridparams[])
{
    new 
vip[MAX_PLAYER_NAME], string[128], Float:health;
    new 
FVTime tickcount() - 180000;
    
FixvehTimer[playerid] = GetTickCount();
    
TimerInfo[playerid][CMD_vfixveh] = tickcount();
    if(
Player[playerid][pVip] < 2) return SCM(pidADMIN_COLORADMIN_MESSAGE);
    new 
vehicleid GetPlayerVehicleID(playerid);
    new 
vehicleHp GetVehicleHealth(playeridhealth);
    
GetPlayerName(playeridvipsizeof(vip));
    if(
vehicleHp == 1000) return SCM(pidADMIN_COLOR" Your vehicle is already at full hp!");
    if(!
IsPlayerInAnyVehicle(playerid))
    {
        
SCM(pidADMIN_COLOR" You are not in any vehicle.");
        
FVTime tickcount() - 180000;
        return 
1;
    }
    else if( 
GetTickCount() - FixvehTimer[playerid] < 180000 )
    {
        
RepairVehicle(vehicleid);
        
SCM(pid, -1" {74FF5C}You have fixed your vehicle! You'll be able to use this command again after 3 minutes.");
        
format(stringsizeof(string), "{EB4255}[VIP CMD] VIP Player %s has repaired his vehicle."vip);
        
SendManagerMessage(-1string);
        
SetTimerEx("EndFixvehTimer"180000false"i"playerid);
        return 
1;
    }
    else
    {
        if(
FVTime TimerInfo[playerid][CMD_vfixveh])
        {
            
SCM(pid, -1"{F71B9C} You can only use this command every 3 minutes.");
            return 
1;
        }
    }
    return 
1;

Reply
#6

I don't know what's wrong, I've tried all the methods and some other ones and the vehicleHp does not function and neither does the timer.
Reply
#7

The way you have made this command is really bad. That's not how you check if a vehicle's health is equal to 1000 either. Plus, gettime() is a better replacement for GetTickCount().

Anyway, I have optimized your code a little. Try it out and let me know how it turns out.

PHP код:
// You can replace this array with your current tick holder or use this one directly
new g_RepairTime[MAX_PLAYERS]; // Global array, put this on top of your script
// Inside OnPlayerConnect
    
g_RepairTime[playerid] = 0;
    
CMD:vfixveh(playeridparams[])
{
    if(
Player[playerid][pVip] < 2)
        return 
SCM(playeridADMIN_COLORADMIN_MESSAGE);
    if(!
IsPlayerInAnyVehicle(playerid))
        return 
SCM(playeridADMIN_COLOR" You are not in any vehicle.");
        
    if (
g_RepairTime[playerid] > gettime())
        return 
SCM(playeridADMIN_COLOR"You need to wait 3 minutes before using this command.");
    new 
vehicleidFloathealth;
    
    
vehicleid GetPlayerVehicleID(playerid);
    
GetVehicleHealth(vehicleidhealth);
    if(
health == 1000.0)
        return 
SCM(playeridADMIN_COLOR" Your vehicle is already at full hp!");
    new 
vip[MAX_PLAYER_NAME], string[128],
    
GetPlayerName(playeridvipsizeof(vip));
    
    
RepairVehicle(vehicleid);
    
SCM(playerid, -1" {74FF5C}You have fixed your vehicle! You'll be able to use this command again after 3 minutes.");
    
format(stringsizeof(string), "{EB4255}[VIP CMD] VIP Player %s has repaired his vehicle."vip);
    
SendManagerMessage(-1string);
    
g_RepairTime[playerid] = (gettime() + 180);
    return 
1;

And btw, why are you using that "pid" inside this command? There's no pid here.
Reply
#8

Quote:
Originally Posted by Sjn
Посмотреть сообщение
And btw, why are you using that "pid" inside this command? There's no pid here.
He'll probably have playerid defined to pid to make it "easier".
Reply
#9

Quote:
Originally Posted by Sjn
Посмотреть сообщение
The way you have made this command is really bad. That's not how you check if a vehicle's health is equal to 1000 either. Plus, gettime() is a better replacement for GetTickCount().

Anyway, I have optimized your code a little. Try it out and let me know how it turns out.

PHP код:
// You can replace this array with your current tick holder or use this one directly
new g_RepairTime[MAX_PLAYERS]; // Global array, put this on top of your script
// Inside OnPlayerConnect
    
g_RepairTime[playerid] = 0;
    
CMD:vfixveh(playeridparams[])
{
    if(
Player[playerid][pVip] < 2)
        return 
SCM(playeridADMIN_COLORADMIN_MESSAGE);
    if(!
IsPlayerInAnyVehicle(playerid))
        return 
SCM(playeridADMIN_COLOR" You are not in any vehicle.");
        
    if (
g_RepairTime[playerid] > gettime())
        return 
SCM(playeridADMIN_COLOR"You need to wait 3 minutes before using this command.");
    new 
vehicleidFloathealth;
    
    
vehicleid GetPlayerVehicleID(playerid);
    
GetVehicleHealth(vehicleidhealth);
    if(
health == 1000.0)
        return 
SCM(playeridADMIN_COLOR" Your vehicle is already at full hp!");
    new 
vip[MAX_PLAYER_NAME], string[128],
    
GetPlayerName(playeridvipsizeof(vip));
    
    
RepairVehicle(vehicleid);
    
SCM(playerid, -1" {74FF5C}You have fixed your vehicle! You'll be able to use this command again after 3 minutes.");
    
format(stringsizeof(string), "{EB4255}[VIP CMD] VIP Player %s has repaired his vehicle."vip);
    
SendManagerMessage(-1string);
    
g_RepairTime[playerid] = (gettime() + 180);
    return 
1;

And btw, why are you using that "pid" inside this command? There's no pid here.
Thank you. It works perfectly.
Been inactive for a couple of days, and yes "pid" is defined as playerid in my script.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)