.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

.gsc Scripting help needed

Post by F |Madness| U » June 4th, 2011, 6:05 pm

Let me just say I'm very new to learning scripting, only started yesterday and I've read drofders guide many times aswell as looked through alot of code trying to understand it. I have a script that follows grenades and other similar things (tomahawks etc) for CoD Black Ops, the majority of it was made by a good scripter, I just added a few extra things (loading previous thrown position) and some dvars. However I need some help understanding it and adding some extra things.


Code: Select all

trol()      //--- following grenade through air feature
{
        self notify("trol");
        self endon("trol");
        self endon("death");
 
        self endon("disconnect");
        self waittill ( "grenade_pullback", weapon );
        self waittill ( "grenade_fire", grenade, weaponName );
 
        grenade enablelinkto();
 
 
 
        for(;;)
        {
                self PlayerLinkToDelta( grenade, undefined, 0.5 );
                self setorigin(grenade.origin);
 
                wait .5;
                self thread trol();
        }
 
}
On the above, I don't understand self notify("trol"); and self endon("trol"); can be there, because from what I thought when it gets to self notify, that notifies the script to end the thread, but I obviously don't understand it fully, if somebody could explain that would be nice.

Nextly, if you throw a grenade in the air and you're following it, if you press the suicide in mid-air it will suicide as normal. However if I try and load my previous position whilst i'm in the air it doesn't work, I have to wait for the throw to finish, and then re-load position. The kill and load threads are:

Code: Select all

dosuicide()     //--- button to suicide
{
        self endon("disconnect");
        self endon("death");
        for(;;) 
        {
                if(self ActionSlotfourButtonPressed()) 
                {
                        self suicide();
                }
                wait .05;
        }
}
and

Code: Select all

doGoback()   //---- load position where you threw grenade from
{
 
        self endon("death");
        for(;;)
        {
                if(self FragButtonPressed())
                {
                        self giveWeapon("frag_grenade_mp");
                        self setWeaponAmmoClip("frag_grenade_mp", 2);
 
                        self.mylastOrigin1337 = self.origin;
 
                }
                if(self meleeButtonPressed())
                {
 
                        self setOrigin(self.mylastOrigin1337);
 
                }
                wait 0.1;
        }
 
}
Now when I throw a grenade and I'm following the grenade through the air, if I suicide it stops following through the air and respawns me somewhere (I'm assuming this is because inside the trol() thread there is self endon("death), meaning when you die it ends that loop). Now I want the same thing to happen if you knife (to load position) whilst in mid-air. I tryed putting self endon("self meleebuttonpressed()") in the trol() thread, but this didn't work. Any help on that would be appreciated.

Finally, need some help understand one other part of code:

Code: Select all

grenade enablelinkto();
 
 
 
        for(;;)
        {
                self PlayerLinkToDelta( grenade, undefined, 0.5 );
                self setorigin(grenade.origin);
 
                wait .5;
                self thread trol();
        }
Is grenade enablelinkto() just a made up name for this function? Or am I misunderstanding something. What is PlayerLinkToDelta ( grenade, undefined, 0.5 )? and I understand that self setorigin(grenade.origin), sets your origin to that of the grenade, in which case why is the playerlinktodelta needed. And I tryed looking for a similar function to grenade.origin that would work for ballistic knifes and grenade launchers, but I couldn't find anyway, how would I go about trying to follow those through the air aswell as grenades?

If anyone can help me with any of this I will be extremely grateful, sorry for long/messy thread.
Last edited by F |Madness| U on June 4th, 2011, 10:57 pm, edited 1 time in total.
-

IzNoGoD
CJ Worshipper
CJ Worshipper
Posts: 343
Joined: January 6th, 2009, 8:39 pm
Location: Netherlands/Holland

Re: .gsc Scripting help needed

Post by IzNoGoD » June 4th, 2011, 6:29 pm

The notify/endon "trol" prevents the thread from running several times.

If you start the thread, the thread will shout (notify) "trol" to self. After shouting that, it will go and listen (endon) to "trol". If the thread starts again, "trol" is shouted, so the (doubled) thread will end. The thread will not end its current run, as the notify comes before the endon.

grenade enablelinkto() is not needed i think, as the grenade is not linked. The player is.

Which is precisely your problem: Try a self unlink().

Then, last part, you said this was written by a very good scripter. I tend to doubt that, as he uses a for(;;) loop to recall the same thread to do exactly the same again :P

This code is much cleaner, and should do exactly the same (however, i have no experience with cod BO)

Code: Select all

trol()      //--- following grenade through air feature
{
        self endon("death");
        self endon("disconnect");
 
        while(true)
        {
                self waittill("grenade_fire",grenade,weaponname);
                self playerlinktodelta(grenade,undefined,0.5);
                while(isdefined(grenade))
                        wait 0.05;
        }
}
 
Then, for the code of the loading position:

Code: Select all

 
        if(self meleeButtonPressed())
        {
                self unlink();
                self setOrigin(self.mylastOrigin1337);
        }
The grenade enablelinkto() does something to the grenade, so that the grenade can be linked to something. As you want to link something to the grenade instead of the other way around, this is not needed.

Playerlinktodelta() will keep the current gap between the player and the object (although im not sure about that, but it seems likely), and will then link it to the object. As such, the setting of the origin is NOT NEEDED, as the gap is stored and cannot be changed while linked.

For ballistic knifes and grenadelaunchers you need some other waittill(), as the "grenade_fire" is obviously only made for grenades (maybe it works now for GLs too, as i removed the waittill Pin thingy, which wasnt needed at all)

Also: messy topics imply messy replies.
GL reading this :P
LMGTFY!

Its not a glitch... Its the future!

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 4th, 2011, 7:33 pm

Just read your reply very quickly and kind of understand, I'll read it more again later when I have time, but thanks for taking the time to look at this and help me.

And I didn't say he was very good, just said by a good scripter, meaning he has been doing it more than a day like me :wink:
-

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 4th, 2011, 11:10 pm

Code: Select all

6.
        while(true)
 
        {
                self waittill("grenade_fire",grenade,weaponname);
 
                self playerlinktodelta(grenade,undefined,0.5);
 
                while(isdefined(grenade))
 
                wait 0.05;
 
        }
 
In this part of code, I don't understand what the argument is? Because your saying that if the argument is true, then when grenade is fired it will link to the grenade etc, but where/what is the argument? Also what does the while(isdefined(grenade)) mean, is this the argument?

Also I tryed using your code and got script compile error, unknown function @ 211109, the only extra function you used was self unlink();, could this possibley not be a real function or something?- Tryed removing that function and still got the error (but @ 211104), so I don't know what it is.

Also, for ballistic knife/grenade launcher if you swap self waittill ("grenade_fire",grenade,weaponname) with self waittill( "weapon_fired", curWeapon ), might that work?
Last edited by F |Madness| U on June 4th, 2011, 11:38 pm, edited 2 times in total.
-

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

Re: .gsc Scripting help needed

Post by Nekoneko » June 4th, 2011, 11:28 pm

while( true ) is just an infinite loop.

while( isdefined( grenade ) ) :
The Script will just wait, until the grenade explodes (it is then undefined, I assume) and then repeat itself.

Also for loading the last position:


this might work:

Code: Select all

 
trol()      //--- following grenade through air feature
{
        self endon("death");
        self endon("disconnect");
 
        while(true)
        {
                self waittill("grenade_fire",grenade,weaponname);
                mylastOrigin1337 = self.origin
                self playerlinktodelta(grenade,undefined,0.5);
                while(isdefined(grenade) && !self meleeButtonPressed() )
                        wait 0.05;
                self unlink();
                self setOrigin(mylastOrigin1337);
        }
}
 
But Im not too sure with self unlink and havent scripted in BO.
Last edited by Nekoneko on June 4th, 2011, 11:37 pm, edited 2 times in total.

IzNoGoD
CJ Worshipper
CJ Worshipper
Posts: 343
Joined: January 6th, 2009, 8:39 pm
Location: Netherlands/Holland

Re: .gsc Scripting help needed

Post by IzNoGoD » June 4th, 2011, 11:36 pm

You are correct. I added this to prevent people from trowing another grenade in air, and getting behind that one xD
LMGTFY!

Its not a glitch... Its the future!

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 4th, 2011, 11:39 pm

Didn't expect such quick replies, just edited my previous post if you want to take a look at what I said :lol:
-

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

Re: .gsc Scripting help needed

Post by Nekoneko » June 4th, 2011, 11:43 pm

No clue for Black Ops tbh xD

But, in cod4 I'd look through the gametypes/_battlecharter.gsc
If that exists for blackops or something like it, look for the waittill's, maybe youll find something for the grenade launcher.

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 4th, 2011, 11:51 pm

I am getting an unknown function error even with your latest code, and the self waittill ("weapon_fired", curWeapon) is defeinitely a function in black ops. So if I swapped that with the grenade_fire, once I have shot my weapon (ballistic knife, launcher etc) it should follow the object that is fired? Or would extra code be needed.

Edit: Looked through battle charter and only useful waitills I found were:
( "begin firing" )
( "weapon_fired" ) -- could this one be used for when you fire a ballistic knife/launcher?
( "grenade_fire" )
( "grenade_stuck" )
( "missile_fire" ) -- perhaps launchers/knife counts as a missile?
Last edited by F |Madness| U on June 4th, 2011, 11:58 pm, edited 1 time in total.
-

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

Re: .gsc Scripting help needed

Post by Nekoneko » June 4th, 2011, 11:57 pm

Could you post the error?

And Youd need to get the object thats fired, I dont know if the grenade in launcher is even an object.

You would need something like:

self waittill( "weapon_fired", curWeapon, bullet );

But I highly doubt bullet really exists :/

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, 12:09 am

It was just a syntax error, in your code you forgot a ; after

Code: Select all

mylastOrigin = self.origin
.

The new load position works a treat, thanks alot. And I searched through all the .gsc files with

Code: Select all

( "weapon_fired" , curWeapon )
and there was only one match, so I don't think the bullet exists.

I don't see why you would need the bullet though, wouldn't that be enough?

EDIT: WOOT!! I got ballistic knife working, I used

Code: Select all

                self waittill ( "missile_fire", missile, weaponName );
                self.lastorigin = self.origin;
                self PlayerLinkToDelta( missile, undefined, 0.5 );
                while( isdefined(missile) && !self meleeButtonPressed() )
Now just to find grenade launchers, I thought that would work with grenade launchers but I guess not.
-

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, 12:25 am

cool that you made ballistic knife

Sorry for the syntax error xD

And well, you cant link yourself to a weapon, it has to be the projectile.
Couldnt find anything like it in cod4 for grenade launcher though :/

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, 12:35 am

Well thanks for your help so far anyway, I'm really happy that I succesfully got ballistic knife working :) For my first proper day of scripting I find it quite an accomplishment ^^

I'll work on this more tomorrow, I would've really thought a grenade launcher would count as either a grenade or a projectile, what else can it be :S
-

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, 1:22 pm

I tryed to make the script so that you can follow grenades or missiles, depending on which you use. I wrote the following script but the first if statement is always true, and I'm not sure what other function I could use. If I can get a function that tells your current weapon you are holding I think I should be able to do it. My code is as follows

Code: Select all

trol()      //--- following grenade through air feature
{
 
        self endon("death");
        self endon("disconnect");
 
        while(true)
        {
                myweapon = self GetWeaponsListPrimaries();
                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;
                }
                self unlink();
                self setOrigin(self.lastorigin);
                if (weaponName == "hatchet_mp")
                {
                        self giveWeapon("hatchet_mp");
                        self setWeaponAmmoClip("hatchet_mp", 2);
                }
                else if (weaponName == "knife_ballistic_mp")
                {
                        self giveWeapon("knife_ballistic_mp");
                        self setWeaponAmmoClip("knife_ballistic_mp", 3);
                }
                else
                {
                        self giveWeapon("frag_grenade_mp");
                        self setWeaponAmmoClip("frag_grenade_mp", 2);
                }
        }
}       
My main problem is this part,

Code: Select all

myweapon = self GetWeaponsListPrimaries();
                if(myweapon == "knife_ballistic_mp")
Even if I don't have ballistic knife equipped or even in my inventory this function is still true, so it doesn't allow me to follow grenades. I need a function that just detects your current weapon if there is one, (I tryed some things like self getCurWeapon but received unknown variable errors).

EDIT: Nvm I found it, it is self GetCurrentWeapon();.
-

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, 1:57 pm

I think getCurrentWeapon() would be the right thing to use.

You could run another thread in a loop, having waittil( "switched_weapon", weapon), then check if its ballistic knife

Also doesnt the waittill( "misile_fire" ); only work on balistic knife, meaning you dont need the weapon-check stuff.

Post Reply

Who is online

Users browsing this forum: No registered users and 32 guests