Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
hzqst committed Jan 19, 2023
1 parent b588d9b commit 79c6500
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
51 changes: 51 additions & 0 deletions README_ASQCVAR.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# QueryCvar in AngelScript (aka asqcvar)

* Exposes "server.NewDllFunction.pfnCvarValue" and "server.NewDllFunction.pfnCvarValue2" to AngelScript engine

* Being able to read response of network message "svc_sendcvarvalue" and "svc_sendcvarvalue2" from client.

## Send a cvar query requset to client

```
//NetworkMessages::NetworkMessageType(58) means "svc_sendcvarvalue2"
NetworkMessage m( MSG_ONE, NetworkMessages::NetworkMessageType(58), pPlayer.edict() );
m.WriteLong(114514);//RequestId
m.WriteString("default_fov");
m.End();
```

## Register an asynchronous callback for cvar query response

```
g_EngineFuncs.SetQueryCvar2Callback(1, function(CBasePlayer@ pPlayer, int requestId, string cvarName, string value){
g_Game.AlertMessage(at_aiconsole, "%1's %2 is %3\n", pPlayer.pev.netname, cvarName, value );
});
```

## Register global hooks

```
HookReturnCode PlayerQueryCvar(CBasePlayer @pPlayer, const string &in value)
{
g_Game.AlertMessage(at_aiconsole, "%1's cvar is %2\n", pPlayer.pev.netname, value );
return HOOK_CONTINUE;
}
HookReturnCode PlayerQueryCvar2(CBasePlayer @pPlayer, int requestId, const string &in cvarName, const string &in value)
{
g_Game.AlertMessage(at_aiconsole, "%1's %2 is %3\n", pPlayer.pev.netname, cvarName, value );
return HOOK_CONTINUE;
}
void MapInit()
{
g_Hooks.RegisterHook(Hooks::Player::QueryCvar, @PlayerQueryCvar);
g_Hooks.RegisterHook(Hooks::Player::QueryCvar2, @PlayerQueryCvar2);
}
```
2 changes: 1 addition & 1 deletion asqcvar/asqcvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ void ASQCvar_CallQueryCvar2Callback(void *pPlayer, int request_id, const char *c
void RegisterAngelScriptHooks()
{
g_QueryCvarHook = ASEXT_RegisterHook("Get called when svc_querycvar response is received", StopMode_CALL_ALL, 2, ASFlag_MapScript | ASFlag_Plugin, "Player", "QueryCvar", "CBasePlayer @pPlayer, const string &in value");
g_QueryCvar2Hook = ASEXT_RegisterHook("Get called when svc_querycvar2 response is received", StopMode_CALL_ALL, 2, ASFlag_MapScript | ASFlag_Plugin, "Player", "QueryCvar2", "CBasePlayer @pPlayer, int requestId, const string &in cvar, const string &in value");
g_QueryCvar2Hook = ASEXT_RegisterHook("Get called when svc_querycvar2 response is received", StopMode_CALL_ALL, 2, ASFlag_MapScript | ASFlag_Plugin, "Player", "QueryCvar2", "CBasePlayer @pPlayer, int requestId, const string &in cvarName, const string &in value");
}

0 comments on commit 79c6500

Please sign in to comment.