[Include] money.inc - Advanced, plug-n-play, server-sided money system
#1

VERSION 1.0

Released on 25/2/2012


INTRO:
Have you ever wanted to have no money hackers at all? Have you ever wanted your server being protected against money hackers that can buy everything? Well, this small include allows you to do so! Basically, it creates 2 textdraws that hide original SA money bar and third one on which is new money ammount displayed! It supports up to 7 digits ( maybe 8 ), and its plug-and-play! See bellow for installation help!
__________________________________________________ __________________________________________________

PREVIEW:


__________________________________________________ __________________________________________________

NATIVES:
pawn Код:
native GiveMoney(playerid,ammount); //give money to player

native TakeMoney(playerid,ammount); //take money from player

native SetMoney(playerid,ammount); //set players money to certain ammount

native ResetMoney(playerid); //reset players money

native GetMoney(playerid); //get money ammount that player owns (same as GetPlayerMoney)
__________________________________________________ _______________________________________________

STUF NEEDED:
One important thing needed to run this script perfectly is - Dini!

__________________________________________________ _______________________________________________

INSTALLATION:
1. Download .rar from Mediafire!
2. Extract anywhere!
3. Put "money.inc" into your "pawno/include" folder!
4. Put "Money" folder into "scriptfiles"!
5. Open some script and add:
pawn Код:
#include <money>
6. Compile and enjoy!

__________________________________________________ _______________________________________________

DOWNLOAD:

Mediafire v1.0

Or copy/paste:
pawn Код:
#if defined _money_included
    #endinput
#endif
#define _money_included
#include <Dini>

new Text:MoneyTD[MAX_PLAYERS];
new Text:MoneyTD2[MAX_PLAYERS];
new Text:MoneyTD3[MAX_PLAYERS];
new PCash[MAX_PLAYERS];
new File[100];

/*Natives:
native GiveMoney(playerid,ammount);
native TakeMoney(playerid,ammount);
native SetMoney(playerid,ammount);
native ResetMoney(playerid);
native GetMoney(playerid);
*/


forward M_OnGameModeInit();
public OnGameModeInit()
{
    for(new playerid=0; playerid < MAX_PLAYERS; playerid++)
    {
        MoneyTD[playerid] = TextDrawCreate(498.000000, 88.000000,"_");
        TextDrawBackgroundColor(MoneyTD[playerid], 255);
        TextDrawFont(MoneyTD[playerid], 1);
        TextDrawLetterSize(MoneyTD[playerid], 0.500000, 1.000000);
        TextDrawColor(MoneyTD[playerid], -1);
        TextDrawSetOutline(MoneyTD[playerid], 0);
        TextDrawSetProportional(MoneyTD[playerid], 1);
        TextDrawSetShadow(MoneyTD[playerid], 1);
        TextDrawUseBox(MoneyTD[playerid], 1);
        TextDrawBoxColor(MoneyTD[playerid], 255);
        TextDrawTextSize(MoneyTD[playerid], 625.000000, 480.000000);
       
        MoneyTD2[playerid] = TextDrawCreate(498.000000, 78.000000,"_");
        TextDrawBackgroundColor(MoneyTD2[playerid], 255);
        TextDrawFont(MoneyTD2[playerid], 1);
        TextDrawLetterSize(MoneyTD2[playerid], 0.500000, 1.000000);
        TextDrawColor(MoneyTD2[playerid], -1);
        TextDrawSetOutline(MoneyTD2[playerid], 0);
        TextDrawSetProportional(MoneyTD2[playerid], 1);
        TextDrawSetShadow(MoneyTD2[playerid], 1);
        TextDrawUseBox(MoneyTD2[playerid], 1);
        TextDrawBoxColor(MoneyTD2[playerid], 255);
        TextDrawTextSize(MoneyTD2[playerid], 625.000000, 480.000000);
       
        MoneyTD3[playerid] = TextDrawCreate(498.000000, 83.000000,"_");
        TextDrawBackgroundColor(MoneyTD3[playerid], 255);
        TextDrawFont(MoneyTD3[playerid], 3);
        TextDrawLetterSize(MoneyTD3[playerid], 0.750000, 1.800000);
        TextDrawColor(MoneyTD3[playerid], -1);
        TextDrawSetOutline(MoneyTD3[playerid], 0);
        TextDrawSetProportional(MoneyTD3[playerid], 1);
        TextDrawSetShadow(MoneyTD3[playerid], 1);
        TextDrawUseBox(MoneyTD3[playerid], 1);
        TextDrawBoxColor(MoneyTD3[playerid], 255);
        TextDrawTextSize(MoneyTD3[playerid], 625.000000, 480.000000);
       
        if(funcidx("M_OnGameModeInit") != -1) CallLocalFunction("M_OnGameModeInit", "");
    }
    return 1;
}
#if defined _ALS_OnGameModeInit
        #undef OnGameModeInit
