PDA

View Full Version : best player map



malyczolg
11th July 2013, 16:44
hello , why first_player_name is not defined


callback_playerconnect()
{
.....
self thread checkstatus();
}


checkstatus()
{
level.brakdanych = &"^1BRAK DANYCH";

players = getentarray("player", "classname");
highexp = undefined;
name = undefined;
highrank = undefined;


for(i = 0; i < players.size; i++)
{
player = players[i];

if(isdefined(player.pers["team"]) && player.pers["team"] == "spectator")
continue;

if(!isdefined(highexp))
{
highexp = player.sexp;
name = player.name;
highrank = player.poziom;
continue;
}


wait 0.01;

if(isDefined(name))
first_player_name = name;
else
first_player_name = level.brakdanych;

if(isDefined(highexp))
first_player_exp = highexp;
else
first_player_exp = level.brakdanych;

if(isDefined(highrank))
first_player_rank = highrank;
else
first_player_rank = level.brakdanych;

wait 3;

players[i] iprintlnbold("name is" + name +"fp name is" + first_player_name);

if(isdefined(first_player_name))
players[i] setClientCvar("first_player", "First Player: Name:" + first_player_name + "His Exp IS:" + first_player_exp + "His rank IS:" + first_player_rank);
else
players[i] setClientCvar("first_player", "First Player: Name:" + "BRAK DANYCH" + "His Exp IS:" +"BRAK DANYCH" + "His rank IS:" + "BRAK DANYCH");

}
}

IzNoGoD
11th July 2013, 17:44
Dude,
We are NOT your personal helpdesk. Please consider narrowing down the problem yourself, use some iprintlns, use some common sense.

If you need the community for every little script you are writing, you are better off not writing the scripts. It will not teach you anything if others do it for you.

I see no effort in your post to debug ANYTHING AT ALL. I dont see error logs, I dont see additional iprintlns, nothing.

The only thing we have to go on here is you saying "why is variable X not defined", while only providing a script WITHOUT any comments in it, without telling us the purpose of this script, nothing.

Please consider doing some of the stuff the community does yourself. Most of us have got the cod scripting as a hobby, we do not have a job supporting you. Providing us with insufficient data over and over again will upset us, and lead to posts like this.

Good day sir.

Peterlankton
11th July 2013, 18:11
If you need the community for every little script you are writing, you are better off not writing the scripts.

Couldn't have said it better myself.
I know what the script is provided to do. But seriously, the way it's scripted does not make any sense at all.
No one becomes perfect over night. I remember the good old times. I'd never debug, but I would get it working anyway. I did not know about 'developer 1', no, the only errors I got were 'Unknown Function @46436'. Sometimes just a semicolon was missing and after hours of searching I found it. So guys, I am telling you, THAT made me good at that shite. And malyczolg, you are complaining about an indefined var. Come on, you're better than that.

Earliboy
11th July 2013, 19:14
Well, if someone posts a problem and allready tried to find the problem by himself, then its fine for me.
But if someone comes ALWAYS if he gets an error WITHOUT trying to fix by himself, i won't help.
Specialy without sending any errors or explains. I'm NOT going to edit my mod to insert an script. It takes much time and all I will get is the same error he got.

megazor
12th July 2013, 00:04
I can see at least two mistakes.


wait 0.01;

if(isDefined(name))
first_player_name = name;
else
first_player_name = level.brakdanych;

Firstly, wait 0.01 will be rounded upwards to 0.05 unless you have sv_fps set to 100.
Secondly, in CoD2 you have to define all variables outside if statements.

And you should really try some debugging :)

IzNoGoD
12th July 2013, 10:08
Secondly, in CoD2 you have to define all variables outside if statements.

Not true.



if(a == b)
c = 1;
else
c = 2;
iprintln(c);

will not produce errors

but


if(a == b)
c = 1;
else if(a != b)
c = 2;
iprintln(c);

will produce errors, for the script cannot be sure that it is actually called, although you can see it will.

also,



somerandomcode();
return;
morerandomcode();

will give the "unreachable code" error.



somerandomcode();
if(true)
return;
morerandomcode();

will not.

CoD2 is weird.

randall
12th July 2013, 10:43
Write first_player_name = undefined; the first line of the function and it will work.

EDIT: Oh, and i forgot: You cannot embed localizedstrings in setClientCvar().

malyczolg
12th July 2013, 19:59
hi , thanks work
but if i have 100exp bot have 200exp l'm on the dvar
Who can help me?

randall
12th July 2013, 22:24
hi , thanks work
but if i have 100exp bot have 200exp l'm on the dvar
Who can help me?

Because your script is totally wrong. The biggest mistake is the waiting in the 'for' cycle. Try this, it causes the result you'd like to see: (not tested!)


