Timers & Booleans usage?
#1

Hi, i've got big problems with my timers and bools, so i want to know how i can use timers and bools the best?
Because, i had with my timers:
One timer of 1 secon, allways on, and one timer from Fallouts Speedometer, every 0,2 sec. The first timer i used, was for IsPlayerInArea, where i made an DM script. If you enter the area, godmode was turned of. If you leave the area, godmode was on. But last, godmode was always off or always on .
Script:
Код:
new DM[MAX_PLAYERS];
new Area69[MAX_PLAYERS];
forward isPlayerInArea(playerid);

public OnGameModeInit()
{
SetTimer("isPlayerInArea",1000, true);
}

public isPlayerInArea(playerid)
 {
   new Float:X, Float:Y, Float:Z; //We use this to store player position
   for(new i=0; i < MAX_PLAYERS; i++) //This line defines a name for all player, the name is "i"
   {
     GetPlayerPos(playerid, X, Y, Z); //Here we are storing the player position on the variables X, Y, and Z defined previously
     	if (X <= 430.6979 && X >= -78.8838 && Y <= 2134.8264 && Y >= 1630.9531)
     	{
			 	if (Area69melding[playerid] ==0)
			 	{
       	Area69melding[playerid] = 1;
  			DM[playerid] = 1;
       	GivePlayerWeapon(playerid, 23, 400);
       	GivePlayerWeapon(playerid, 29, 300);
       	GivePlayerWeapon(playerid, 31, 150);
       	}
     	}
   		else
   		{
 				Area69melding[playerid] = 0;
   			DM[playerid] = 0;
			}
			if (DM[playerid] == 0 )
     	{
				if(adminlevel[playerid] < 3)
				{
					ResetPlayerWeapons(playerid);
				}
				else
				{
					ResetPlayerWeapons(playerid);
				}
   			new Float:Health;
   			new Float:Armor;
				GetPlayerHealth(playerid,Health);
				GetPlayerArmour(playerid, Armor);
				if (Health < 100.0)
				{
					SetPlayerHealth(playerid,100.0);
				}
				if (Armor < 100.0)
				{
					SetPlayerArmour(playerid,100.0);
				}
				if (IsPlayerInAnyVehicle(playerid) == 1)
				{
		  		new PlayerCar;
		  		new Float:CarHealth;
		  		PlayerCar = GetPlayerVehicleID(playerid);
					GetVehicleHealth(PlayerCar,CarHealth);
					if (CarHealth < 1000.0)
					{
						SetVehicleHealth(PlayerCar, 1000.0);
 					}
 				}
   		}
 		}
	}
And my error with booleans. I made is vehicle spawn tool, for all players. They can spawn vehicles, as a infernus, and if they want a new vehicle to spawn, the other will be destroyed. It all time worked, until the last time. If someone spawn a vehicle, and drive it, suddenly their vehicle is gone Or someone on a vehicle is teleported to him
Code:
Код:
new Vehicle[MAX_PLAYERS];
new bool:VehicleSpawned[MAX_PLAYERS];

public OnPlayerCommandText(playerid, cmdtext[])
{
new Float:px, Float:py, Float:pz, Float:pa;
if (strcmp("/infernus", cmdtext, true) == 0)
  {
  	if(VoertuigSpawned[playerid] == true)
  	{
    DestroyVehicle(Voertuig[playerid]);
  	}
  	VoertuigSpawned[playerid] = true;
    GetPlayerFacingAngle(playerid,pa);
    GetPlayerPos(playerid, px, py, pz);
    Voertuig[playerid] = CreateVehicle(411, px+5, py, pz, pa,-1, -1,600000);
    SendClientMessage(playerid, GREEN,"Spawned a Infernus!");
    format(string, sizeof(string), "%s (ID %d) Has spawned a Infernus", name, playerid);
		print(string);
    return 1;
  }
return SendClientMessage(...);
)
How can i prevent my errors?

PS: Sorry for my bad english
Reply
#2

pawn Код:
new DM[MAX_PLAYERS];
new Area69[MAX_PLAYERS];
forward isPlayerInArea();

public OnGameModeInit()
{
SetTimer("isPlayerInArea",1000, true);
}

