Could you please help me?
#1

I have this code right here
Код:
//this is on game mode init//
SetTimer("vcheck",500,1);
//this is what i have forwarded//
forward vcheck();
//and this is the script//
public vcheck()
{
   if(GetVehicleHealth(vehicleid) < 300)
   {
       new vehicleid = GetPlayerVehicleID(playerid);
       new Float:VehHealth;
       GetVehicleHealth(vehicleid,VehHealth);
       if(VehHealth <= 50) return RepairVehicle(GetPlayerVehicleID(playerid));
       PlayerPlaySound(playerid, 1056, 0.0,0.0, 0.0);
       SendClientMessage(playerid, COLOR_KRED, "Your vehicle has been fixed");
       return 1;
   }
    return 1;
}
i get these errors
Код:
D:\samp03asvr_R4_win32\gamemodes\Untitled.pwn(493) : error 017: undefined symbol "vehicleid"
D:\samp03asvr_R4_win32\gamemodes\Untitled.pwn(495) : error 017: undefined symbol "playerid"
D:\samp03asvr_R4_win32\gamemodes\Untitled.pwn(498) : error 017: undefined symbol "playerid"
D:\samp03asvr_R4_win32\gamemodes\Untitled.pwn(499) : error 017: undefined symbol "playerid"
D:\samp03asvr_R4_win32\gamemodes\Untitled.pwn(500) : error 017: undefined symbol "playerid"
D:\samp03asvr_R4_win32\gamemodes\Untitled.pwn(503) : warning 217: loose indentation
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


5 Errors.
Help?
I can fix the indentation, so don't worry
Reply
#2

pawn Код:
// OnGameModeInit
for (new playerid = 0; playerid < MAX_PLAYERS; playerid++)
{
    SetTimerEx("vcheck", 500, 1, "i", playerid);
}

// Anywhere
forward vcheck(playerid);
public vcheck(playerid)
{
    if (IsPlayerInAnyVehicle(playerid))
    {
        new vehicleid = GetPlayerVehicleID(playerid);
        if(GetVehicleHealth(vehicleid) < 300)
        {
                new Float:VehHealth;
            GetVehicleHealth(vehicleid, VehHealth);
            if(VehHealth <= 50) { RepairVehicle(vehicleid); }
            PlayerPlaySound(playerid, 1056, 0.0,0.0, 0.0);
            SendClientMessage(playerid, COLOR_KRED, "Your vehicle has been fixed");
        }
    }
    return 1;
}
Reply
#3

@Anwix: OnGameModeInit is called when gamemode starts, and when that happens, then no one is on the server. And it's a bad idea to loop and create 500 (MAX_PLAYERS) timers.
Reply
#4

Код:
(499) : warning 202: number of arguments does not match definition
line 499 is this

Код:
if(GetVehicleHealth(vehicleid) < 300)
Reply
#5

pawn Код:
public vcheck(playerid)
{
    if (IsPlayerInAnyVehicle(playerid))
    {
        new vehicleid = GetPlayerVehicleID(playerid);
        new Float:VehHealth;
        GetVehicleHealth(vehicleid, VehHealth);

        if(VehHealth <= 50)
        {          
            RepairVehicle(vehicleid);
            PlayerPlaySound(playerid, 1056, 0.0,0.0, 0.0);
            SendClientMessage(playerid, COLOR_KRED, "Your vehicle has been fixed");
        }
    }
    return 1;
}

//OnPlayerConnect
SetTimerEx("vcheck", 500, 1, "i", playerid); // Remove the loop from OnGameModeInit
Reply
#6

And if 30 players connect? That means that there will be 30 timers which is still too many and you're not even killing them on player-disconnect.

pawn Код:
/* Under OnGameModeInit callback. */
SetTimer("vcheck", 1000, true);

public vcheck()
{
  for(new u = 0; u < GetMaxPlayers(); u++)
  {
    if(IsPlayerInAnyVehicle(u))
    {
      new
          vehicleID = GetPlayerVehicleID(u), Float:vehicleHealth;
      GetVehicleHealth(vehicleID, vehicleHealth);
      if(vehicleHealth <= 500) // I've changed the health-check from 50 to 500 because vehicles maximum health is 1000, not 100. Vehicle with 50 health is already burning.
      {        
        RepairVehicle(vehicleID);
        PlayerPlaySound(u, 1056, 0.0, 0.0, 0.0);
        SendClientMessage(u, COLOR_KRED, "Your vehicle has been fixed.");
      }
    }
  }
  return true;
}
Reply
#7

Or that way :P
Код:
//OnGameModeInit
SetTimer("vcheck", 800, true);


forward vcheck();
public vcheck()
{
	new Float:VHealth,PVeh,PSeat;
	for(new d,g=GetMaxPlayers(); d<g; d++) if(IsPlayerConnected(d) && !IsPlayerNPC(d))
	{
		PSeat = GetPlayerVehicleSeat(d);
		if(!PSeat)
		{
			PVeh = GetPlayerVehicleID(d);
			GetVehicleHealth(PVeh,VHealth);
			if(VHealth <= 300)
			{
				RepairVehicle(PVeh);
				PlayerPlaySound(d, 1056, 0.0,0.0,0.0);
				SendClientMessage(d, COLOR_KRED, "Your vehicle has been fixed");
			}
		}
	}
	return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)