checkStatus()
{
level.brakdanych = "^1BRAK DANYCH";
first = [];
first["player"] = undefined;
first["name"] = level.brakdanych;
first["exp"] = level.brakdanych;
first["rank"] = level.brakdanych;

players = getEntarray("player", "classname");
for (i = 0; i < players.size; i++)
{
player = players[ i ];

if (! isDefined(player.pers["team"]) || player.pers["team"] == "spectator")
continue;

if (! isDefined(first["player"]) || player.sexp > first["exp"])
{
first["player"] = player;
first["name"] = player.name;
first["exp"] = player.sexp;
first["rank"] = player.poziom;
}
}

for (i = 0; i < players.size; i++)
{
player = players[ i ];

player setClientCvar("first_player",
"First Player: Name:" + first["name"] +
" His Exp IS:" + first["exp"] +
" His rank IS:" + first["rank"]);
}
}

malyczolg
12th July 2013, 23:03
randall very thanks it works , can u tell me how add the second player?

Tally
13th July 2013, 06:36
Because your script is totally wrong. The biggest mistake is the waiting in the 'for' cycle. Try this, it causes the result you'd like to see: (not tested!)


checkStatus()
{
level.brakdanych = "^1BRAK DANYCH";
first = [];
first["player"] = undefined;
first["name"] = level.brakdanych;
first["exp"] = level.brakdanych;
first["rank"] = level.brakdanych;

players = getEntarray("player", "classname");
for (i = 0; i < players.size; i++)
{
player = players[ i ];

if (! isDefined(player.pers["team"]) || player.pers["team"] == "spectator")
continue;

if (! isDefined(first["player"]) || player.sexp > first["exp"])
{
first["player"] = player;
first["name"] = player.name;
first["exp"] = player.sexp;
first["rank"] = player.poziom;
}
}

for (i = 0; i < players.size; i++)
{
player = players[ i ];

player setClientCvar("first_player",
"First Player: Name:" + first["name"] +
" His Exp IS:" + first["exp"] +
" His rank IS:" + first["rank"]);
}
}



player.sexp > first["exp"]

I have only looked at the code casually, but isn't first["exp"] a string (level.brakdanych = "^1BRAK DANYCH")? So, how is the game not throwing an error saying that an int can't be compared to a string?

randall
13th July 2013, 10:22
player.sexp > first["exp"]

I have only looked at the code casually, but isn't first["exp"] a string (level.brakdanych = "^1BRAK DANYCH")? So, how is the game not throwing an error saying that an int can't be compared to a string?

You're right, not the best solution to set different types for a variable, but this is the simplest way. Actually the first condition (! isDefined(first["player"])) is undefined, so the script will not check the second condition, and the first["exp"] will get a numeric value. In the practice it don't be a problem. In theory :D

Tally
13th July 2013, 10:36
Looking at the code a bit more, I can see that all it does is assign the very first player to the value first["player"] without any conditions at all. So, pretty pointless really. What he needs to do is set a condition for who the first player is (possibly by setting a numerical value for first["exp"]) and attenuate the players on that basis.

What I would do is compare every player's XP, and attenuate the players on that basis. Pretty much like 1st, 2nd, and 3rd are attenuated placements based on scores in other well known end-of-game scripts.

randall
13th July 2013, 10:52
Well, it would the best sort the players by exp, and only get the first 3 elements of the array.

http://en.wikipedia.org/wiki/Insertion_sort


randall very thanks it works , can u tell me how add the second player?

This script is only get the best player, if you wanna get the 2nd and 3rd players, then you have to rewrite the all function. See above.

malyczolg
13th July 2013, 14:26
secondplayer()
{
level.brakdanych = "^1BRAK DANYCH";
second = [];
second["player"] = undefined;
second["name"] = level.brakdanych;
second["exp"] = level.brakdanych;
second["rank"] = level.brakdanych;

players = getEntarray("player", "classname");
for (i = 0; i < players.size; i++)
{
player = players[ i ];

if (! isDefined(player.pers["team"]) || player.pers["team"] == "spectator")
continue;

if (! isDefined(second["player"]) || player.sexp > second["exp"])
{
second["player"] = player;
second["name"] = player.name;
second["exp"] = player.sexp;
second["rank"] = player.poziom;
}
}

for (i = 0; i < players.size; i++)
{
player = players[ i ];

player setClientCvar("second_player",
"second Player: Name:" + second["name"] +
" His Exp IS:" + second["exp"] +
" His rank IS:" + second["rank"]);
}
}




if (! isDefined(second["player"]) || player.sexp > second["exp"])
{
second["player"] = player;
second["name"] = player.name;
second["exp"] = player.sexp;
second["rank"] = player.poziom;
}


how get best second player ?

randall
13th July 2013, 15:03
If you rename a variable the result still not going to change xd Forget this script, i wrote it before you said you need 2nd and 3rd players too. I copied a link above about the insertion sort, use that to sort the players by exp. After you're ready, you have to only print (or put in cvars) the first 3 elements of the sorted array.

