Public Function ? - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Public Function ? (
/showthread.php?tid=298176)
Public Function ? -
park4bmx - 19.11.2011
i started makin this really simple MONEY AntuCheat into a #include
all works fine is just that when the server saves the players money in the gamemode into
pMoney lests say
$5600 are saved into the
pMoney
but then in my DriftCounter System i give the player lets say
+$500 and the that will caunt as a cheat
even though i did use a custume function.
pawn Код:
new pMoney[MAX_PLAYERS];//I want to make this Global
stock mGivePlayerMoney(playerid, AMOUNT)//if use this in the FS it will only make the "pMoney" variable to its own
{
pMoney[playerid] += AMOUNT;
GivePlayerMoney(playerid,AMOUNT);
return 1;
}
stock mSetPlayerMoney(playerid, AMOUNT)
{
pMoney[playerid] = 0;
pMoney[playerid] = AMOUNT;
ResetPlayerMoney(playerid);
GivePlayerMoney(playerid, AMOUNT);
}
stock mRemovePlayerMoney(playerid, AMOUNT)
{
pMoney[playerid] -= AMOUNT;
GivePlayerMoney(playerid,GetPlayerMoney(playerid)-AMOUNT);
}
stock mResetPlayerMoney(playerid)
{
pMoney[playerid] = 0;
ResetPlayerMoney(playerid);
}
stock mGetPlayerMoney(playerid)
{
new Amount = pMoney[playerid];
return Amount;
}
stock ReFormatMoney(playerid)//i use this under OnPlayerUpdate In my Gamemode works fine
{
LoadmMoney(playerid);
ResetPlayerMoney(playerid);
GivePlayerMoney(playerid, pMoney[playerid]);
return pMoney[playerid];
}
stock LoadmMoney(playerid)
{
new name[MAX_PLAYER_NAME],file[80];GetPlayerName(playerid, name, sizeof(name));
format(file,sizeof(file),"/mRegistration/Users/%s.txt",name);
if(fexist(file)) INI_ParseFile(file, "LoadMoney", false, true, playerid, true, false);
if(fexist(file))
{
mSetPlayerMoney(playerid,GetPVarInt(playerid, "Money"));
}
return pMoney[playerid];
}
forward LoadMoney(playerid, name[], value[]);
public LoadMoney(playerid, name[], value[])
{
if(!strcmp(name, "Money"))SetPVarInt(playerid,"Money", strval(value));
}
Re: Public Function ? -
MP2 - 19.11.2011
File functions in OnPlayerUpdate are a very bad idea. Also, why do you need to check so often?
I've re-written most of the code and optimized it a little:
pawn Код:
new pMoney[MAX_PLAYERS];
stock mGivePlayerMoney(playerid, AMOUNT)//if use this in the FS it will only make the "pMoney" variable to its own
{
pMoney[playerid] += AMOUNT;
GivePlayerMoney(playerid, AMOUNT);
return 1;
}
stock mSetPlayerMoney(playerid, AMOUNT)
{
pMoney[playerid] = AMOUNT;
ResetPlayerMoney(playerid);
GivePlayerMoney(playerid, AMOUNT);
}
stock mRemovePlayerMoney(playerid, AMOUNT)
{
pMoney[playerid] -= AMOUNT;
GivePlayerMoney(playerid, pMoney[playerid]);
}
stock mGetPlayerMoney(playerid) return pMoney[playerid];
forward MoneyCheck();
public MoneyCheck()
{
for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i) && GetPlayerMoney(i) != pMoney[i])
{
ResetPlayerMoney(i);
GivePlayerMoney(i, pMoney[i]);
}
}
return 1;
}
Remove the code from OnPlayerUpdate and just use the timer in the above code:
pawn Код:
// Under OnGameModeInit/OnFilterScriptInit
SetTimer("MoneyCheck", 4321, 1); // Every 4~ seconds check everyone's cash
To load their money, I'm not sure what systems you have in place but basically
pawn Код:
pMoney[playerid] = money_that_is_saved;
EDIT: Reading it back, It would probably be better to use PVars to use the system between scripts.
Also there's no need for mResetPlayerMoney, just mSetPlayerMoney(playerid, 0); ?