.gsc Scripting help needed
Moderator: Core Staff
-
- CJ G0D!
- Posts: 1575
- Joined: June 3rd, 2009, 9:02 pm
- Location: Cardiff University, UK
Re: .gsc Scripting help needed
You could be right about the missile fire, I'll check that. My current script is bugged though (what I posted up there). If I spawn and I'm holding an M16, then I switch to the ballistic knife which I've given myself. If I use a grenade then, it follows it through the air ( which it shouldn't because currentweapon = ballistic knife right?) Similarly, if I switch to ballistic knife and fire it, it doesn't follow the missile. I have to throw a grenade, load previous position out of it, and then fire a ballistic knife for it to work. I don't understand whats wrong the the script.
Also how would I go about it without checking what gun I'm holding, I tryed something but did something hideously wrong
Also how would I go about it without checking what gun I'm holding, I tryed something but did something hideously wrong
-
Re: .gsc Scripting help needed
well ur script is kinda messed up.
You cant have it waiting for both "missile_fire" and "grenade_fire" in one function.
Basically what you do is just have 2 threads, 1 waiting for missile_fire and other for grenade_fire
So have something like this
and:
You could make the script more advanced, such as not allowing the player to follow the missile, if hes following the grenade, but this should work for now.
You cant have it waiting for both "missile_fire" and "grenade_fire" in one function.
Basically what you do is just have 2 threads, 1 waiting for missile_fire and other for grenade_fire
So have something like this
Code: Select all
trol() //same function as before
{
self endon("death");
self endon("disconnect");
while(true)
{
self waittill("grenade_fire",grenade);
mylastOrigin1337 = self.origin;
self playerlinktodelta(grenade,undefined,0.5);
while(isdefined(grenade) && !self meleeButtonPressed() )
wait 0.05;
self unlink();
self setOrigin(mylastOrigin1337);
}
}
Code: Select all
trol_missile() //--- following missile through air
{
self endon("death");
self endon("disconnect");
while(true)
{
self waittill("missile_fire",missile);
mylastOrigin1337 = self.origin;
self playerlinktodelta(missile,undefined,0.5);
while(isdefined(missile) && !self meleeButtonPressed() )
wait 0.05;
self unlink();
self setOrigin(mylastOrigin1337);
}
}
-
- Core Staff
- Posts: 13313
- Joined: April 13th, 2005, 8:22 pm
- Location: UK, London
Re: .gsc Scripting help needed
Not true.Nekoneko wrote:well ur script is kinda messed up.
You cant have it waiting for both "missile_fire" and "grenade_fire" in one function.
The reason your script is not working IS because of the 'waittill' functions but is not because you require multiple threads.
You problem comes when you switch weapons.
Code: Select all
  myweapon = self GetCurrentWeapon();
Â
  if(myweapon == "knife_ballistic_mp")
  {
   self waittill ( "missile_fire", missile, weaponName );
   self.lastorigin = self.origin;
   self PlayerLinkToDelta( missile, undefined, 0.5 );
   while( isdefined(missile) && !self meleeButtonPressed() )
     wait 0.05;
  }
  else
  {
   self waittill ( "grenade_fire", grenade, weaponName );
   self.lastorigin = self.origin;
   self PlayerLinkToDelta ( grenade, undefined, 0.5 );
   while ( isdefined(grenade) && !self meleeButtonPressed() )
     wait 0.05;
  }
When you spawn, lets say your weapon is NOT a ballistic knife.
Your script will instantly get to the IF part of the statement and decide that the statement is false.
The code will then wait, and will continue to wait until a grenade is thrown.
You need to tell your script to restart when a weapon is changed.
The simplest way of doing this is creating a NEW while loop inside the IF statements, that will stop the "waittill" from waitting aftera cahnge in weapon.
Code: Select all
  myweapon = self GetCurrentWeapon();
Â
  if(myweapon == "knife_ballistic_mp")
  {
   while(self GetCurrentWeapon() == "knife_ballistic_mp" || self GetCurrentWeapon() == "hatchet_mp"))
   {
     self waittill ( "missile_fire", missile, weaponName );
     self.lastorigin = self.origin;
     self PlayerLinkToDelta( missile, undefined, 0.5 );
     while( isdefined(missile) && !self meleeButtonPressed() )
      wait 0.05;
   }
  }
  else
  {
   while(self GetCurrentWeapon() != "knife_ballistic_mp" || self GetCurrentWeapon() != "hatchet_mp")
   {
     self waittill ( "grenade_fire", grenade, weaponName );
     self.lastorigin = self.origin;
     self PlayerLinkToDelta ( grenade, undefined, 0.5 );
     while ( isdefined(grenade) && !self meleeButtonPressed() )
      wait 0.05;
   }
  }
