Problem
#1

Hello guys,i wrote this code to check if player is reloading and send a message on chat:

pawn Код:
forward CheckReloadingWeapon()
public CheckReloadingWeapon()
{
 if(GetPlayerWeaponState(i) == WEAPONSTATE_RELOADING && laststate[i] != WEAPONSTATE_RELOADING)
  {
   for(new i = 0; i < MAX_PLAYERS; i++)
   {
   if(IsPlayerConnected(i))
   {
   GetPlayerWeaponData(i, 7, weap, ammo);
   new string [128];
   new pName[MAX_PLAYER_NAME];
   GetPlayerName(i, pName, sizeof(pName));
   format(string, sizeof(string), "%s is reloading.Weapon: %s - Ammo %d", pName,weap,ammo);
   SendClientMessageToAll(0xFF0000FF, string);
   }
  }
 }
}
But i get this errors:

error 001: expected token: ";", but found "public"
error 017: undefined symbol "i"
error 017: undefined symbol "i"
error 029: invalid expression, assumed zero

What's wrong?Also,i wanna know if the code is written right.Thanks.
Reply
#2

Код:
forward CheckReloadingWeapon();
I assume that's your only problem, I didn't check for anything else.

oh and you haven't defined the variable "i"...
Reply
#3

You get no error for the laststate thing? I do, so I think you have not included the whole script.
Reply
#4

pawn Код:
forward CheckReloadingWeapon();
Quote:
Originally Posted by Mini`
oh and you haven't defined the variable "i"...
It has been defined and declared within the for loop type structure. The preceding if statement contains i, which I assume is supposed to be proceeding the for loop type instruction.
Reply
#5

Код:
forward CheckReloadingWeapon();
public CheckReloadingWeapon()
{
   for(new i = 0; i < MAX_PLAYERS; i++)
	{
 		if(GetPlayerWeaponState(i) == WEAPONSTATE_RELOADING) //&& laststate[i] != WEAPONSTATE_RELOADING)
  		{
 			if(IsPlayerConnected(i))
   			{
				new weap, ammo, string [128], wName[24], pName[24];
			   	GetPlayerWeaponData(i, 7, weap, ammo);
			   	GetWeaponName(weap, wName, sizeof(wName));
			   	GetPlayerName(i, pName, sizeof(pName));
			   	format(string, sizeof(string), "%s is reloading.Weapon: %s - Ammo %d", pName, weap, ammo);
			   	SendClientMessageToAll(0xFF0000FF, string);
   			}
  		}
 	}
}
No errors, no idea if works.
Reply
#6

Thanks guys but seems not working,when i reload the weapon,there is weapon reload message...
Reply
#7

Create a timer that checks for players reloading
Код:
SetTimer("CheckReloadingWeapon", 300, 1);
Put that to OnGameModeInit (please note that it's called every 300ms, might make your server lag, but if you increase it might not detect it.
Reply
#8

Better version, this works 100%, I tested it.
OnGameModeInit:

Код:
    SetTimer("CheckReloadingWeapon", 1500, 1);
Somewhere:

Код:
forward CheckReloadingWeapon();
public CheckReloadingWeapon()
{
   for(new i = 0; i < MAX_PLAYERS; i++)
	{
 		if(GetPlayerWeaponState(i) == WEAPONSTATE_RELOADING) //&& laststate[i] != WEAPONSTATE_RELOADING)
  		{
 			if(IsPlayerConnected(i))
   			{
				new  string [128], wName[24], pName[24], wep;
				wep = GetPlayerWeapon(i);
			   	GetWeaponName(wep, wName, sizeof(wName));
			   	GetPlayerName(i, pName, sizeof(pName));
			   	format(string, sizeof(string), "%s is reloading. Weapon: %s - Ammo %d", pName, wName, GetPlayerAmmo(i));
			   	SendClientMessageToAll(0xFF0000FF, string);
   			}
  		}
 	}
}
Reply
#9

Now is working,thanks all (:
Reply
#10

Quote:
Originally Posted by Gh05t_
Посмотреть сообщение
It has been defined and declared within the for loop type structure. The preceding if statement contains i, which I assume is supposed to be proceeding the for loop type instruction.
Oh. Well damn...
I forgot you are supposed to define them in the for statement like he did... Live and learn...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)