********EDITED:
For the tutorial,i am going to do it on TDM gametype.
So take out the tdm.gsc from main (main/iw_07.iwd/maps/mp/gametypes/tdm.gsc)
and drag it on your desktop.
Now in the tdm.gsc we're going to call a new thread for money when a player connects so
find :
Code:
Callback_PlayerConnect()
now here we're going to call new thread so put this code in there
Code:
self thread Money();
So from here a money thread is called but we have no money thread...Don't worry we're going to make one xD
so now above the
Code:
Callback_PlayerConnect()
put this code so it should look something like :
Code:
Money()
{
if(!isDefined(self.money)) // checks that money is already defined or not .
{
/*********************************
Disabled by Si13n7
self.money = 0; //here is when a player will connect he'll get 0 money.You can change it as much as you want :)
*********************************/
// Si13n7
self loadMoneyFile(200); // Change the 200 value to set the start money for new player
}
}
Callback_PlayerConnect()
{
ok now that we've done that we're going to make money increase as someone kills
go into your tdm.gsc go find Callback_PlayerKilled(eInflictor, attacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, psOffsetTime, deathAnimDuration) in this function is where EVERY death is handled.
go find somewhere in that function where it says
Code:
else
{
attacker.score++;
teamscore = getTeamScore(attacker.pers["team"]);
teamscore++;
setTeamScore(attacker.pers["team"], teamscore);
checkScoreLimit();
}
here is where a player gets a kill so here we're going to give player 50 money.
so edit it so it should look something like this.
Code:
else
{
attacker.score++;
attacker.money += 50; //so player gets 50 money after a kill
teamscore = getTeamScore(attacker.pers["team"]);
teamscore++;
setTeamScore(attacker.pers["team"], teamscore);
checkScoreLimit();
// Si13n7
attacker manageMoneyFile(); // Create and update the saved file with every kill
}
Now that we've give the player money for every kill but if you go ingame now you wont see any difference
but i works, all we need to do now is to display money on screen
for that we'll have to make a hud
so in the start of tdm.gsc find this function
Code:
Callback_StartGameType()
you'll see under there that many things are precached
so we are going to precache our money hud
so put this code there
Code:
game["hud_money"] = &"-=^1MoneY^7=-";
precacheString(game["hud_money"]);
so now that we've precached the hud its time to make the hud
but first you have to call the hud
so find player spawn function
here we're going to call the hud so put this code in this function
Code:
self thread spawnmoneyhuds();
In this new thread we'll add the money hud so we're going to make this hud thread
just write this thread when the spawnplayer thread ends
Code:
spawnmoneyhuds()
{
self endon("disconnect");
self endon("joined_spectators");
if(!isDefined(self.moneyhud))
{
self.moneyhud = newClientHudElem(self);
self.moneyhud.x = 520;
self.moneyhud.y = 280;
self.moneyhud.alignX = "left";
self.moneyhud.alignY = "middle";
self.moneyhud.sort = 1;
self.moneyhud.alpha = 1;
self.moneyhud.fontScale = 1.2;
self.moneyhud.archived = true;
self.moneyhud setText(game["hud_money"]);
}
if(!isDefined(self.moneyVALUEhud))
{
self.moneyVALUEhud = newClientHudElem(self);
self.moneyVALUEhud.x = 600;
self.moneyVALUEhud.y = 275;
}
while(1)
{
wait(1.1);
self.moneyVALUEhud setvalue(self.money);
}
}
Don't forget to make the iwd file :p
now you've got some money in game..
********ADDED:
Add few threads to the end...
Code:
loadMoneyFile(startMoney)
{
self endon("disconnect");
if(!isPlayer(self))
return;
guid=self getGuid();
if(!isDefined(guid) || guid==0)
return;
if(!isDefined(startMoney))
startMoney=0;
fid=openFile("money\\"+guid+".acc","read");
if(fid!=-1)
{
argcount=fReadLn(fid);
linenum=0;
while(argcount>0)
{
if(linenum>0 && argcount==2)
if(guid==int(fGetArg(fid,0)))
self.money=int(fGetArg(fid,1));
argcount=fReadLn(fid);
linenum++;
}
closeFile(fid);
}
else
self.money=startMoney;
}
manageMoneyFile()
{
if(!isPlayer(self))
return;
guid=self getGuid();
if(!isDefined(guid) || guid==0)
return;
fid=openFile("money\\"+guid+".acc","write");
closeFile(fid);
fid=openFile("money\\"+guid+".acc","append");
fPrintLn(fid,"Money-Account");
fPrintLn(fid,"\n"+guid+","+self.money);
closeFile(fid);
}
It's not for cracked servers because nobody have a guid. And I wrote that very fast and I didn't tested. But I think, it will still work. ;)