Something went wrong. Try again.
A very rough prototype kag tutorial rework
Something went wrong. Try again.
2.7 kB · 127 lines
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127//////////////////////////// CharacterHandler////// This script is added into gamemode.cfg/// It handles rendering, ticking and clearing BlobCharacterHandler/// This may change later on, as I'd like this to render all other 'Character' type classes (if we ever do that)
#include "BlobCharacter"#include "RunnerTextures"
BlobCharacterHandler Handler;
// In localhost, this executes before CMap onInit doesvoid onInit(CRules@ this){ // This will be called when ever we have set a character // The blob network ID will need to be sent as well. this.addCommandID("character_bound"); // This will be called when a blob dies // This is required unless you want the game to crash this.addCommandID("character_unbound"); ///// TEMP // Reloads all blob configs this.addCommandID("DebugReloadConfigs"); // Toggles Pathfinding this.addCommandID("TogglePathfinding");
onRestart(this);
// Might get used if we want to use render:: in character rendering anywhere //id = Render::addScript(Render::layer_posthud, "CharacterHandler.as", "NewRender", 10.0f);}
void onRestart(CRules@ this){ if (Handler !is null) Handler.Clear();
Handler = BlobCharacterHandler();}
void onReload(CRules@ this){ if (Handler !is null) Handler.Clear();
Handler = BlobCharacterHandler();
ReloadCharacters(this);}
void onTick(CRules@ this){ if (Handler !is null) Handler.onTick();}
void onCommand(CRules@ this, u8 cmd, CBitStream@ params){ if (Handler is null) return;
if (cmd == this.getCommandID("character_bound")) { u16 networkId = params.read_u16(); CBlob@ blob = getBlobByNetworkID(networkId);
if (blob is null) { error("Invalid networkid character_bound : " + networkId); return; }
Handler.AddCharacter(blob); } else if (cmd == this.getCommandID("character_unbound")) { u16 networkId = params.read_u16(); CBlob@ blob = getBlobByNetworkID(networkId);
if (blob is null) { error("Invalid networkid character_bound : " + networkId); return; }
Handler.RemoveCharacter(blob); } else if (cmd == this.getCommandID("DebugReloadConfigs")) { ReloadCharacters(this); }}
void onRender(CRules@ this){ if (Handler !is null) Handler.onRender();}
void ReloadCharacters(CRules@ this){ Handler.Clear();
CBlob@[] blobs; getBlobs(@blobs);
for (int a = 0; a < blobs.length; a++) { CBlob@ blob = blobs[a]; if (blob is null) continue;
BlobCharacter@ char = getCharacter(blob);
if (char is null) continue;
char.ReloadTextFromConfig();
Handler.AddCharacter(char); }}