However this will then spawn a new problem of the thread executing the rest of the function.
This can easily be stopped by breaking the latter part of the thread into a second function and calling the functions from within the new while statements.
I'll let you do the work as you may well stumble across other small issues, which can only help with the learning
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010
-
- CJ G0D!
- Posts: 1575
- Joined: June 3rd, 2009, 9:02 pm
- Location: Cardiff University, UK
Re: .gsc Scripting help needed
Thankyou very much for the explanation of why it wasn't working as intended Drofder. I however already decided to use Nekoneko's idea of multiple threads, which I made on my own without lookingg at the ones he provided
Everything now works as intended, I also found a way for it to follow grenade launchers and am very pleased with my progress I also added something to make it switch gametypes if it isn't loaded in a certain gametype, (much like on the CJ mod), however I havn't worked out how to add the text saying "Incorrect gametype loaded, switching in **", but I hope to work on that as it doesn't seem like it would be too complicated.
EDIT: Fixed c4 problem, it was renamed to satchel_charge_mp.
The final thing I need to do then is make a way so that when a player spawns, they are given the option to choose which type of grenade they want to use (frag grenade, tomahawk, semtex). I have no idea how to do that, I know I would use self thread selection(); in playerspawn(). But I would need to create some sort of menu with writing where they choose which grenade they want
Everything now works as intended, I also found a way for it to follow grenade launchers and am very pleased with my progress I also added something to make it switch gametypes if it isn't loaded in a certain gametype, (much like on the CJ mod), however I havn't worked out how to add the text saying "Incorrect gametype loaded, switching in **", but I hope to work on that as it doesn't seem like it would be too complicated.
EDIT: Fixed c4 problem, it was renamed to satchel_charge_mp.
The final thing I need to do then is make a way so that when a player spawns, they are given the option to choose which type of grenade they want to use (frag grenade, tomahawk, semtex). I have no idea how to do that, I know I would use self thread selection(); in playerspawn(). But I would need to create some sort of menu with writing where they choose which grenade they want
-
-
- Core Staff
- Posts: 13313
- Joined: April 13th, 2005, 8:22 pm
- Location: UK, London
Re: .gsc Scripting help needed
There are several ways of doing it, but the method you use would be the best looking and most appropriate method.xSnipeZx wrote:...
The final thing I need to do then is make a way so that when a player spawns, they are given the option to choose which type of grenade they want to use (frag grenade, tomahawk, semtex). I have no idea how to do that, I know I would use self thread selection(); in playerspawn(). But I would need to create some sort of menu with writing where they choose which grenade they want
This would involve creating a "scriptmenu" and using a "menuresponse" swtich statement to control the events of the selection.
Easiest way of doing this is to look at the quick menus in CoD2, they are the most straight forward and can easily be translated to CoD4, although usure of the methods used if different for BO.
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010
Re: .gsc Scripting help needed
Very nice there.
I'd like to know how you got the grenade launcher to work ^^.
Bet you'll be ending up making your script more and more complicated XD
I'd like to know how you got the grenade launcher to work ^^.
Bet you'll be ending up making your script more and more complicated XD
-
- CJ G0D!
- Posts: 1575
- Joined: June 3rd, 2009, 9:02 pm
- Location: Cardiff University, UK
Re: .gsc Scripting help needed
Grenade launcher was really simple once I found it haha.
self waittill ("grenade_fire", grenade, weaponName); <----- Tomahawks, grenades, c4
self waittill ( "missile_fire", missile, weaponName ); <----- ballistic knife, rpg
self waittill ("grenade_launcher_fire", grenade, weaponName); <------ _gl attachments, probably china lake aswell.
self waittill ("grenade_fire", grenade, weaponName); <----- Tomahawks, grenades, c4
self waittill ( "missile_fire", missile, weaponName ); <----- ballistic knife, rpg
self waittill ("grenade_launcher_fire", grenade, weaponName); <------ _gl attachments, probably china lake aswell.
-
Re: .gsc Scripting help needed
Very cool, how did you find out?
-
- CJ G0D!
- Posts: 1575
- Joined: June 3rd, 2009, 9:02 pm
- Location: Cardiff University, UK
-
- CJ G0D!
- Posts: 1575
- Joined: June 3rd, 2009, 9:02 pm
- Location: Cardiff University, UK
Re: .gsc Scripting help needed
@Drofder, I don't have access to cod2 gsc scripts or anything. But instead I came up with some code where when pressed, it would swap your tomahawks with grenades, or swap grenades with tomahawks. The code is:
However "Getcurrentlethalgrenade();" isn't a real function, I was wondering if there is a function for cod2 or cod4 that returns what grenade you have. Even if there is, does it look like this code should work?
Also I found something cool, inside mp_cosmodrome.gsc for example (the map Launch), you can see the spawn structures that have been put in place to stop previous jump spots (like jumping onto ledges that have since been clipped), and if you delete them you have the `unpatched` version of that map on your mod
Code: Select all
togglenade()
{
    self endon("disconnect");
    self endon("death");
    while(true)
    {
        self waittill (self ActionSlottwoButtonPressed());
        currentgrenade = Getcurrentlethalgrenade();
        if(currentgrenade == "frag_grenade_mp")
        {
            self Takeweapon ( "frag_grenade_mp", 0, false );
            self Giveweapon ( "hatchet_mp", 0, false );
        }
        else
        {
            self Takeweapon ( "hatchet_mp", 0, false );
            self Giveweapon ( "frag_grenade_mp", 0, false );
        }
        wait .05;
    }
}
Also I found something cool, inside mp_cosmodrome.gsc for example (the map Launch), you can see the spawn structures that have been put in place to stop previous jump spots (like jumping onto ledges that have since been clipped), and if you delete them you have the `unpatched` version of that map on your mod
Last edited by F |Madness| U on June 5th, 2011, 10:55 pm, edited 1 time in total.
-
-
- Core Staff
- Posts: 13313
- Joined: April 13th, 2005, 8:22 pm
- Location: UK, London
Re: .gsc Scripting help needed
self hasWeapon( "frag_grenade_mp" );
Also = ActionSlottwoButtonPressed()
Is that valid, not in CoD4 at least.
Also = ActionSlottwoButtonPressed()
Is that valid, not in CoD4 at least.
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010
-
- CJ G0D!
- Posts: 1575
- Joined: June 3rd, 2009, 9:02 pm
- Location: Cardiff University, UK
Re: .gsc Scripting help needed
Yeah it is valid in Black Ops.
The concept works, but something is bad with my script, because it is infinitely toggling between frag_grenade and tomahawk, even though I didn't press actionslottwobutton. Relevant bits of code are:
Note that one of my threads gives hatchet_mp on spawn, if that is any relevance. And self thread togglenade() is in an for(;;) loop inside OnPlayerSpawned().
Also check my previous post for something cool I found.
The concept works, but something is bad with my script, because it is infinitely toggling between frag_grenade and tomahawk, even though I didn't press actionslottwobutton. Relevant bits of code are:
Code: Select all
togglenade()
{
    self endon("disconnect");
    self endon("death");
    while(true)
    {
       Â
        self waittill(self ActionSlottwoButtonPressed());
        if ( self hasWeapon( "hatchet_mp" ) )
        {
            self Takeweapon ( "hatchet_mp", 0, false );
            self Giveweapon ( "frag_grenade_mp", 0, false );
        }
        else
        {
            self Takeweapon ( "frag_grenade_mp", 0, false );
            self Giveweapon ( "hatchet_mp", 0, false );
        }
        wait .05;
    }
}
Also check my previous post for something cool I found.
-
-
- Core Staff
- Posts: 13313
- Joined: April 13th, 2005, 8:22 pm
- Location: UK, London
Re: .gsc Scripting help needed
Change:
to
And change your "wait .05" [line 19] to something longer, i.e 1 second.
Regarding your something interesting, this is how all 'fixes' are done. It is too much hassle to recompile a full map.
How are they doing it though? Please post just a single (or few) line of code, just for that section.
Code: Select all
 self waittill(self ActionSlottwoButtonPressed());
