Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Coin amount Get Function
Charles445 Offline
Junior Member

Posts: 6
Threads: 3
Joined: Sep 2010
Reputation: 0
#1
Coin amount Get Function

What's the function to retrieve the amount of thaler the player has?
09-19-2010, 03:23 AM
Find
MulleDK19 Offline
Senior Member

Posts: 545
Threads: 21
Joined: Jun 2009
Reputation: 10
#2
RE: Coin amount Get Function

I highly doubt there is one.

[Image: 16455.png]
09-19-2010, 12:58 PM
Find
Pandemoneus Offline
Senior Member

Posts: 328
Threads: 2
Joined: Sep 2010
Reputation: 0
#3
RE: Coin amount Get Function

Well, you could create an integer (like int thalers = 0) and add the amount of thalers you pick up to it. Add a "SetEntityCallbackFunc(string& asName, string& asCallback);" and do AddLocalVarInt(thalers, AmountOfThalersToAdd);

This is just a part of the script, if you need more help I will give you a full one.

09-19-2010, 01:24 PM
Find
MulleDK19 Offline
Senior Member

Posts: 545
Threads: 21
Joined: Jun 2009
Reputation: 10
#4
RE: Coin amount Get Function

Just wrote a little system for you. I haven't tested it, but I don't see a reason why it shouldn't work.

Simply paste it in to your script (Eg. at the bottom), then call SetupCoins from OnStart.

Example:
void OnStart()
{
    SetupCoins(1024);
}


The coin system:
//////////
/// COIN SYSTEM

/**
* Sets up the coin system.
* In order for this to work, the coin bags must have their default names.
* Parameter "max" is the maximum number of coin bags of each type.
* You can just call it with 1024, is it's not really that much of a CPU hog
* To do this once :P
**/
void SetupCoins(int max)
{
    SetGlobalVarInt("Coins", 0);
    
    for(int i = 1; i <= max; ++i)
    {
        if(GetEntityExists("coins_large_" + i))
            SetEntityPlayerInteractCallback("coins_large_" + i, "CollectedCoinsLarge", true);
        if(GetEntityExists("coins_medium_" + i))
            SetEntityPlayerInteractCallback("coins_medium_" + i, "CollectedCoinsMedium", true);
        if(GetEntityExists("coins_small_" + i))
            SetEntityPlayerInteractCallback("coins_small_" + i, "CollectedCoinsSmall", true);
    }
}

//Callbacks for picking up coins
void CollectedCoinsLarge(string &in asEntity) { AddCoins(50); }
void CollectedCoinsMedium(string &in asEntity) { AddCoins(25); }
void CollectedCoinsSmall(string &in asEntity) { AddCoins(10); }

/**
* Gives the player some coins.
* Parameter "amount" being the number of coins to give.
**/
void AddCoins(int amount)
{
    SetGlobalVarInt("Coins", GetGlobalVarInt("Coins") + amount);
}

/**
* Takes some coins from the player.
* Parameter "amount" being the number of coins to take.
**/
void TakeCoins(int amount)
{
    amount = GetGlobalVarInt("Coins") - amount;
    if(amount < 0)
        amount = 0;
    SetGlobalVarInt("Coins", amount);
}

/**
* Sets the current amount of coins the player has.
* Parameter "amount" being the number of coins to set.
**/
void SetCoins(int amount)
{
    SetGlobalVarInt("Coins", amount);
}

/**
* Returns the amount of coins the player currently have in their posession.
**/
int GetCoins()
{
    return GetGlobalVarInt("Coins");
}

/**
* Returns true if the player can afford the specified amount of coins.
* Returns false otherwise.
**/
bool CanAfford(int amount)
{
    return (GetCoins() >= amount);
}
/// COIN SYSTEM
//////////

[Image: 16455.png]
09-19-2010, 03:28 PM
Find
Pandemoneus Offline
Senior Member

Posts: 328
Threads: 2
Joined: Sep 2010
Reputation: 0
#5
RE: Coin amount Get Function

Well done. Wink

09-19-2010, 03:38 PM
Find
MulleDK19 Offline
Senior Member

Posts: 545
Threads: 21
Joined: Jun 2009
Reputation: 10
#6
RE: Coin amount Get Function

(09-19-2010, 03:38 PM)Pandemoneus Wrote: Well done. Wink

Thanks Tongue

[Image: 16455.png]
09-19-2010, 04:17 PM
Find




Users browsing this thread: 1 Guest(s)