Can callbacks be called within a map script?

Have questions about CoD4 mapping that aren't covered in the tutorials section? Post here!

Moderator: Core Staff

Post Reply
Pphelix
CJ Wannabe
CJ Wannabe
Posts: 2
Joined: March 21st, 2016, 11:34 pm

Can callbacks be called within a map script?

Post by Pphelix » March 21st, 2016, 11:37 pm

Are callbacks possible within a map script? Reason as to why is because i want something to happen when someone dies within a map. If they're how are they accessed?

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Can callbacks be called within a map script?

Post by Rezil » March 22nd, 2016, 3:46 pm

I'm not sure, but if you want to do something once a player dies couldn't you just track each player as they connect (and stop tracking them once they disconnect) and check their health every server frame? Once it reaches zero execute whatever code you want to execute. Also take care of players going into spectator mode etc.
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

Pphelix
CJ Wannabe
CJ Wannabe
Posts: 2
Joined: March 21st, 2016, 11:34 pm

Re: Can callbacks be called within a map script?

Post by Pphelix » March 23rd, 2016, 12:53 am

I just did a for loop for all players and ran a thread, i don't know why i didn't think of that in the first place XD Problem is solved now!

MoonDog
CJ Wannabe
CJ Wannabe
Posts: 3
Joined: March 23rd, 2016, 8:59 am
Contact:

Re: Can callbacks be called within a map script?

Post by MoonDog » March 23rd, 2016, 9:04 am

I know I'm late to the thread, but the answer is yes.

I don't what you are scripting for, but code hits a script callback that is setup in _callbacksetup.gsc.

[[level.callbackPlayerKilled]]


So if you have your own custom function you'd like to setup, some where in your map you need to point that to your function.

Example:


level.callbackPlayerKilled= ::YourFunction;


YourFunction( eInflictor, eAttacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, timeOffset, deathAnimDuration )
{
}
Last edited by MoonDog on March 24th, 2016, 9:47 pm, edited 1 time in total.

MoonDog
CJ Wannabe
CJ Wannabe
Posts: 3
Joined: March 23rd, 2016, 8:59 am
Contact:

Re: Can callbacks be called within a map script?

Post by MoonDog » March 23rd, 2016, 9:06 am

Can't modify my post while waiting for moderation, but I pasted the wrong callback I believe. Should be [[level.callbackPlayerKilled]]

Pedsdude
Site Admin
Site Admin
Posts: 15908
Joined: October 15th, 2004, 7:18 pm
Location: UK

Re: Can callbacks be called within a map script?

Post by Pedsdude » March 24th, 2016, 5:26 pm

MoonDog wrote:Can't modify my post while waiting for moderation, but I pasted the wrong callback I believe. Should be [[level.callbackPlayerKilled]]
Posts approved now :)
Image
Image

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

Re: Can callbacks be called within a map script?

Post by IzNoGoD » April 9th, 2016, 3:31 pm

MoonDog wrote:I know I'm late to the thread, but the answer is yes.

I don't what you are scripting for, but code hits a script callback that is setup in _callbacksetup.gsc.

[[level.callbackPlayerKilled]]


So if you have your own custom function you'd like to setup, some where in your map you need to point that to your function.

Example:


level.callbackPlayerKilled= ::YourFunction;


YourFunction( eInflictor, eAttacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, timeOffset, deathAnimDuration )
{
}
Should keep the original callback in place. Best way to do that is to overwrite the level.callbackplayerkilled 2 seconds after server has started (because some mods overwrite it 1 second after already...) and call the original callback from within your custom callback.

Code: Select all

main()
{
    thread hijack();
}

hijack()
{
    wait 2;
    level.originalcallbackPlayerKilled = level.callbackPlayerKilled;
    level.callbackPlayerKilled = ::yourfunction;
}

yourfunction(stuff goes here)
{
    self iprintln("You are dead meat");
    self [[level.originalcallbackPlayerKilled]](stuff goes here again);
}
LMGTFY!

Its not a glitch... Its the future!

MoonDog
CJ Wannabe
CJ Wannabe
Posts: 3
Joined: March 23rd, 2016, 8:59 am
Contact:

Re: Can callbacks be called within a map script?

Post by MoonDog » April 12th, 2016, 3:06 am

IzNoGoD wrote:
Should keep the original callback in place. Best way to do that is to overwrite the level.callbackplayerkilled 2 seconds after server has started (because some mods overwrite it 1 second after already...) and call the original callback from within your custom callback.

Code: Select all

main()
{
    thread hijack();
}

hijack()
{
    wait 2;
    level.originalcallbackPlayerKilled = level.callbackPlayerKilled;
    level.callbackPlayerKilled = ::yourfunction;
}

yourfunction(stuff goes here)
{
    self iprintln("You are dead meat");
    self [[level.originalcallbackPlayerKilled]](stuff goes here again);
}

If you really want to store off the original callback, you can. I don't necessarily like making a call stack larger than it needs to be, just out of best practice. If possible, however, avoid waits. If you are working on a mode that has waits before it defines its callbacks, it is probably a hacky fix because they are attempting to define them out of order and they are getting overridden by the default logic. That or they are improperly threading functions when they do not need to be threaded.

See if you can refactor it, take note of when it is executed and then see to it that your call happens afterwards. At most, waittillframeend will suffice. Again, its a best practices thing. Waits should be avoided in threads and functions during load and setup when it is possible to do so.

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

Re: Can callbacks be called within a map script?

Post by IzNoGoD » May 8th, 2016, 12:20 pm

MoonDog wrote:
IzNoGoD wrote:
Should keep the original callback in place. Best way to do that is to overwrite the level.callbackplayerkilled 2 seconds after server has started (because some mods overwrite it 1 second after already...) and call the original callback from within your custom callback.

Code: Select all

main()
{
    thread hijack();
}

hijack()
{
    wait 2;
    level.originalcallbackPlayerKilled = level.callbackPlayerKilled;
    level.callbackPlayerKilled = ::yourfunction;
}

yourfunction(stuff goes here)
{
    self iprintln("You are dead meat");
    self [[level.originalcallbackPlayerKilled]](stuff goes here again);
}

If you really want to store off the original callback, you can. I don't necessarily like making a call stack larger than it needs to be, just out of best practice. If possible, however, avoid waits. If you are working on a mode that has waits before it defines its callbacks, it is probably a hacky fix because they are attempting to define them out of order and they are getting overridden by the default logic. That or they are improperly threading functions when they do not need to be threaded.

See if you can refactor it, take note of when it is executed and then see to it that your call happens afterwards. At most, waittillframeend will suffice. Again, its a best practices thing. Waits should be avoided in threads and functions during load and setup when it is possible to do so.
I fully agree coding-wise, however, I've seen a few mods (in cod2) that hijack the callbacks without calling the original ones. Hijacking the original ones and re-calling them would break some of that stuff for sure.
LMGTFY!

Its not a glitch... Its the future!

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests