AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [CSGO]SDKHooks: Instruction contained invalid parameter (https://forums.alliedmods.net/showthread.php?t=306808)

Nerus 04-15-2018 04:27

[CSGO]SDKHooks: Instruction contained invalid parameter
 
I have the same problem on 1.9 and 1.8 SM.

Problem:
On shoot temmate, plugn blaming:

Code:

L 04/15/2018 - 00:15:48: [SM] Exception reported: Instruction contained invalid parameter
L 04/15/2018 - 00:15:48: [SM] Blaming: teamkill.smx
L 04/15/2018 - 00:15:48: [SM] Call stack trace:
L 04/15/2018 - 00:15:48: [SM]  [1] Line 64, teamkill.sp::OnTakeDamage

Code:
PHP Code:

#include <maincore>

#pragma semicolon 1
#pragma newdecls required

#define PLUGIN_NAME            "Team kill"
#define PLUGIN_VERSION        "v1.0"
#define PLUGIN_DESCRIPTION    "Controling team killing"
#define DEBUG                1

public Plugin myinfo 
{
    
name PLUGIN_NAME,
    
author "Nerus",
    
description PLUGIN_DESCRIPTION,
    
version PLUGIN_VERSION,
    
url "https://forums.alliedmods.net/"
};

enum PluginErrors
{
    
SDKHookError 1
}

public 
void OnClientPostAdminCheck(int client)
{
    if(!
IsValidClient(client))
    {
        
#if DEBUG
        
PrintToServer("Client: [%d] is invalid"client);
        
#endif

        
return;
    }

    if(!
SDKHookEx(clientSDKHook_OnTakeDamageAliveOnTakeDamage))
        
ThrowError("Can't hook client: [%d]%N 'On Take Damage'."clientclient);
}

public 
Action OnTakeDamage(int victimint &attackerint &inflictorfloat &damageint &damagetypeint &weaponfloat damageForce[3], float damagePosition[3], int damagecustom)
{
    if(
IsValidPlayer(victimfalse) && IsValidPlayer(attackerfalse))
    {
        if(
IsSamePlayer(victimattacker))
            return 
Plugin_Continue;
        else
        {
            
//char WeaponCallBack[32];
            //GetEdictClassname(inflictor, WeaponCallBack, sizeof(WeaponCallBack));

            //if(StrEqual(WeaponCallBack, "inferno", false) || StrEqual(WeaponCallBack, "hegrenade_projectile", false))
            //    return Plugin_Continue;
        
}

        if(
IsTeammate(victimattacker))
            return 
Plugin_Handled;
    }

    
// Plugin_Continue    Continue with the original action
    // Plugin_Changed    Inputs or outputs have been overridden with new values
    // Plugin_Handled    Handle the action at the end (don't call it)
    // Plugin_Stop        Immediately stop the hook chain and handle the original

    
return Plugin_Continue// <-- this is 64 line nr.


PHP Code:

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <cstrike>
#include <multicolors>

#pragma semicolon             1

//////////////////
// PLAYER

stock int GetClientFromEvent(Handle event)
{
    return 
GetClientOfUserId(GetEventInt(event"userid"));
}

stock int GetAttackerFromEvent(Handle event)
{
    return 
GetClientOfUserId(GetEventInt(event"attacker"));
}

stock bool IsClient(int client)
{
    return (
client && client MaxClients+1);
}

stock bool IsValidClient(int client)
{
    return (
IsClient(client) && IsClientConnected(client) && IsClientInGame(client));
}

stock bool IsValidPlayer(int clientbool only_human)
{
    if(
only_human)
        return (
IsValidClient(client) && !IsClientSourceTV(client) && !IsFakeClient(client));
    else
        return (
IsValidClient(client) && !IsClientSourceTV(client));
}

stock bool IsDeadPlayer(int clientbool only_human false)
{
    return (
IsValidPlayer(clientonly_human) && !IsPlayerAlive(client));
}

stock bool IsAlivePlayer(int clientbool only_human)
{
    return (
IsValidPlayer(clientonly_human) && IsPlayerAlive(client));
}

stock bool IsBot(int client)
{
    return (
IsValidPlayer(clientfalse) && IsFakeClient(client));
}

stock bool IsSourceTV(int client)
{
    return (
IsValidClient(client) && IsClientSourceTV(client));
}

stock bool IsSamePlayer(int clientint other)
{
    return (
client == other);
}

stock bool IsPlayerAlone(int client)
{
    return ( 
IsAlivePlayer(clientfalse) && (GetPlayersCountFromTeam(GetClientTeam(client), ONLY_ALIVES, !ONLY_HUMMANS) < 2) );
}

stock bool IsVip(int client)
{
    return (
IsValidPlayer(clienttrue) && GetUserAdmin(client) != INVALID_ADMIN_ID);
}

stock bool IsAdmin(int client)
{
    return (
IsValidPlayer(clienttrue) && GetAdminFlag(GetUserAdmin(client), Admin_Generic));
}

//////////////////
// Team

stock bool IsTeammate(int clientint second)
{
    return (
GetClientTeam(client) == GetClientTeam(second));



Fyren 04-15-2018 06:24

Re: [CSGO]SDKHooks: Instruction contained invalid parameter
 
Are you using a compiler from an official build of SM?

Nerus 04-15-2018 07:20

Re: [CSGO]SDKHooks: Instruction contained invalid parameter
 
Quote:

Originally Posted by Fyren (Post 2587785)
Are you using a compiler from an official build of SM?

Yes, but where is the point of your question, this problem is not occurred by the compiler?

Fyren 04-15-2018 07:48

Re: [CSGO]SDKHooks: Instruction contained invalid parameter
 
SM does checks on the compiled plugin code to see that some things make sense. The error means one of those checks failed. Either the compiler output something it shouldn't have or the check itself is wrong. A bug in the compiler is more likely, especially if you're running a custom modified version.

Can you post the exact versions of SM and compiler that result in seeing the error? Can you also post a copy of your plugin that you compiled?

Nerus 04-15-2018 11:38

Re: [CSGO]SDKHooks: Instruction contained invalid parameter
 
Currently, I found the problem in all of my functions of include but I don't get it:

Try to explain where is a different between "IsValidPlayer" and "IsValidEntity", valid ent will work correctly.
In the scope of SDKHooks "victim" is a client index same as "attacker", why then I have got "Instruction contained invalid parameter" error.

asherkin 04-15-2018 13:52

Re: [CSGO]SDKHooks: Instruction contained invalid parameter
 
We can not help you if you do not provide what was asked.

Nerus 04-15-2018 15:51

Re: [CSGO]SDKHooks: Instruction contained invalid parameter
 
Quote:

Originally Posted by asherkin (Post 2587865)
We can not help you if you do not provide what was asked.

OK, from scratch: I have the plugin to prevent Team killing with nades exception.
In the current state, plugin works.

But if I will use some functionality from maincore lib, the plugin will crash without any exception.
E.G: "IsValidClient" instead sm "IsValidEntity".

Code new version:

PHP Code:

#include <sdktools>
#include <sdkhooks>
#include <cstrike>

#pragma semicolon 1
#pragma newdecls required

#define PLUGIN_NAME            "Team kill"
#define PLUGIN_VERSION        "v1.0"
#define PLUGIN_DESCRIPTION            "Controling Shooting to Team and Killing Teammates"
#define DEBUG                0

public Plugin myinfo 
{
    
name PLUGIN_NAME,
    
author "Nerus",
    
description PLUGIN_DESCRIPTION,
    
version PLUGIN_VERSION,
    
url "https://forums.alliedmods.net/"
};

public 
void OnClientConnected(int client)
{
    if(
IsValidEntity(client))
        
SDKHook(clientSDKHook_OnTakeDamageOnTakeDamage);
}

public 
void OnPlayerSpawn(Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(GetEventInt(event"userid"));

    if(
IsValidEntity(client) && client && !PlayerChocked[client])
    {
        
SDKHook(clientSDKHook_OnTakeDamageOnTakeDamage);

        
PlayerChocked[client] = true;
    }
}

public 
Action OnTakeDamage(int victimint &attackerint &inflictorfloat &damageint &damagetype)
{
    
int attackerUserId attacker;
    
int victimUserId victim;
    
int inflictorId inflictor;

    
#if DEBUG
    
PrintToServer("attackerUserId: %d, victimUserId: %d, inflictorId: %d "attackerUserIdvictimUserIdinflictorId);
    
#endif

    
if ((!IsValidEntity(victimUserId)) || (!IsValidEntity(attackerUserId)))
        return 
Plugin_Continue;

    
char WeaponCallBack[32];
    
GetEdictClassname(inflictorWeaponCallBacksizeof(WeaponCallBack));

    if ((
strlen(WeaponCallBack) <= 0) || (attackerUserId == victimUserId) || (GetClientTeam(victimUserId) != GetClientTeam(attackerUserId)) )
        return 
Plugin_Continue;

    if (
IsUnRestrictedInflictEffect(inflictorId))
        return 
Plugin_Continue;

    
float attackerDamage damage;

    
#if DEBUG
    
PrintToServer("damage given: %f"attackerDamage);
    
#endif

    
int attacerHealth GetClientHealth(attackerUserId);

    
#if DEBUG
    
PrintToServer("attacerHealth: healt: %d"attacerHealth);
    
#endif

    
int relative view_as<int>(RoundToNearest(float(attacerHealth) - attackerDamage));
    
    
#if DEBUG
    
PrintToServer("Relative: %d"relative);
    
#endif

    
if(relative && attacerHealth relative)
        
SetEntityHealth(attackerrelative);
    else
        
ForcePlayerSuicide(attacker);

    return 
Plugin_Handled;
}

public 
bool IsUnRestrictedInflictEffect(int inflictor)
{
    
char effect[32];
    
GetEdictClassname(inflictoreffect32);

    
#if DEBUG
    
PrintToServer("Inflictor effect: %s"effect);
    
#endif

    
return (StrEqual(effect"inferno"false) ||
            
StrEqual(effect"hegrenade_projectile"false) ||
            
StrEqual(effect"decoy_projectile"false) ||
            
StrEqual(effect"flashbang_projectile"false) ||
            
StrEqual(effect"smokegrenade_projectile"false));



Nerus 04-16-2018 12:03

Re: [CSGO]SDKHooks: Instruction contained invalid parameter
 
Ok I found the problem:

PHP Code:

OnTakeDamage(int victimint &attackerint &inflictorfloat &damageint &damagetype

Client indexing started from 1 to MaxClients but in this case int &attacker is always 0.

any idea how to fix it?

asherkin 04-16-2018 17:35

Re: [CSGO]SDKHooks: Instruction contained invalid parameter
 
0 is perfectly valid for attacker - it indicates damage done by the world (such as falling damage).

Nerus 04-16-2018 17:48

Re: [CSGO]SDKHooks: Instruction contained invalid parameter
 
Quote:

Originally Posted by asherkin (Post 2588031)
0 is perfectly valid for attacker - it indicates damage done by the world (such as falling damage).

OK, then how to determinate who directly was shooting to the victim?


All times are GMT -4. The time now is 16:56.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.