Can callbacks be called within a map script?
Moderator: Core Staff
Can callbacks be called within a map script?
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?
-
- 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?
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.
[...]
#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.
Re: Can callbacks be called within a map script?
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!
Re: Can callbacks be called within a map script?
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 )
{
}
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.
Re: Can callbacks be called within a map script?
Can't modify my post while waiting for moderation, but I pasted the wrong callback I believe. Should be [[level.callbackPlayerKilled]]
Re: Can callbacks be called within a map script?
Posts approved nowMoonDog wrote:Can't modify my post while waiting for moderation, but I pasted the wrong callback I believe. Should be [[level.callbackPlayerKilled]]



Re: Can callbacks be called within a map script?
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.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 )
{
}
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);
}
Re: Can callbacks be called within a map script?
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.
Re: Can callbacks be called within a map script?
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.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.
Who is online
Users browsing this forum: No registered users and 3 guests