SA-MP Forums Archive
Problem - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Problem (/showthread.php?tid=306068)



Problem - Face9000 - 24.12.2011

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.


Re: Problem - Mini` - 24.12.2011

Код:
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"...


Re: Problem - spedico - 24.12.2011

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


Re: Problem - Gh05t_ - 24.12.2011

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.


Re: Problem - spedico - 24.12.2011

Код:
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.


Re: Problem - Face9000 - 24.12.2011

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


Re: Problem - spedico - 25.12.2011

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.


Re: Problem - spedico - 25.12.2011

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);
   			}
  		}
 	}
}



Re: Problem - Face9000 - 25.12.2011

Now is working,thanks all (:


Re: Problem - Mini` - 25.12.2011

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