Code: Select all
 while(!self ActionSlotTwoButtonPressed())
  wait 0.05;
Regarding your something interesting, this is how all 'fixes' are done. It is too much hassle to recompile a full map.
How are they doing it though? Please post just a single (or few) line of code, just for that section.
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010
-
- CJ G0D!
- Posts: 1575
- Joined: June 3rd, 2009, 9:02 pm
- Location: Cardiff University, UK
Re: .gsc Scripting help needed
Works an absolute treat Drofder, thanks! I hope that some day I won't be so incompetant at scripting
As for their `map fixing`, here is some code:
I like how they describe the places they `fixed` aswell.
and this is also relevant:
The prechaching is before the spawn collision code, self explanatory. I simply deleted the spawncollision lines from the .gsc, loaded my mod onto mp_cosmodrome, and hey presto I could sneak inside the 2 vents aswell as all the other previous spots. Does this also mean it would be possible to add extra invisible barriers and such into maps, just simply by .gsc scripting? Oh and all of this code was taken from raw/maps/mp/mp_cosmodrome.gsc
As for their `map fixing`, here is some code:
Code: Select all
    // spawn collision to prevent players from sneaking under a small area by the rocket
    spawncollision("collision_wall_128x128x10","collider",(1558, -179, -362), (0, 225, 0));
Â
    // spawn collision to prevent players from sneaking inside 2 vents
    spawncollision("collision_wall_128x128x10","collider",(-699, 1457, -60), (0, 270, 0));
    spawncollision("collision_wall_128x128x10","collider",(-699, 1329, -60), (0, 270, 0));]
and this is also relevant:
Code: Select all
    precachemodel("collision_wall_128x128x10");
    precachemodel("collision_geo_128x128x128");
    precachemodel("collision_wall_512x512x10");
-
-
- Core Staff
- Posts: 13313
- Joined: April 13th, 2005, 8:22 pm
- Location: UK, London
Re: .gsc Scripting help needed
Spawn Collision... wouldn't it be awesome if this were possible in CoD4
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010
Who is online
Users browsing this forum: No registered users and 29 guests