Sven Co-op

Sven Co-op

Help, please
Hello. I tried to write a plugin to make it possible to breathe underwater, but it does not compile, it says in the log file Warnings are treated as errors by the application. Sorry for my English.

void PluginInit()
{
g_Module.ScriptInfo.SetAuthor( "Author" );
g_Module.ScriptInfo.SetContactInfo( "" );

g_Hooks.RegisterHook( Hooks::Player::PlayerTakeDamage, @PlayerTakeDamage );
}

HookReturnCode PlayerTakeDamage( DamageInfo@ pPlayer )
{
CBaseEntity@ pevVictim;
CBaseEntity@ pevInflictor;
CBaseEntity@ pevAttacker;
float flDamage;
int bitsDamageType;

for (int i = 1; i <= g_Engine.maxClients; i++)
{
CBasePlayer@ pPlayer = g_PlayerFuncs.FindPlayerByIndex(i);
if ( pPlayer !is null && pPlayer.IsAlive() )
{
if ( bitsDamageType & DMG_DROWN != 0 )
flDamage = 0;
}
return HOOK_CONTINUE;
}
return HOOK_HANDLED;
}
< >
Showing 1-7 of 7 comments
Sep 17, 2024 @ 12:22am 
Did you check what the error is in the console?
Hello, there are no errors in the console, I am new to scripting, I tried many options, but almost always there was a description of the error in the log file
Sep 17, 2024 @ 9:39am 
Originally posted by Nemo:
but almost always there was a description of the error in the log file
That's what you need to post.

If you enable developer mode in your game as follows you should also see warnings and errors in the game console when you (re)start the map:
developer 1
Thank you for your advice. Here are the lines from the console

WARNING: Angelscript: e:/steam/steamapps/common/sven co-op/svencoop/scripts/plugins/Test.as (19, 16) : Variable 'pPlayer' hides another variable of same name in outer scope
WARNING: Angelscript: e:/steam/steamapps/common/sven co-op/svencoop/scripts/plugins/Test.as (22, 24) : 'bitsDamageType' is not initialized.
Sep 17, 2024 @ 1:07pm 
I can see two problems with your script.

1. Your `PlayerTakeDamage` function is looping through all players, but with variable `pPlayer`. You already declared `pPlayer` as a function argument so you can't declare it again with the same name. I'd just remove the `for` loop entirely.
2. `bitsDamageType` is not being set prior to reading it again. You need to read it from the DamageInfo[r4to0.github.io] instance first.
or you could improve on (steal) someone else's idea and you're sorted :)

https://github.com/ValveSoftware/halflife/blob/master/dlls/airtank.cpp

or just place the entity itself, which svencoop has
Thank you for your help
< >
Showing 1-7 of 7 comments
Per page: 1530 50

Date Posted: Sep 16, 2024 @ 10:45am
Posts: 7