PDA

View Full Version : Help with hudelement for rank-system



EvoloZz
2nd January 2013, 14:48
I was trying to make crappy rank system (just for test), but I already get errors. So I made huds and everything for it, but the error seems to occur in the hud, even tho i think it seems to be alright.
WARNING: The rank system is really crappy!!
So here's the error:

******* script runtime error *******
type string is not a float: (file 'maps/mp/gametypes/_rifles.gsc', line 750)
self.rankvalue setvalue(self.rank_name);
*

I dont even understand what it says, but ehh.
Here's the main script:

init()
{
self thread onPlayerConnect();
self thread ranks();
}

onPlayerConnect()
{
if(!isDefined(self.xp))
self.xp = 0;
}

ranks()
{
xp = self.xp;

switch(xp)
{
case 0:
self.rank = 1;
self.rank_name = "Private First Class";
break;

case 30:
self.rank = 2;
self.rank_name = "Private First Class I";
self rankup();
break;

case 120:
self.rank = 3;
self.rank_name = "Private First Class II";
self rankup();
break;
}
}

rankup()
{
self iprintlnbold("You have been promoted to ^3" + self.rank_name);
}

And if important, here's the hud:

Rank()
{
if(!isDefined(self.rank_name))
{
self thread maps\mp\gametypes\_ranks::init();
}
self endon("disconnect");
self endon("joined_spectators");

if(!isDefined(self.rankhud))
{
self.rankhud = newClientHudElem(self);
self.rankhud.horzAlign = "left";
self.rankhud.vertAlign = "top";
self.rankhud.x = 6;
self.rankhud.y = 70;
self.rankhud.sort = 1;
self.rankhud.alpha = 1;
self.rankhud.fontScale = 2;
self.rankhud.archived = true;
self.rankhud setText(game["hud_rank"]);
}

if(!isDefined(self.rankvalue))
{
self.rankvalue = newClientHudElem(self);
self.rankvalue.x = 6;
self.rankvalue.y = 90;
self.rankvalue.fontScale = 1.8;
}

while(1)
{
wait(0.3);
self.rankvalue setvalue(self.rank_name);
}
}
I have tried some ways to fix it, but no progress. I am sure there is an error in the scripts, but I am just blind -_-

KillerBoB
2nd January 2013, 14:59
Do it with setText instead of setvalue and precache it

serthy
2nd January 2013, 15:49
type string is not a float
the game said it

string: "This is a string" "012wsjsj!"
int: 0 1 2 3 -5 -100
float: 1.000 -0.3245 19.432
localized-string: &"Textextext" &"LOCALIZED_STRING"

setText() requrires a precached localized-string (precacheString( &"locstring" ))

EDIT1: oupps KillerBoB was faster :o

EDIT2:
script runtime error >>> there is a logical error in your script (wrong datatypes etc.) that will appear and crash your server while the game runs (runtime...)
script compile error >>> there is a syntax error in your script, the game wouldnt start at all

IzNoGoD
2nd January 2013, 16:04
Thread renamed.

EvoloZz
2nd January 2013, 16:57
Thanks for help, but how do I set value for the precached string? I mean self.rank_name

KillerBoB
2nd January 2013, 17:39
game["rank1"] = &"Rank 1";
precacheString(game["rank1"]);
self.rankvalue setText(game["rank1"]);

EvoloZz
2nd January 2013, 19:32
I thought there is an automated way to do it, seems like I need to precache strings for every rank -_-

Peterlankton
2nd January 2013, 21:56
Here's an automated way:



level.ranknames = [];
level.ranknames[0] = &"Rank 1";
level.ranknames[1] = &"Rank 2";
for(i=0;i<level.ranknames.size;i++)
{
precacheString(level.ranknames[i]);
}

kung foo man
3rd January 2013, 02:58
Just a word on performance: you are using an endless-loop on every player to update the rank every 0.3 seconds. Instead of that, better add a function like:



addXP(xp)
{
player = self;

// in this function also save the xp etc..., but only want to show this:

rank_name = getRankName(player); // your function somewhere
player.rankvalue setText(rank_name);
}

// somewhere in player_killed-callback:
player addXP(10);


So you dont need a set-it-forever-again-thread but only one obvious call, with does also update the huds.

EvoloZz
3rd January 2013, 15:21
I just updated the code entirely, and using value instead of rank names, much easier :D