.gsc Scripting help needed

Have a question about modding, modelling or skinning? Have a tutorial to post? Post here!

Moderator: Core Staff

F |Madness| U
CJ G0D!
CJ G0D!
Posts: 1575
Joined: June 3rd, 2009, 9:02 pm
Location: Cardiff University, UK

Re: .gsc Scripting help needed

Post by F |Madness| U » June 5th, 2011, 2:24 pm

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 :P
-

Nekoneko
CJ Fan
CJ Fan
Posts: 170
Joined: April 18th, 2011, 3:48 pm

Re: .gsc Scripting help needed

Post by Nekoneko » June 5th, 2011, 3:52 pm

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

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);
        }
}
 
and:

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);
        }
}
 
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.

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: .gsc Scripting help needed

Post by Drofder2004 » June 5th, 2011, 5:00 pm

Nekoneko wrote:well ur script is kinda messed up.
You cant have it waiting for both "missile_fire" and "grenade_fire" in one function.
Not true.

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;
   }
[/size]

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;
      }
   }
[/size]
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 :)
Image
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

F |Madness| U
CJ G0D!
CJ G0D!
Posts: 1575
Joined: June 3rd, 2009, 9:02 pm
Location: Cardiff University, UK

Re: .gsc Scripting help needed

Post by F |Madness| U » June 5th, 2011, 6:13 pm

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 :D

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 :?
-

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: .gsc Scripting help needed

Post by Drofder2004 » June 5th, 2011, 6:29 pm

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 :?
There are several ways of doing it, but the method you use would be the best looking and most appropriate method.

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.
Image
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

Nekoneko
CJ Fan
CJ Fan
Posts: 170
Joined: April 18th, 2011, 3:48 pm

Re: .gsc Scripting help needed

Post by Nekoneko » June 5th, 2011, 6:57 pm

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

F |Madness| U
CJ G0D!
CJ G0D!
Posts: 1575
Joined: June 3rd, 2009, 9:02 pm
Location: Cardiff University, UK

Re: .gsc Scripting help needed

Post by F |Madness| U » June 5th, 2011, 7:33 pm

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.
-

Nekoneko
CJ Fan
CJ Fan
Posts: 170
Joined: April 18th, 2011, 3:48 pm

Re: .gsc Scripting help needed

Post by Nekoneko » June 5th, 2011, 9:42 pm

Very cool, how did you find out? :D

F |Madness| U
CJ G0D!
CJ G0D!
Posts: 1575
Joined: June 3rd, 2009, 9:02 pm
Location: Cardiff University, UK

Re: .gsc Scripting help needed

Post by F |Madness| U » June 5th, 2011, 9:51 pm

Searched for the phrase "_fire" in every gsc file.
-

F |Madness| U
CJ G0D!
CJ G0D!
Posts: 1575
Joined: June 3rd, 2009, 9:02 pm
Location: Cardiff University, UK

Re: .gsc Scripting help needed

Post by F |Madness| U » June 5th, 2011, 10:20 pm

@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:

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;
        }
}
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 :)
Last edited by F |Madness| U on June 5th, 2011, 10:55 pm, edited 1 time in total.
-

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: .gsc Scripting help needed

Post by Drofder2004 » June 5th, 2011, 10:51 pm

self hasWeapon( "frag_grenade_mp" );


Also = ActionSlottwoButtonPressed()
Is that valid, not in CoD4 at least.
Image
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

F |Madness| U
CJ G0D!
CJ G0D!
Posts: 1575
Joined: June 3rd, 2009, 9:02 pm
Location: Cardiff University, UK

Re: .gsc Scripting help needed

Post by F |Madness| U » June 5th, 2011, 11:00 pm

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:

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;
        }
}
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.
-

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: .gsc Scripting help needed

Post by Drofder2004 » June 5th, 2011, 11:25 pm

Change:

Code: Select all

 self waittill(self ActionSlottwoButtonPressed());
to

Code: Select all

 while(!self ActionSlotTwoButtonPressed())
    wait 0.05;
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.
Image
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

F |Madness| U
CJ G0D!
CJ G0D!
Posts: 1575
Joined: June 3rd, 2009, 9:02 pm
Location: Cardiff University, UK

Re: .gsc Scripting help needed

Post by F |Madness| U » June 5th, 2011, 11:45 pm

Works an absolute treat Drofder, thanks! I hope that some day I won't be so incompetant at scripting :P

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));]
I like how they describe the places they `fixed` aswell.

and this is also relevant:

Code: Select all

        precachemodel("collision_wall_128x128x10");
        precachemodel("collision_geo_128x128x128");
        precachemodel("collision_wall_512x512x10");
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
-

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: .gsc Scripting help needed

Post by Drofder2004 » June 6th, 2011, 3:05 am

Spawn Collision... wouldn't it be awesome if this were possible in CoD4 :(
Image
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

Post Reply

Who is online

Users browsing this forum: No registered users and 29 guests