Command tells much.....

Started by FarisDon, Feb 19, 2016, 12:37 PM

Previous topic - Next topic

FarisDon

Hey, Folks! Well, I actually made this codeelse if ( cmd =="bla")
 {
     
          foreach(a,val in players)
         {
                local plr = FindPlayer ( players[a].tointeger() ), b = 0;
                if ( plr )
                {
                        if (GetKills( plr ) == 3 )
                        {
                        b++;
                        ClientMessage("" + player.Name + " is asking, for bla",plr,255,255,0);
                       } 
                        if ( b == 0 ) ClientMessage("No player with 3 kills yet",player,255,255,0);
 
                     
                   }
                 
 
      }

}
As you can see, their isn't any kind of error, but the thing I actually want to ask, from you guys, that if their are 2 players in the server, and one is having 3 kills it returns 1 time( with 2 players) ClientMessage("No player with 3 kills yet",player,255,255,0); if nobody is having 3 kills it returns 2 times(with 2 players) ClientMessage("No player with 3 kills yet",player,255,255,0);, ClientMessage("No player with 3 kills yet",player,255,255,0);if 100, then 100 times( with 100 PLAYERS ) ClientMessage("No player with 3 kills yet",player,255,255,0);......I've actually tried much to fix it, but unable to do, so, I don't have any algroithm to fix The messages of 2-100 times, I just want the message to come once, if their isn't any body with Kills, just once, do you guys have any idea how to fix this :(?
P.S : - Sorry, for my bad english, but hope you are getting what I mean.
EDIT: just want to ask that how can i return the message once, instead that the message is coming according to the number of Players who don't have 3 kills.

DizzasTeR

that's because you are running a foreach loop, the loop contains all the online players, that loop will loop as how many players are there, 2 players, twice, 3 players thrice and so forth. Have a look here
else if ( cmd =="bla")
 {
local iCount;

foreach( index, iPlayer in players)
{
if( iPlayer ) {

if( GetKills( iPlayer ) == 3 )
            {
iCount++;
ClientMessage( player.Name + " is asking, for bla",plr,255,255,0);
}
}

if( iCount == 0 )
ClientMessage( "No player with 3 kills yet",player,255,255,0);
}
}

FarisDon

#2
Quote from: Doom_Kill3R on Feb 19, 2016, 12:43 PMthat's because you are running a foreach loop, the loop contains all the online players, that loop will loop as how many players are there, 2 players, twice, 3 players thrice and so forth. Have a look here
else if ( cmd =="bla")
 {
local iCount;

foreach( index, iPlayer in players)
{
if( iPlayer ) {

if( GetKills( iPlayer ) == 3 )
            {
iCount++;
ClientMessage( player.Name + " is asking, for bla",plr,255,255,0);
}
}

if( iCount == 0 )
ClientMessage( "No player with 3 kills yet",player,255,255,0);
}
}
Well, I guess it is surely gonna work, but just one question, i've seen many snippets being released on the other forum as your is also like them that, so, i'm curious to know the reason why we actually left space over their( in the code you will see), and sent the message(1) instead of not their(0)else if ( cmd =="bla")
 {
local iCount;

foreach( index, iPlayer in players)
{
if( iPlayer ) {

if( GetKills( iPlayer ) == 3 )
            {
iCount++;
ClientMessage( player.Name + " is asking, for bla",plr,255,255,0);
}
//why we didn't wrote over here(0)
}

if( iCount == 0 ) // why we wrote over here ( 1 )
ClientMessage( "No player with 3 kills yet",player,255,255,0);// why we wrote over here ( 1 )
}
}
it's mostly like we do if ( cmd == "bla " ) { if (  player.IsSpawned ) { if ( player.Vehicle ) { //bla } else ClientMessage("no spawned",player,255,255,0); } else ClientMessage("no vehicle",player,255,255,0) }   as you can see it's not in rythm, and wrong message, it's in rythm if ( cmd == "bla " ) { if (  player.IsSpawned ) { if ( player.Vehicle ) { //bla } else ClientMessage("no vehicle",player,255,255,0); } else ClientMessage("no spawned",player,255,255,0) } so basically why the message isn't their in the first row, instead of 2nd ?

KAKAN

Well if you put it to 0 and there are no players online, then the 2nd message, which is at 1, will not appear.
It's something like:
if( player ){
if( player.IsSpawned ) iCount++;
if( iCount != 0 ) Message("NO!!!");
}
Now think, what would happen if there are no players? Will the message "NO!!!" will show up? Answer is no. In your case, it's the same. Hope you got it.
oh no

FarisDon

Quote from: KAKAN on Feb 19, 2016, 01:32 PMWell if you put it to 0 and there are no players online, then the 2nd message, which is at 1, will not appear.
It's something like:
if( player ){
if( player.IsSpawned ) iCount++;
if( iCount != 0 ) Message("NO!!!");
}
Now think, what would happen if there are no players? Will the message "NO!!!" will show up? Answer is no. In your case, it's the same. Hope you got it.
-_- i'm seriously thinking, it doesn't even make sense, Kakan, if there will be no players, so a ghost can't use this command( I mean obviously their would be some/one player in the server which used this cmd ).
I guess, I need more sensible reason here.

FarisDon

#5
Quote from: Doom_Kill3R on Feb 19, 2016, 12:43 PMthat's because you are running a foreach loop, the loop contains all the online players, that loop will loop as how many players are there, 2 players, twice, 3 players thrice and so forth. Have a look here
else if ( cmd =="bla")
 {
local iCount;

foreach( index, iPlayer in players)
{
if( iPlayer ) {

if( GetKills( iPlayer ) == 3 )
            {
iCount++;
ClientMessage( player.Name + " is asking, for bla",plr,255,255,0);
}
}

if( iCount == 0 )
ClientMessage( "No player with 3 kills yet",player,255,255,0);
}
}
Eh, Sir. #Dhoom, ._. as you can see "plr" doesn't exist in this whole cmd, sorry, I don't really like to point out mistake from your code, but anyway ._. the code doesn't worked, showed no error, but also doesn't worked.I even change plr to iPlayer.
Edit : - So I just changed a bit of these functions to this
else if ( cmd =="bla")
 {
   local iCount = 0;
   
   foreach( index, iPlayer in players)
   {
                local plr = FindPlayer ( iPlayer);
      if( iPlayer )
                     {
      
         if( GetKills( iPlayer ) == 3 )
            {
            iCount++;
            ClientMessage( player.Name + " is asking, for bla",plr,255,255,0);
         }
      }
      
      if( iCount == 0 ) ClientMessage( "No player with 3 kills yet",player,255,255,0);
   }
}Well as you can see changed iCount; to iCount = 0; to define that it's actually an integer, and just want to find the Players using FindPlayer, which made the function worked great, however in the first code plr wasn't defined, you can see in your Code, Sir Dhoom, but still :( i'm not getting why we didn't used if( iCount == 0 ) ClientMessage( "No player with 3 kills yet",player,255,255,0); in the second row, but however, it's a noobish thing, even if i can solve a code, I should really now the actually theme about it mean, like i just want to know why 3rd row, not the second? however it stills hows me thrice, forth, and etc. :(

DizzasTeR

Your English is too weak, I can't exactly understand what you're trying to say. The code I gave you must work, yes that plr can be replaced. Change every 'player' or 'plr' to iPlayer and try.

FarisDon

#7
Quote from: Doom_Kill3R on Feb 19, 2016, 04:07 PMYour English is too weak, I can't exactly understand what you're trying to say. The code I gave you must work, yes that plr can be replaced. Change every 'player' or 'plr' to iPlayer and try.
Well, it's gives no error, but also shows nothing :|

DizzasTeR

else if ( cmd =="bla")
{
    local iCount;
 
    foreach( index, iPlayer in players )
    {
        local plr = FindPlayer( iPlayer );
        if( plr ) {
            if( GetKills( iPlayer ) == 3 )
            {
                iCount++;
                ClientMessage( player.Name + " is asking, for bla", plr, 255, 255, 0 );
            }
    }

        if( iCount == 0 )
        ClientMessage( "No player with 3 kills yet", player, 255, 255, 0 );
    }
}

I think you are storing IDs of player in the 'players' array so ofcourse we need to use FindPlayer to get the instance then use the Name var. We can't do that on ID.

FarisDon

#9
Quote from: Doom_Kill3R on Feb 19, 2016, 04:25 PMelse if ( cmd =="bla")
{
    local iCount;
 
    foreach( index, iPlayer in players )
    {
        local plr = FindPlayer( iPlayer );
        if( plr ) {
            if( GetKills( iPlayer ) == 3 )
            {
                iCount++;
                ClientMessage( player.Name + " is asking, for bla", plr, 255, 255, 0 );
            }
    }

        if( iCount == 0 )
        ClientMessage( "No player with 3 kills yet", player, 255, 255, 0 );
    }
}

I think you are storing IDs of player in the 'players' array so ofcourse we need to use FindPlayer to get the instance then use the Name var. We can't do that on ID.
else if ( cmd =="bla")
{
    local iCount;
 
    foreach( index, iPlayer in players )
    {
        local plr = FindPlayer( iPlayer );
        if( plr ) {
            if( GetKills( iPlayer ) == 3 )
            {
                iCount++;
                ClientMessage( player.Name + " is asking, for bla", plr, 255, 255, 0 );
            }
  if( iCount == 0 )
        ClientMessage( "No player with 3 kills yet", player, 255, 255, 0 );
// why aren't you keeping this over here?   }

     
    }
}

FarisDon

However it still gives the same error "Name" doesn't exist. ._.

Xmair

#11
else if ( cmd =="bla")
{
    local iCount;
 
    foreach( index, iPlayer in players )
    {
        local plr = FindPlayer( iPlayer );
        if( plr ) {
            if( GetKills( plr ) == 3 ) // You used iPlayer here, huh, such a momo =..=
            {
                iCount++;
                ClientMessage( player.Name + " is asking, for bla", plr, 255, 255, 0 ); // you nie define 'player'
            }
    }

        if( iCount == 0 )
        ClientMessage( "No player with 3 kills yet", player, 255, 255, 0 );// nie player
    }
}

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

KAKAN

#12
Quote from: [TBS]Destroyer on Feb 19, 2016, 04:35 PMHowever it still gives the same error "Name" doesn't exist. ._.
Because we're using the instance as plr and not player.
Use this code:-
else if ( cmd =="bla")
{
    foreach( index, iPlayer in players )
    {
        local plr = FindPlayer( iPlayer );
            if( GetKills( plr ) == 3 ) ClientMessage( plr.Name + " is asking, for bla", plr /*It should be player I think*/ , 255, 255, 0 );
       else ClientMessage( "No player with 3 kills yet", player, 255, 255, 0 );
    }
}
oh no

FarisDon

#13
Quote from: KAKAN on Feb 19, 2016, 04:47 PM
Quote from: [TBS]Destroyer on Feb 19, 2016, 04:35 PMHowever it still gives the same error "Name" doesn't exist. ._.
Because we're using the instance as plr and not player.
Use this code:-
else if ( cmd =="bla")
{
    foreach( index, iPlayer in players )
    {
        local plr = FindPlayer( iPlayer );
            if( GetKills( plr ) == 3 ) ClientMessage( plr.Name + " is asking, for bla", plr /*It should be player I think*/ , 255, 255, 0 );
       else ClientMessage( "No player with 3 kills yet", player, 255, 255, 0 );
    }
}
What's the point of this Cmd? it's works exactly same as else if ( cmd =="bla")
 {
     
          foreach(a,val in players)
          {
                local plr = FindPlayer ( players[a].tointeger() ), b = 0;
                if ( plr )
                {
                        if (GetKills( plr ) == 3 )
                        {
                        b++;
                        ClientMessage("" + player.Name + " is asking, for bla",plr,255,255,0);
                       } 
                        if ( b == 0 ) ClientMessage("No player with 3 kills yet",player,255,255,0);
 
                     
                   }
                 
 
      }

}
man, Kakan :|
and as, for you, Xmair
else if ( cmd =="bla")
{
    local iCount;
 
    foreach( index, iPlayer in players )
    {
        local plr = FindPlayer( iPlayer );
        if( plr ) {
            if( GetKills( plr ) == 3 ) // You used iPlayer here, huh, such a momo =..=
            {
                iCount++;
                ClientMessage( player.Name + " is asking, for bla", plr, 255, 255, 0 ); // you nie define 'player'
            }
    }
Well, i've already changed iPlayer, to plr, forgot to tell lol sorry, but there is also a error that we were unable to see it was tiny, anyway I've to change iCount to iCount = 0; since iCount is null in that way, and we can't make it iCount++;
well the other thing is that i changed that code to this if ( iCount == 0 )ClientMessage("BLA",player,255,255,0),iCount++; which respectively just give it once even if their are hundred players together :P; However,nobody still didn't explained me why we didn't used that above the barrack -_- else if ( cmd =="bla")
{
    local iCount = 0;
 
    foreach( index, iPlayer in players )
    {
        local plr = FindPlayer( iPlayer );
        if( plr ) {
            if( GetKill( plr ) == 3 )
            {
                iCount++;
                ClientMessage( player.Name + " is asking, for bla", plr, 255, 255, 0 );
            }
    }
 if ( iCount == 0 )ClientMessage("BLA",player,255,255,0), iCount++; // why we put this over here not above( before this barrack)

}
}
Edit: it just works fine, but -_- it really sucks at one point, it shows the message to the people who isn't even having the 3 kills :(

KAKAN

Meh, what's the point of using Icount?
use the one I gave, but I have one question.
In this script:-
else if ( cmd =="bla")
{
    foreach( iPlayer in players )
    {
        local plr = FindPlayer( iPlayer );
            if( GetKills( plr ) == 3 ) ClientMessage( plr.Name + " is asking, for bla", plr /*It should be player I think*/ , 255, 255, 0 );
       else ClientMessage( "No player with 3 kills yet", player, 255, 255, 0 );
    }
}
ClientMessage( plr.Name + " is asking, for bla", plr , 255, 255, 0 );
Why do you give the message to the plr?

And according to your problem, I think you need to show us the GetKill function, make sure it's correct
oh no