Thread: Networth command

Results 1 to 4 of 4
  1. #1 Networth command 
    Registered Member kalo93's Avatar
    Join Date
    Aug 2010
    Posts
    55
    Thanks given
    0
    Thanks received
    10
    Rep Power
    1
    I'm trying to make a networth command on my 317 server.

    I have this:
    Code:
    public long totalvalue() {
    try {
    for(int i = 0; i < bankItems.length; i++){
    totvalue += GetItemValue(bankItems[i]-1);
    }
    for(int i = 0; i < playerItems.length; i++){
    totvalue += GetItemValue(playerItems[i]);
    }
    return (long)(totvalue);
    } catch ( Exception e ) {}
    return 0;
    }
    But when I type ::networth, the number changes each time.

    Here's my networth command:
    Code:
    if(command.startsWith("networth")) {
        sM("Your networth is @or2@"+totalvalue()+ "@bla@ coins.");
        }
    Reply With Quote  
     

  2. #2  
    Banned

    Join Date
    Dec 2008
    Posts
    2,097
    Thanks given
    1,419
    Thanks received
    732
    Rep Power
    0
    that looks right but... you forgot about equipment and another thing why are you using a long.. it should be an int..
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    May 2010
    Posts
    70
    Thanks given
    26
    Thanks received
    2
    Rep Power
    2
    Eh, a long would do the job better cause many players will get over 2.1b in items+cash.
    Reply With Quote  
     

  4. #4  
    Registered Member
    Whired's Avatar
    Join Date
    Aug 2007
    Posts
    2,126
    Thanks given
    238
    Thanks received
    500
    Rep Power
    822
    If you're casting an int to a long, it's still truncating..

    declare it as a long and return it as a long

    If you need to assign a number to it manually, do it like this
    Code:
    long l = 9223372036854775807L;
    The literal L is promoting what the compiler thinks is an int to a long
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

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