Hey guys,
Today i'm going to show you how to make virtual money so that when you kill someone you get money.
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 .
self.money = 0; //here is when a player will connect he'll get 0 money.You can change it as much as you want :)
}
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();
}
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
now you've got some money in game..
In my next tutorial i'll show you guys to use this money to do some good
(Thanks liltc64,kungfooman,and all others)