EDIT: I thought you will never write the script, so:


checkStatus()
{
level.brakdanych = "^1BRAK DANYCH";
places = [];
places[0] = []; // 1st player
places[1] = []; // 2nd player
places[2] = []; // 3rd player

players = getEntArray("player", "classname");

// take invalid players from the array
array = [];
for (i = 0; i < players.size; i++)
{
player = players[ i ];

if (! isDefined(player.pers["team"]) || player.pers["team"] == "spectator")
continue;

array[ array.size ] = players[ i ];
}

// sort the 'players' array by exp
array = array_sort_by_exp(array);

// set places
for (i = 0; i < places.size; i++)
{
if (isDefined(array[ i ])) {
places[ i ]["player"] = array[ i ];
places[ i ]["name"] = array[ i ].name;
places[ i ]["exp"] = array[ i ].sexp;
places[ i ]["rank"] = array[ i ].poziom;
} else {
places[ i ]["player"] = undefined;
places[ i ]["name"] = level.brakdanych;
places[ i ]["exp"] = level.brakdanych;
places[ i ]["rank"] = level.brakdanych;
}
}

// set cvars for all players
for (i = 0; i < players.size; i++)
{
player = players[ i ];

player setClientCvar("first_player",
"first Player: Name:" + places[0]["name"] +
" His Exp IS:" + places[0]["exp"] +
" His rank IS:" + places[0]["rank"]);
player setClientCvar("second_player",
"second Player: Name:" + places[1]["name"] +
" His Exp IS:" + places[1]["exp"] +
" His rank IS:" + places[1]["rank"]);
player setClientCvar("third_player",
"third Player: Name:" + places[2]["name"] +
" His Exp IS:" + places[2]["exp"] +
" His rank IS:" + places[2]["rank"]);
}
}

array_sort_by_exp(array)
{
temp = array;

for (i = 0; i < temp.size - 1; i++)
{
for (j = i + 1; j < temp.size; j++)
{
if (temp[ i ].sexp > temp[ j ].sexp)
{
var = temp[ i ];
temp[ i ] = temp[ j ];
temp[ j ] = var;
}
}
}

return temp;
}

IzNoGoD
13th July 2013, 16:06
getbestplayers(amount)
{
players = getentarray("player", "classname");
if(amount > players.size)
amount = players.size;
result = [];
for(i = 0; i < amount; i++)
{
best = i;
for(j = i + 1; j < players.size; j++)
{
if(players[j].score > players[best].score)
best = j;
}
tmp = players[best];
players[best] = players[i];
players[i] = tmp;
result[result.size] = tmp;
}
return result;
}
Untested code

malyczolg
13th July 2013, 20:07
randal your script almost work ,but script show top3 worst player not the best.
can u fix it?

Peterlankton
13th July 2013, 20:33
randal your script almost work ,but script show top3 worst player not the best.
can u fix it?

Why don't you try it on your own first? It's not that hard..

randall
13th July 2013, 21:05
randal your script almost work ,but script show top3 worst player not the best.
can u fix it?

Please, use your brains just a little :S Try to understand my script line by line and don't be a "copypaste-modder". A bit help: u need to change only an operator.

Tally
13th July 2013, 21:22
randal your script almost work ,but script show top3 worst player not the best.
can u fix it?

That's because you have no criteria to put any players ahead of others. You need to do something like IznoGod did with his score ranking. After all, that is what you are doing - ranking players. Whether it is XP or score, you need to find something a player has done to make them better than the others, and then use it to place them into position.

malyczolg
14th July 2013, 08:43
ok work thanks :)


array_sort_by_exp(array)
{
temp = array;

for (i = 0; i < temp.size - 1; i++)
{
for (j = i + 1; j < temp.size; j++)
{
if (temp[ i ].sexp < temp[ j ].sexp)
{
var = temp[ i ];
temp[ i ] = temp[ j ];
temp[ j ] = var;
}
}
}

return temp;
}

malyczolg
14th July 2013, 08:43
PLEASE CLOSE TOPIC :)

kung foo man
14th July 2013, 09:29
No need to close :)

NemanjA
2nd August 2013, 12:08
And how to save / load the stats?

kung foo man
2nd August 2013, 12:15
Just search this forum for "openfile"

NemanjA
10th August 2013, 09:50
Ye, the openfile, i know for it but it don't work... How to save the PLACES 1, 2, 3. So When the map ends to save the places, and on next map to load them, and to check if the places change and save it again... :D

kung foo man
10th August 2013, 09:57
You just load in player_connect() and save on player_disconnect() and endMap().

When you say something not worked, what did you actually tried?

NemanjA
10th August 2013, 10:03
I tried the same, i just get this error: uninitialised variable 'places'