Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: FarisDon on Feb 19, 2016, 12:37 PM

Title: Command tells much.....
Post by: FarisDon on Feb 19, 2016, 12:37 PM
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.
Title: Re: Command tells much.....
Post by: DizzasTeR on Feb 19, 2016, 12:43 PM
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);
}
}
Title: Re: Command tells much.....
Post by: FarisDon on Feb 19, 2016, 01:03 PM
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 ?
Title: Re: Command tells much.....
Post by: KAKAN on Feb 19, 2016, 01:32 PM
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.
Title: Re: Command tells much.....
Post by: FarisDon on Feb 19, 2016, 02:59 PM
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.
Title: Re: Command tells much.....
Post by: FarisDon on Feb 19, 2016, 03:09 PM
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. :(
Title: Re: Command tells much.....
Post by: DizzasTeR on Feb 19, 2016, 04:07 PM
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.
Title: Re: Command tells much.....
Post by: FarisDon on Feb 19, 2016, 04:17 PM
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 :|
Title: Re: Command tells much.....
Post by: DizzasTeR on Feb 19, 2016, 04:25 PM
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.
Title: Re: Command tells much.....
Post by: FarisDon on Feb 19, 2016, 04:31 PM
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?   }

     
    }
}
Title: Re: Command tells much.....
Post by: FarisDon on Feb 19, 2016, 04:35 PM
However it still gives the same error "Name" doesn't exist. ._.
Title: Re: Command tells much.....
Post by: Xmair on Feb 19, 2016, 04:45 PM
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
    }
}
Title: Re: Command tells much.....
Post by: 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 );
    }
}
Title: Re: Command tells much.....
Post by: FarisDon on Feb 19, 2016, 05:05 PM
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 :(
Title: Re: Command tells much.....
Post by: KAKAN on Feb 19, 2016, 05:39 PM
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
Title: Re: Command tells much.....
Post by: DizzasTeR on Feb 19, 2016, 05:48 PM
I'm not putting it there just to avoid it from being called several times since it needs to be called only once. It may also interfere with the loop and may result wrong info.
Title: Re: Command tells much.....
Post by: FarisDon on Feb 19, 2016, 07:24 PM
Quote from: Doom_Kill3R on Feb 19, 2016, 05:48 PMI'm not putting it there just to avoid it from being called several times since it needs to be called only once. It may also interfere with the loop and may result wrong info.
Well, Dhoom Sir; actually the problem is that if we look to the Code, it isn't showing it once; however it is showing to those persons whom, it doesn't even have to show :|
Title: Re: Command tells much.....
Post by: KAKAN on Feb 20, 2016, 05:41 AM
Well, I got your problem now, here's the fixed code.
else if ( cmd =="bla")
{
local buffer = "";
    foreach( iPlayer in players ) if( GetKills( FindPlayer( iPlayer ) ) == 3 ) buffer = buffer + " " + FindPlayer( iPlayer ).Name;
if( buffer != "" ) ClientMessage("Players with 3 kills: [ " + buffer + " ]", player , 255, 255, 0 );
       else ClientMessage( "No player with 3 kills yet", player, 255, 255, 0 );
}
Title: Re: Command tells much.....
Post by: FarisDon on Feb 20, 2016, 07:40 AM
Quote from: KAKAN on Feb 20, 2016, 05:41 AMWell, I got your problem now, here's the fixed code.
else if ( cmd =="bla")
{
local buffer = "";
    foreach( iPlayer in players ) if( GetKills( FindPlayer( iPlayer ) ) == 3 ) buffer = buffer + " " + FindPlayer( iPlayer ).Name;
if( buffer != "" ) ClientMessage("Players with 3 kills: [ " + buffer + " ]", player , 255, 255, 0 );
       else ClientMessage( "No player with 3 kills yet", player, 255, 255, 0 );
}
Eh, it's already been fixed ._. i'm just waiting, for #Dhoom to answer why he didn't used the code in the 2nd row instead of 3rd. Anyway, for me I guess we did that cause we have to return something in end after all queries and stuff have been made, like just you did ._.
Title: Re: Command tells much.....
Post by: DizzasTeR on Feb 20, 2016, 08:16 AM
Its not 'Dhoom'.

Destroyer, script executes in sequence so if you send the message first and store the data later what will happen? Common Sense.
Title: Re: Command tells much.....
Post by: FarisDon on Feb 20, 2016, 07:48 PM
Quote from: Doom_Kill3R on Feb 20, 2016, 08:16 AMIts not 'Dhoom'.

Destroyer, script executes in sequence so if you send the message first and store the data later what will happen? Common Sense.
Uhm, right! Thanks :)