public isPlayerInArea()
{
 new Float:X, Float:Y, Float:Z; //We use this to store player position
 for(new playerid=0; playerid < MAX_PLAYERS; playerid++) //This line defines a name for all player, the name is "playerid"
 {
     if(IsPlayerConnected(playerid))
     {
         GetPlayerPos(playerid, X, Y, Z); //Here we are storing the player position on the variables X, Y, and Z defined previously
            if (X <= 430.6979 && X >= -78.8838 && Y <= 2134.8264 && Y >= 1630.9531)
            {
                if (Area69[playerid] ==0)
                {
                    Area69[playerid] = 1;
                    DM[playerid] = 1;
                    GivePlayerWeapon(playerid, 23, 400);
                    GivePlayerWeapon(playerid, 29, 300);
                    GivePlayerWeapon(playerid, 31, 150);
                }
            }
            else
            {
                Area69[playerid] = 0;
                DM[playerid] = 0;
            }
            if (DM[playerid] == 0 )
            {
                ResetPlayerWeapons(playerid);
               
                new Float:Health;
                new Float:Armor;
                GetPlayerHealth(playerid,Health);
                GetPlayerArmour(playerid, Armor);
                if (Health < 100.0)
                {
                    SetPlayerHealth(playerid,100.0);
                }
                if (Armor < 100.0)
                {
                    SetPlayerArmour(playerid,100.0);
                }
                if ( IsPlayerInAnyVehicle(playerid) )
                {
                    new PlayerCar;
                    new Float:CarHealth;
                    PlayerCar = GetPlayerVehicleID(playerid);
                    GetVehicleHealth(PlayerCar,CarHealth);
                    if (CarHealth < 1000.0)
                    {
                        SetVehicleHealth(PlayerCar, 1000.0);
                    }
                }
            }
        }
    }
}
pawn Код:
new Vehicle[MAX_PLAYERS];
new bool:VehicleSpawned[MAX_PLAYERS];

public OnPlayerConnect( playerid )
{
    ...
    Vehicle[playerid]=INVALID_VEHICLE_ID;
    ...
}
public OnPlayerDisconnect( playerid, reason )
{
    ...
    if( Vehicle[playerid] != INVALID_VEHICLE_ID )
    DestroyVehicle( Vehicle[playerid] );
    ...
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    new Float:px, Float:py, Float:pz, Float:pa;
    if (strcmp("/infernus", cmdtext, true) == 0)
        {
            if( Vehicle[playerid] !=INVALID_VEHICLE_ID )
            {
            DestroyVehicle( Vehicle[playerid] );
            }
            VoertuigSpawned[playerid] = true;
            GetPlayerFacingAngle(playerid,pa);
            GetPlayerPos(playerid, px, py, pz);
            Vehicle[playerid] = CreateVehicle( 411, px+5, py, pz, pa,-1, -1, 60000 );
           
            PutPlayerInVehicle( playerid, Vehicle[playerid], 0 );
           
            SendClientMessage(playerid, GREEN,"Spawned a Infernus!");
            format(string, sizeof(string), "%s (ID %d) Has spawned a Infernus", name, playerid);
            print(string);
            return 1;
        }
    return SendClientMessage(...);
}
Reply
#3

1: I shall test it soon.
2: Whats different? BTW: OnPlayerConnect: I say that there's no vehiclespawned: VehicleSpawned[playerid] = false.
On disconnect i check is theres a vehicle spawned, as yes, it wil destroyed. So whats different? :
Reply
#4

Dubble post :P
My vehicle spawn works, my godmode just a bit. Sometimes it work, sometimes not. I hadnt see also any difference in youy God script, only playerid is on another way used.

And a new problem, if someone kills someone, the server crashes. How can that?

Godmode (again, but none IsPlayerInArea more)
pawn Код:
public OnGameModeInit()
{
    //Timers
    SetTimer("OnPlayerStateChange",1000, true);
}


///////////OnPlayerStateChange//////////
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    //News
    new Float:Health;
    new Float:Armor;
   
    //Gets
    GetPlayerHealth(playerid, Health);
    GetPlayerArmour(playerid, Armor);
   
    //Adds/Removers
    //ResetPlayerWeapons(playerid);
   
    //Do
    if (Health < 100.0)
        {
            SetPlayerHealth(playerid,100.0);
        }
    if (Armor < 100.0)
        {
            SetPlayerArmour(playerid,100.0);
        }
    if (IsPlayerInAnyVehicle(playerid) == 1)
        {
            new PlayerCar;
            new Float:CarHealth;
            PlayerCar = GetPlayerVehicleID(playerid);
            GetVehicleHealth(PlayerCar,CarHealth);
            if (CarHealth < 1000.0)
            {
                SetVehicleHealth(PlayerCar, 1000.0);
            }
        }
return 1;
}

And my OnPlayerDeath/Spawn:
pawn Код:
///////////OnPlayerSpawn//////////
public OnPlayerSpawn(playerid)
{
    //Stuff
    SetPlayerArmour(playerid, 100.0);
    SetPlayerHealth(playerid, 100.0);
    GivePlayerWeapon(playerid, 29, 5000);
    return 1;
}



///////////OnPlayerDeath//////////
public OnPlayerDeath(playerid, killerid, reason)
{
    //News
    new score;
    new killmoney;
    new deathmoney;
   
    //Gets
    score = GetPlayerScore(killerid);
    killmoney = GetPlayerMoney(killerid);
    deathmoney = GetPlayerMoney(playerid);
   
    //Stuff
    SetPlayerScore(killerid, score+1);
    GivePlayerMoney(playerid, deathmoney-500);
    GivePlayerMoney(killerid, killmoney+100);
 
    //Text
    SendDeathMessage(killerid,playerid,reason);
    SendClientMessage(playerid, GRAY, "You've died. You will pay the hospital 500 dollar.");
    SendClientMessage(killerid, GRAY, "You've killed %s (ID %d). You get 100 dollar for this and 1 point.");
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)