Key to check player stats?
#1

Ok, i want it so that if a for example you presses the key LCTRL while on foot or 2 in car and is a level 3
pawn Код:
if(playerdata[playerid][level] == 3)
, it checks the nearest player to you within a radius of 10 and sees if they are the hacker team
pawn Код:
playerdata[playerid][team] == 3
, and if they are it charges them the players defined hack charge
pawn Код:
playerdata[playerid][charge]
and gives it to the level 3 player that checked the hacker. Its kinda complex (i think) but id love it if someone would help!

Whoever helps with this will get staff on my SA:MP Computer Wars server.
Reply
#2

https://sampwiki.blast.hk/wiki/GetPlayerKeys
https://sampwiki.blast.hk/wiki/OnPlayerKeyStateChange

Should get you quite somewhere. There is however no direct way to check a specific key (Like LCTRL or 'K'), only the special keys which actually do something in-game (Like entering vehicles or shooting guns)
Reply
#3

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    new Float:x,Float:y,Float:z;
   
    if(newkeys & KEY_FIRE)
    {
      if(!IsPlayerInAnyVehicle(playerid))
      {
       for(new i = 0; i < MAX_PLAYERS; i++)
       {
           if(IsPlayerConnected(i))
           {
                if(playerdata[i][team] == 3)
                {
                      GetPlayerPos(playerid, x, y, z);
                      if(IsPlayerInRangeOfPoint(i, 10, x, y, z))
                      {
                      new string[128],name[MAX_PLAYER_NAME];
                      GetPlayerName(i,name,sizeof(name));
                      format(string,sizeof(string),"HACKER TEAM: %s\n",name);
                      SendClientMessage(playerid, 0xFF8811FF, string);
                      }
                 }
            }
       }
   }
}
return 1;
}
Gave me fatal errors, but it was due I dont have your variables, like PlayerData. And also I didn't test, just compiled. And without your variables I compiled it normally
Reply
#4

It does not have the code to see if the player being check is hacker team tho. Can you revise it by chance?
Reply
#5

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    new Float:x,Float:y,Float:z;
    GetPlayerPos(playerid, x, y, z);
    if(newkeys & KEY_FIRE)
    {
      if(!IsPlayerInAnyVehicle(playerid))
      {
      if(playerdata[i][team] == 3) // Checks if the team is hacker 'here'
      {
       for(new i = 0; i < MAX_PLAYERS; i++)
       {
           if(IsPlayerConnected(i))
           {
                if(playerdata[i][team] == 3)
                {
                     
                      if(IsPlayerInRangeOfPoint(i, 10, x, y, z))
                      {
                      new string[128],name[MAX_PLAYER_NAME];
                      GetPlayerName(i,name,sizeof(name));
                      format(string,sizeof(string),"HACKER TEAM: %s",name);
                      SendClientMessage(playerid, 0xFF8811FF, string);
                      }
                 }
            }
       }
   }
}
}
return 1;
}
Reply
#6

blackwave, you should get the playerpos before the loop, less possible functions going off. also \n is pointless with SendClientMessage

edit: also 128 string size is way too big for that message
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)