#else
        #define _ALS_OnGameModeInit
#endif
#define OnGameModeInit M_OnGameModeInit

forward M_OnPlayerConnect(playerid);
public OnPlayerConnect(playerid)
{
    TextDrawShowForPlayer(playerid,MoneyTD2[playerid]);
    TextDrawShowForPlayer(playerid,MoneyTD[playerid]);
    TextDrawShowForPlayer(playerid,MoneyTD3[playerid]);
    new playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    format(File,sizeof(File),"/Money/%s.txt",playername);
    if(dini_Exists(File))
    {
        PCash[playerid] = dini_Int(File,"Money");
    }
    else
    {
        dini_Create(File);
        dini_IntSet(File, "Money", PCash[playerid]);
    }
    if(funcidx("M_OnPlayerConnect") != -1) CallLocalFunction("M_OnPlayerConnect", "i", playerid);
    return 1;
}
#if defined _ALS_OnPlayerConnect
        #undef OnPlayerConnect
#else
        #define _ALS_OnPlayerConnect
#endif
#define OnPlayerConnect M_OnPlayerConnect

forward M_OnPlayerUpdate(playerid);
public OnPlayerUpdate(playerid)
{
    new cashstr[100];
    format(cashstr,sizeof(cashstr),"~g~$~w~%d", PCash[playerid]);
    TextDrawSetString(MoneyTD3[playerid],cashstr);
    new playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,playername,sizeof(playername));
    format(File,sizeof(File),"/Money/%s.txt",playername);
    if(dini_Exists(File))
    {
        dini_IntSet(File, "Money", PCash[playerid]);
    }
    if(funcidx("M_OnPlayerUpdate") != -1) CallLocalFunction("OnPlayerUpdate", "i", playerid);
    return 1;
}
#if defined _ALS_OnPlayerUpdate
        #undef OnPlayerUpdate
#else
        #define _ALS_OnPlayerUpdate
#endif
#define OnPlayerUpdate M_OnPlayerUpdate

stock GiveMoney(playerid,ammount)
{
    PCash[playerid] += ammount;
    return 1;
}

stock TakeMoney(playerid,ammount)
{
    PCash[playerid] -= ammount;
    return 1;
}

stock SetMoney(playerid,ammount)
{
    PCash[playerid] = ammount;
    return 1;
}

stock ResetMoney(playerid)
{
    PCash[playerid] = 0;
    return 1;
}

stock GetMoney(playerid)
{
    return PCash[playerid];
}
__________________________________________________ _______________________________________________

CREDITS:

fiki574_CRO - Creating everything
DracoBlue - His awesome Dini
__________________________________________________ _______________________________________________

Have fun!

Regards,
Fiki!
Reply
#2

I'll forget the fact that you use dini, for now..

You shouldn't use file functions under OnPlayerUpdate. It will, in most cases, lag up your mode.
funcidx will also slow it down.

The textdraws are unneeded as you can use the original money display.

why is the "file" variable global?

I think you should revise your script.
Reply
#3

Quote:
Originally Posted by Psymetrix
Посмотреть сообщение
I'll forget the fact that you use dini, for now..

You shouldn't use file functions under OnPlayerUpdate. It will, in most cases, lag up your mode.
funcidx will also slow it down.

The textdraws are unneeded as you can use the original money display.

why is the "file" variable global?

I think you should revise your script.
Why not? Best and fast saving! And as you said, it will cause lag, so if you dont want it, simply remove it and place it under disconnect!

The texdraws are needed if you want to use this! :O

About "file" - make it local??


And btw, go test it before commenting, you cant see everything just from code
Reply
#4

You do realise, you open, write, and close the file about 20 times per second PER PLAYER?
so 20times x 200players= 4000 times / second. Is that really needed?
And you're saying it won't lag?
Reply
#5

Epic Fail on saving method.
Reply
#6

Good GOod

Serbian:Lepo lepo lepo
Reply
#7

You better listen to those people and optimize the script ASAP.
Reply
#8

I didn't mean for my post to sound harsh or any thing but dini is WELL outdated and very slow compared to what is available these days. You don't even need a library, you could write your own functions in a few minutes for this.

What I meant by the global variable is that you shouldn't declare at as global as you don't need to retrieve it's previous value. Recreate the variable as you use it.

You should also hook the original money functions, GivePlayerMoney for example. Rather than create new functions. ALS hooking also works for functions.

Quote:
Originally Posted by fiki574_CRO
Посмотреть сообщение
And btw, go test it before commenting, you cant see everything just from code
Maybe not but you can still see most things.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)