Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: MODDING : How to make virtual money.

  1. #1
    Corporal Killer.Pro's Avatar
    Join Date
    Jul 2012
    Location
    belgium
    Posts
    274
    Thanks
    102
    Thanked 213 Times in 141 Posts

    Post MODDING : How to make virtual money.

    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

    Code:
    spawnplayer()
    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)
    Last edited by Killer.Pro; 26th September 2012 at 05:17.

  2. The Following 3 Users Say Thank You to Killer.Pro For This Useful Post:

    EvoloZz (3rd November 2012),Kangaroo (2nd September 2012),kung foo man (18th November 2012)

  3. #2
    Sergeant EvoloZz's Avatar
    Join Date
    Sep 2012
    Location
    Helsinki, Finland
    Posts
    360
    Thanks
    314
    Thanked 167 Times in 120 Posts
    Is there any way to save the money?

  4. #3
    Private
    Join Date
    Oct 2012
    Posts
    10
    Thanks
    2
    Thanked 22 Times in 8 Posts
    ********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

    Code:
    spawnplayer()
    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..



    ********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.
    Last edited by DisSle; 24th November 2012 at 11:39.

  5. The Following User Says Thank You to DisSle For This Useful Post:

    kung foo man (24th November 2012)

  6. #4
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,626
    Thanks
    17
    Thanked 968 Times in 606 Posts
    Code:
        if(fid==0)
        {
            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++;
            }
        }
        else
            self.money=startMoney;
    Please replace the first check with a check for -1 instead of 0. So, if(fid != -1)

    Also, this looks like the reading file function is ripped DIRECTLY out of my account system:

    Code:
    	//MY code.
    	argcount=freadln(fid);
    	linenum=0;
    	self.stats=[];
    	while(argcount!=0)
    	{
    		if(linenum>0)
    			self.stats[fgetarg(fid,0)]=int(fgetarg(fid,1));
    		argcount=freadln(fid);
    		linenum++;
    	}
    No worries, please just add credits and it will be fine.
    Last edited by IzNoGoD; 24th November 2012 at 10:30.

  7. The Following User Says Thank You to IzNoGoD For This Useful Post:

    kung foo man (24th November 2012)

  8. #5
    Private
    Join Date
    Oct 2012
    Posts
    10
    Thanks
    2
    Thanked 22 Times in 8 Posts
    Replaced, you was right with the changes.

    But what you mean about the code... I ask me... you're really arrogant, right?
    I saw only one of your mods and it was Defrag and I never liked. To be honest!
    Only the idea I like because it was the best mod for Q3.

    CoD2 is dead for me. I interest me for programming for everything shit. So I'm not interest for other mods, only for programming itself. I have no reason to look other mod codes, only for help others and that since a long time. So shut up, I'm not a small kid! And I will not add your credits!
    Last edited by DisSle; 24th November 2012 at 11:34.

  9. #6
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,626
    Thanks
    17
    Thanked 968 Times in 606 Posts
    I mean that the code you posted is definitely written by me, or based on the code I wrote.

    The file handling is so goddamn similar that it cannot be a coincidence. Why else would you create a useless line of "Money-Account" in your .acc file?

  10. #7
    Private
    Join Date
    Oct 2012
    Posts
    10
    Thanks
    2
    Thanked 22 Times in 8 Posts
    Right, and guid arg is useless too. I really like feedback, but you behave like a child.
    But OK... If the baby cry, I'll try to help...

    ********THREADS UPDATED:
    Code:
    loadMoneyFile(start)
    {
        if(!isPlayer(self))
            return;
        
        guid=self getGuid();
        if(!isDefined(guid) || guid==0)
            return;
        
        if(!isDefined(start))
            start=0;
            
        fid=openFile("money\\"+guid+".acc","read");
        if(fid!=-1)
        {
            self.money=int(fGetArg(fid,0));
            closeFile(fid);
        }
        else    // If no saved file found
        {
            self.money=start;
            self manageMoneyFile();    // Create and update the saved file with every kill
        }
    }
    
    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,self.money);
        closeFile(fid);
    }
    Last edited by DisSle; 25th November 2012 at 21:08.

  11. #8
    Private
    Join Date
    Nov 2012
    Location
    Denmark, where else
    Posts
    27
    Thanks
    5
    Thanked 13 Times in 6 Posts
    I agree with izno, it is his code.

  12. #9
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    632
    Thanks
    197
    Thanked 429 Times in 289 Posts
    Quote Originally Posted by Si13n7 View Post
    ********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

    Code:
    spawnplayer()
    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..



    ********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.
    You can add text and value in one hud element. There is no need for two huds.

    Code:
    self.moneyhud = newClientHudElem(self);
    self.moneyhud.label = &"MyPreCachedText";
    self.moneyhud setValue(1337);
    About this tutorial in general, i think it would be better if you start simple. For example, start with creating and destroying the hud. And after that make a part about the money.

    Edit: Advice about openFile function. When you open a file and you don't get -1 always close this file after you are done with it. Because if you don't your server is gonna crash on the next map.
    Last edited by Mitch; 29th November 2012 at 14:50.

  13. The Following User Says Thank You to Mitch For This Useful Post:

    kung foo man (30th November 2012)

  14. #10
    Sergeant EvoloZz's Avatar
    Join Date
    Sep 2012
    Location
    Helsinki, Finland
    Posts
    360
    Thanks
    314
    Thanked 167 Times in 120 Posts
    Quote Originally Posted by Si13n7 View Post
    ********EDITED:

    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);
        }
    }
    Script compile error in line 622: wait(1.1);
    Whats wrong?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •