Results 1 to 10 of 10

Thread: Help with hudelement for rank-system

  1. #1
    Sergeant EvoloZz's Avatar
    Join Date
    Sep 2012
    Location
    Helsinki, Finland
    Posts
    360
    Thanks
    314
    Thanked 167 Times in 120 Posts

    Help with hudelement for rank-system

    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:
    Code:
    ******* 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:
    Code:
    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:
    Code:
    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 -_-

  2. #2
    Private
    Join Date
    Nov 2012
    Posts
    15
    Thanks
    3
    Thanked 18 Times in 11 Posts
    Do it with setText instead of setvalue and precache it

  3. The Following 2 Users Say Thank You to KillerBoB For This Useful Post:

    EvoloZz (2nd January 2013),kung foo man (3rd January 2013)

  4. #3
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts
    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

    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
    Last edited by serthy; 2nd January 2013 at 14:53.

  5. The Following 2 Users Say Thank You to serthy For This Useful Post:

    EvoloZz (2nd January 2013),kung foo man (3rd January 2013)

  6. #4
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Thread renamed.

  7. The Following User Says Thank You to IzNoGoD For This Useful Post:

    kung foo man (3rd January 2013)

  8. #5
    Sergeant EvoloZz's Avatar
    Join Date
    Sep 2012
    Location
    Helsinki, Finland
    Posts
    360
    Thanks
    314
    Thanked 167 Times in 120 Posts
    Thanks for help, but how do I set value for the precached string? I mean self.rank_name

  9. #6
    Private
    Join Date
    Nov 2012
    Posts
    15
    Thanks
    3
    Thanked 18 Times in 11 Posts
    game["rank1"] = &"Rank 1";
    precacheString(game["rank1"]);
    self.rankvalue setText(game["rank1"]);

  10. The Following 2 Users Say Thank You to KillerBoB For This Useful Post:

    EvoloZz (2nd January 2013),kung foo man (3rd January 2013)

  11. #7
    Sergeant EvoloZz's Avatar
    Join Date
    Sep 2012
    Location
    Helsinki, Finland
    Posts
    360
    Thanks
    314
    Thanked 167 Times in 120 Posts
    I thought there is an automated way to do it, seems like I need to precache strings for every rank -_-

  12. #8
    Private
    Join Date
    Jul 2012
    Posts
    76
    Thanks
    9
    Thanked 56 Times in 38 Posts
    Here's an automated way:

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

  13. The Following 2 Users Say Thank You to Peterlankton For This Useful Post:

    EvoloZz (3rd January 2013),kung foo man (3rd January 2013)

  14. #9
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,011
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    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:

    Code:
    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.
    timescale 0.01

  15. The Following User Says Thank You to kung foo man For This Useful Post:

    EvoloZz (3rd January 2013)

  16. #10
    Sergeant EvoloZz's Avatar
    Join Date
    Sep 2012
    Location
    Helsinki, Finland
    Posts
    360
    Thanks
    314
    Thanked 167 Times in 120 Posts
    I just updated the code entirely, and using value instead of rank names, much easier

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •