Post: [GSC] Using callbacks
09-29-2016, 07:31 PM #1
Tustin
Balls of Steel
(adsbygoogle = window.adsbygoogle || []).push({}); Callbacks seem to be a new addition to GSC with these mod tools and they can be really useful. If you're not familiar with what a callback is; a callback is something that fires when an action/event happens. You can use these to invoke functions when a specific event happens in game.

To use these, you need to include the callbacks script to your script (this is already added when you create a new mp/zm map):
#using scripts\shared\callbacks_shared;

Once you add it, you can reference it's functions by using the namespace callback. Now we can add a callback to our script for a function to execute whenever a player spawns in:
    
function main(){
.... other code ....
callback:Gaspn_spawned(&on_player_spawned);
}
function on_player_spawned()
{
wait(5);
IPrintLnBold("WELCOME");
}


All the callback functions require the function names to be passed as a pointer, so just include & before the function name.

You can find all the callbacks that Treyarch provided by opening share\raw\scripts\shared\callbacks_shared.gsc and jump down to line 113. They include comments on what each one does and how to use it.

The following 7 users say thank you to Tustin for this useful post:

anthonything, Black Panther, Kryptus, Darth Saul, Kronos, Specter
09-29-2016, 09:23 PM #2
anthonything
Space Ninja
Originally posted by Tustin View Post
Callbacks seem to be a new addition to GSC with these mod tools and they can be really useful. If you're not familiar with what a callback is; a callback is something that fires when an action/event happens. You can use these to invoke functions when a specific event happens in game.

To use these, you need to include the callbacks script to your script (this is already added when you create a new mp/zm map):
#using scripts\shared\callbacks_shared;

Once you add it, you can reference it's functions by using the namespace callback. Now we can add a callback to our script for a function to execute whenever a player spawns in:
    
function main(){
.... other code ....
callback:Gaspn_spawned(&on_player_spawned);
}
function on_player_spawned()
{
wait(5);
IPrintLnBold("WELCOME");
}


All the callback functions require the function names to be passed as a pointer, so just include & before the function name.

You can find all the callbacks that Treyarch provided by opening share\raw\scripts\shared\callbacks_shared.gsc and jump down to line 113. They include comments on what each one does and how to use it.


Is this necessary? Or is it still possible to ghetto rig it?
09-29-2016, 09:32 PM #3
Specter
Pro Memer
Originally posted by anthonything View Post
Is this necessary? Or is it still possible to ghetto rig it?


Why would you want to though
09-29-2016, 09:59 PM #4
Tustin
Balls of Steel
Originally posted by anthonything View Post
Is this necessary? Or is it still possible to ghetto rig it?

It's not necessary and the old way of doing things still works, but this is far cleaner and easier to write if you're making a bunch of scripts :p.
09-30-2016, 02:05 AM #5
anthonything
Space Ninja
Originally posted by Tustin View Post
It's not necessary and the old way of doing things still works, but this is far cleaner and easier to write if you're making a bunch of scripts :p.


Oh I agree. I just like to know how it all works. Can't get the tools cause I dont have the game, so i'm trying to stay updated
09-30-2016, 02:05 AM #6
anthonything
Space Ninja
Originally posted by Specter View Post
Why would you want to though


Because in certain scenarios you may not need a callback at all.
09-30-2016, 02:38 AM #7
SC58
Former Staff
not really new, callbacks where in bo1/2
Last edited by SC58 ; 09-30-2016 at 02:42 AM.

The following 2 users say thank you to SC58 for this useful post:

EternalHabit, MCabCon
12-08-2017, 08:32 AM #8
Revenant Mods
TrophyHunter
cool Happy

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo