• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Change weapon onDeath?
#1
Hello all,
Very new to this modding deal, however I am a developer but on the php side of things. My main problem I'm seeing is knowing the function names and understanding threads. Thanks to all the great mods already released here I'm starting to learn.

So to do my first "basic" mod, I thought about doing something similar to gungame, but I'm getting stuck. Here is my code at the moment:

Code:
onPlayerSpawned()
{
    self endon("disconnect");

    for(;;)
    {
        self waittill("spawned_player");
        
        //Pulls the return data from the changeWep() function
        newwep = changeWep();
        
        //Using the results from changeWep() as parameter, call the wepControl() function.
        wepControl(newwep);

    }
}

changeWep()
{
    curweap = self getCurrentWeapon();
    
    //print our "current weapon" for testing
    AllClientsPrint(curweap);
    
    switch(curweap)
    {
        case "commando_mp":
            chweap = "enfield_mp";
        break;
        default:
            chweap = "commando_mp";
        break;
    }
    
    return chweap;
}

wepControl(weap)
{
    //take away our current weapon
    self takeWeapon(self getCurrentWeapon());
    //give weapon choosen by wepControl()
    self giveWeapon(weap);
        //set our current weapon to infinte ammo
    self setWeaponAmmoStock( self getCurrentWeapon(), 99 );
    //switch the weapon we just gave ourself to our hand,. and PWN
    self switchToWeapon(weap);
}

So here I'm trying to switch the gun based on the gun you had when you died. But it always goes back to the gun you originally picked as your kit and not what I change it to. And I'm also not sure this is the best way to do it.

What I would like to know is what are the functions/properties for determining how many deaths you have upon spawn. Can anyone help? Also sorry for being long winded lol.
  Reply
#2
PHP Code:
checkGunOnDeath()
{
    
self endon("death");
    
self endon("disconnect");
    
    for(;;)
    {
        
self.weaponOnDeath self getCurrentWeapon();
        
wait 0.05;
    }
}

onPlayerSpawned()
{
    if(
isDefined(self.weaponOnDeath))
    {
        switch(
self.weaponondeath)
        {
            case 
"ak74u_mp"
                                             
.... etc
        
}
    }
    
self thread checkGunOnDeath();


The checkGunOnDeath() function will check your current weapon every 0.05 secs, until you die, once you die, the weaponname will be saved as self.weaponondeath.
Whenever you spawn, it will check if self.weaponondeath is defined (thats only to stop a small error for when a person spawns for the first time), and if it is, it will do something depending on what the weapon was. After giving you the newweapon, it will run the weaponondeath thread again until you next die, etc.

Edit: The checkGunOnDeath() function might be possible to simplify, by just having it as self waittill("death"); self.weaponondeath = self getcurrentweapon();, but I'm not sure if this will work, but the code I quoted *should* work although I havn't tested it.
And for keeping track of how many deaths you have, something like this should work *not tested*.

PHP Code:
onPlayerConnect()
{
    
player thread totaldeaths();
}

totaldeaths()
{
    
0;
    for(;;)
    {
        
self waittill("update_death");
        
i++;
        
self iprintln("^2You have died "+i+" times");
    }

onPlayerSpawned()
{
    
self thread countdeath();
}

countdeath()
{
    
self waittill("death");
    
self notify("update_death");


Note, I didn't put the full onPlayerSpawned/onPlayerConnect functions in, you just need to add those lines into those functions.
  Reply
#3
Ok great thanks! This works good,. now time to play some more Smile Again thank you for your help!

EDIT: Sweet I didn't see the "number of deaths" code. Thanks man,. this should be fun to play with.
  Reply
#4
You're welcome.
  Reply
#5
Or just do it with self.deaths. much easier Tongue
  Reply
#6
If he's learning to mod it's better to learn things long way, to see how they're done.
  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Help Mw2 weapon skin question FroxIVx4 1 2,757 10-13-2013, 16:54
Last Post: hmann
Question Help Weapon Name iRoNinja 8 6,011 10-08-2013, 08:31
Last Post: iRoNinja
  Mw2 weapon porting? Cuddlyedits 3 4,327 09-15-2013, 16:43
Last Post: DidUknowiPwn
Rainbow [Release] MW3: Random Weapon Plugin V1 Nekochan 50 30,330 09-11-2013, 15:11
Last Post: EnVi Sweden Rocks
  Using Cheat Engine 6.2 to change BO2 address values wzlrsaur 6 7,585 08-06-2013, 06:28
Last Post: 14th
Exclamation [Request] Random Weapon At Spawn Scripts18 3 4,370 07-27-2013, 23:53
Last Post: DidUknowiPwn
  Mw3 Feed Color Change?? aluzion 5 5,383 07-16-2013, 19:52
Last Post: barata
  Help Mw2 weapon skin question FroxIVx4 1 2,681 07-06-2013, 19:22
Last Post: surtek
  Change death animation Keouf 3 3,630 07-05-2013, 18:39
Last Post: Nekochan
Question Help change single file lzma maker to multiple in c# raminr63 1 2,727 05-12-2013, 19:31
Last Post: raminr63

Forum Jump:


Users browsing this thread: 1 Guest(s)