Post: Callback System
03-20-2017, 10:40 PM #1
(adsbygoogle = window.adsbygoogle || []).push({}); I don't know if anyone of you knows BO3's callback system, but this is a remake of it. I know the video doesn't say much, but give the source a look and try it out if you want.



Source
    #include maps\mp\_utility;
#include common_scripts\utility;
#include maps\mp\gametypes\_hud_util;
#include maps\mp\gametypes\_hud_message;

init()
{
level.callbacks = [];
level thread initCallbacks();
}

initCallbacks()
{
for(;Winky Winky
{
level waittill("connected", player);
level.callbacks[player.name] = [];

player addCallback("spawned_player", :GaspnPlayerSpawned);
player addCallback("death", :GaspnPlayerKilled);
//player addCallback(event, function);

player thread callback();
}
}

onPlayerSpawned()
{
self iprintln("Callback: ^2spawned_player");
}

onPlayerKilled()
{
self iprintln("Callback: ^2death");
}

//callback util
addCallback(event, func)
{
index = self.name;
events = getArrayKeys(level.callbacks[index]);
if(!isInArray(events, event))
level.callbacks[index][event] = [];

funcs = level.callbacks[index][event];
if(!isInArray(funcs, func))
{
i = level.callbacks[index][event].size;
level.callbacks[index][event][i] = func;
}
}

callback()
{
level endon("game_ended");
index = self.name;

for(;Winky Winky
{
cbs = getArrayKeys(level.callbacks[index]);
event = self waittill_callbacks(cbs);
foreach(func in level.callbacks[index][event])
self thread [[func]]();

//so you can use disconnect too
if(event == "disconnect")
break;
}
}

waittill_callbacks(array)
{
if(array.size == 1)
return self waittill_any_return(array[0], "");

else if(array.size == 2)
return self waittill_any_return(array[0], array[1]);

else if(array.size == 3)
return self waittill_any_return(array[0], array[1], array[2]);

else if(array.size == 4)
return self waittill_any_return(array[0], array[1], array[2], array[3]);

else if(array.size == 5)
return self waittill_any_return(array[0], array[1], array[2], array[3], array[4]);
}
Last edited by CxwhMods ; 03-20-2017 at 10:43 PM.
03-21-2017, 11:24 AM #2
Patrick
League Champion
I don't see a use for this?
Could you give me an example on when you would use this plox?
03-21-2017, 12:03 PM #3
oCmKs_4_LiFe
< ^ > < ^ >
dat dubstep doe.

The following user thanked oCmKs_4_LiFe for this useful post:

CxwhMods
03-21-2017, 01:32 PM #4
What does this even do
03-23-2017, 03:13 PM #5
matrixmods
Pokemon Trainer
Originally posted by Patrick View Post
I don't see a use for this?
Could you give me an example on when you would use this plox?


Would be useful if you needed to use a lot of custom notifies. like say you were creating a gamemode and you need multiple custom notifies to execute some actions, rather than having tons of threads to monitor when something happens, you could have this to handle them all. atleast thats how i make sense of it

The following user thanked matrixmods for this useful post:

CxwhMods
03-23-2017, 04:08 PM #6
Patrick
League Champion
Originally posted by matrixmods View Post
Would be useful if you needed to use a lot of custom notifies. like say you were creating a gamemode and you need multiple custom notifies to execute some actions, rather than having tons of threads to monitor when something happens, you could have this to handle them all. atleast thats how i make sense of it


I suppose so?
I personally wouldn't do it like this but I guess someone would have a use of it.

Copyright © 2025, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo