Raised This Month: $32 Target: $400
 8% 

Solved CreateTimer and using own cvar, it doesnt work, why?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Javierko
AlliedModders Donor
Join Date: Sep 2017
Location: Czech republic
Old 03-19-2018 , 14:40   CreateTimer and using own cvar, it doesnt work, why?
Reply With Quote #1

Hello,

i am making plugin, that will give you after some seconds from roundstart gun. But there is problem,
i made cvar with value and after that i created timers with cvar.FloatValue, but it doesnt work and idk why.

Here is code hastebin
__________________
My Github & Sourcemod work.
If you like my work and if you want to support me, you can through PayPal.

Official SourceMod CZ/SK Discord: https://discord.gg/Qvar55a

Last edited by Javierko; 03-20-2018 at 17:22.
Javierko is offline
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 03-19-2018 , 15:14   Re: CreateTimer and using own cvar, it doesnt work, why?
Reply With Quote #2

Quote:
Originally Posted by Javierko View Post
Hello,

i am making plugin, that will give you after some seconds from roundstart gun. But there is problem,
i made cvar with value and after that i created timers with cvar.FloatValue, but it doesnt work and idk why.

Here is code hastebin
maybe show us full code.
no need for extern paste provider. [PHP][/PHP]-Tags working fine on forum.

edit:
PHP Code:
GetEventInt(event"userid"
won't works cause event 'round_start' don't have a user event. You have to make a loop through all players on round start.

edit2: powerlord beat me =)
__________________
coding & free software

Last edited by shanapu; 03-19-2018 at 15:19.
shanapu is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 03-19-2018 , 15:15   Re: CreateTimer and using own cvar, it doesnt work, why?
Reply With Quote #3

Code:
int client = GetClientOfUserId(GetEventInt(event, "userid"));
round_start doesn't have a userid parameter. You need to loop over all valid client indexes (1 through MaxClients) instead.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 03-19-2018 , 15:24   Re: CreateTimer and using own cvar, it doesnt work, why?
Reply With Quote #4

You would see in your error logs that you are trying to get an event parameter that doesn't exist.

When things dont work as expected.

1. Check error logs
2. Put print messages in your code to help debug and find problems
3. Post full code sets
__________________
Neuro Toxin is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 03-19-2018 , 16:44   Re: CreateTimer and using own cvar, it doesnt work, why?
Reply With Quote #5

I meant to mention this in my last post, but you should probably look over the clients in the timer callback rather than creating one timer per person. Just remember to check if the client is in game and alive before giving them weapons.

Oh, and maybe store the timers as global handles so that you can close them if the round ends before they're called.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 03-19-2018 at 16:45.
Powerlord is offline
Javierko
AlliedModders Donor
Join Date: Sep 2017
Location: Czech republic
Old 03-19-2018 , 16:46   Re: CreateTimer and using own cvar, it doesnt work, why?
Reply With Quote #6

Okay, there is some update, but still doesnt work...

PHP Code:
#pragma semicolon 1

#define DEBUG

#define PLUGIN_AUTHOR "Javierko"
#define PLUGIN_VERSION "1.0.0"

#include <sourcemod>
#include <sdktools>
#include <cstrike>

char g_szTag[64];

ConVar g_cvTag;
ConVar g_cvTimerFirst;
float g_fTimerFirst;

ConVar g_cvTimerSec;
float g_fTimerSec;

ConVar g_cvTimerThd;
float g_fTimerThd;

int m_hMyWeapons;

#pragma newdecls required

public Plugin myinfo =
{
    
name "[CS:GO] Round item giver",
    
author PLUGIN_AUTHOR,
    
description "You can set by own item giver.",
    
version PLUGIN_VERSION,
    
url "https://github.com/javierko"
};

public 
void OnPluginStart()
{
    
HookEvent("player_spawn"Event_PlayerSpawnEventHookMode_Pre);

    
g_cvTag CreateConVar("sm_ig_chattag""[SM]""Sets tag for messages.");
    
g_cvTag.AddChangeHook(OnConVarChanged);
    
g_cvTag.GetString(g_szTagsizeof(g_szTag));

    
g_cvTimerFirst CreateConVar("sm_ig_giveknife""60.0""Sets a first time to drop knife"_true1.0);
    
g_fTimerFirst g_cvTimerFirst.FloatValue;
    
g_cvTimerSec CreateConVar("sm_ig_givep250""120.0""Sets a time to drop P250"_true1.0);
    
g_fTimerSec g_cvTimerSec.FloatValue;
    
g_cvTimerThd CreateConVar("sm_ig_giveump""180.0""Sets a time to drop UMP"_true1.0);
    
g_fTimerThd g_cvTimerThd.FloatValue;

    
g_cvTimerFirst.AddChangeHook(OnConVarChanged);
    
g_cvTimerSec.AddChangeHook(OnConVarChanged);
    
g_cvTimerThd.AddChangeHook(OnConVarChanged);

    
AutoExecConfig(true"RoundItemGiver");
}

public 
void OnConVarChanged(ConVar convar, const char[] oldValue, const char[] newValue)
{
    if(
convar == g_cvTimerFirst)
    {
        
g_fTimerFirst StringToFloat(newValue);
    }
    else if(
convar == g_cvTimerSec)
    {
        
g_fTimerSec StringToFloat(newValue);
    }
    else if(
convar == g_cvTimerThd)
    {
        
g_fTimerThd StringToFloat(newValue);
    }
    else if(
convar == g_cvTag)
    {
        
strcopy(g_szTagsizeof(g_szTag), newValue);
    }
}

public 
Action Event_PlayerSpawn(Handle event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(GetEventInt(event"userid"));
    if(
IsValidClient(client) && IsPlayerAlive(client))
    {
        
CreateTimer(g_fTimerFirstGiveKnifeclient);
        
CreateTimer(g_fTimerSecGiveP250client);
        
CreateTimer(g_fTimerThdGiveUMPclient);
    }
}

public 
Action GiveKnife(Handle timerint userid)
{
    
int client GetClientOfUserId(userid);
    if(
IsValidClient(client) && IsPlayerAlive(client))
    {
        if(!
HasClientKnife(client))
        {
            
GivePlayerItem(client"weapon_knife");
            
PrintToChat(client"%s You got knife as present from server."g_szTag);
        }
        
PrintToChat(client"%s Everybody got knife as present from server."g_szTag);
    }
    return 
Plugin_Stop;
}

public 
Action GiveUMP(Handle timerint userid)
{
    
int client GetClientOfUserId(userid);
    if(
IsValidClient(client) && IsPlayerAlive(client))
    {
        if(!
HasClientPrimaryGun(client))
        {
            
GivePlayerItem(client"weapon_ump45");
            
PrintToChat(client"%s You got UMP as present from server."g_szTag);
        }
        
PrintToChat(client"%s Everybody got knife as present from server."g_szTag);
    }
    return 
Plugin_Stop;
}

public 
Action GiveP250(Handle timerint userid)
{
    
int client GetClientOfUserId(userid);
    if(
IsValidClient(client) && IsPlayerAlive(client))
    {
        if(!
HasClientSecundaryGun(client))
        {
            
GivePlayerItem(client"weapon_p250");
            
PrintToChat(client"%s You got p250 as present from server."g_szTag);
        }
        
PrintToChat(client"%s Everybody got p250 as present from server."g_szTag);
    }

    return 
Plugin_Stop;
}

public 
bool HasClientKnife(int client)
{
    for(
int i 0128+= 4)
    {
        
int ent GetEntDataEnt2(clientm_hMyWeapons i);
        if(!
IsValidEntity(ent))
        {
            continue;
        }
        
int iDefIndex GetEntProp(entProp_Send"m_iItemDefinitionIndex");
        switch(
iDefIndex)
        {
            case 
41: return true//Knife
            
case 42: return true//Knife
            
case 59: return true//Knife
            
case 500: return true//Knife
            
case 505: return true//Knife
            
case 506: return true//Knife
            
case 507: return true//Knife
            
case 508: return true//Knife
            
case 509: return true//Knife
            
case 512: return true//Knife
            
case 514: return true//Knife
            
case 515: return true//Knife
            
case 516: return true//Knife
        
}
    }
    return 
false;
}

public 
bool HasClientSecundaryGun(int client)
{
    for(
int i 0128+= 4)
    {
        
int ent GetEntDataEnt2(clientm_hMyWeapons i);
        if(!
IsValidEntity(ent))
        {
            continue;
        }
        
int iDefIndex GetEntProp(entProp_Send"m_iItemDefinitionIndex");
        switch(
iDefIndex)
        {
            case 
1: return true//Deagle
            
case 2: return true//Dual berretas
            
case 3: return true//Five-seven
            
case 4: return true//Glock
            
case 30: return true//Tec-9
            
case 32: return true//P2000
            
case 36: return true//P250
            
case 61: return true//USP
            
case 63: return true//CZ75
            
case 64: return true//Revolver
        
}
    }
    return 
false;
}

public 
bool HasClientPrimaryGun(int client)
{
    for(
int i 0128+= 4)
    {
        
int ent GetEntDataEnt2(clientm_hMyWeapons i);
        if(!
IsValidEntity(ent))
        {
            continue;
        }
        
int iDefIndex GetEntProp(entProp_Send"m_iItemDefinitionIndex");
        switch(
iDefIndex)
        {
            case 
7: return true//AK-47
            
case 8: return true//AUG
            
case 9: return true//AWP
            
case 10: return true//FAMAS
            
case 11: return true//G35G1
            
case 13: return true//Galil
            
case 14: return true//M249
            
case 16: return true//M4A4
            
case 17: return true//MAC-10
            
case 19: return true//P90
            
case 24: return true//UMP
            
case 25: return true//XM1014
            
case 26: return true//Bizon
            
case 27: return true//MAG
            
case 28: return true//negev
            
case 29: return true//Sawed Off
            
case 33: return true//MP7
            
case 34: return true//MP9
            
case 35: return true//nova
            
case 38: return true//scar
            
case 39: return true//SG 553
            
case 40: return true//SSG 08
            
case 60: return true//M4A1-S
        
}
    }
    return 
false;
}

stock bool IsValidClient(int client)
{
    if (
client <= || client MaxClients || !IsClientInGame(client))
      {
        return 
false;
    }
    return 
true;

__________________
My Github & Sourcemod work.
If you like my work and if you want to support me, you can through PayPal.

Official SourceMod CZ/SK Discord: https://discord.gg/Qvar55a
Javierko is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 03-19-2018 , 17:42   Re: CreateTimer and using own cvar, it doesnt work, why?
Reply With Quote #7

Always mention how it doesnt work and any errors.
__________________
Neuro Toxin is offline
Javierko
AlliedModders Donor
Join Date: Sep 2017
Location: Czech republic
Old 03-19-2018 , 18:16   Re: CreateTimer and using own cvar, it doesnt work, why?
Reply With Quote #8

Sorry I forget it.

Here we go:

PHP Code:
L 03/19/2018 20:35:38: [SMBlamingrounditemgiver.smx
L 03
/19/2018 20:35:38: [SMCall stack trace:
L 03/19/2018 20:35:38: [SM]   [0GetEntDataEnt2
L 03
/19/2018 20:35:38: [SM]   [1Line 87C:\Users\User\Desktop\scripting\rounditemgiver.sp::HasClientKnife
L 03
/19/2018 20:35:38: [SM]   [2Line 59C:\Users\User\Desktop\scripting\rounditemgiver.sp::GiveKnife
L 03
/19/2018 20:35:38: [SMException reportedOffset 0 is invalid
L 03
/19/2018 20:35:38: [SMBlamingrounditemgiver.smx
L 03
/19/2018 20:35:38: [SMCall stack trace:
L 03/19/2018 20:35:38: [SM]   [0GetEntDataEnt2
L 03
/19/2018 20:35:38: [SM]   [1Line 87C:\Users\User\Desktop\scripting\rounditemgiver.sp::HasClientKnife
L 03
/19/2018 20:35:38: [SM]   [2Line 59C:\Users\User\Desktop\scripting\rounditemgiver.sp::GiveKnife
L 03
/19/2018 20:36:38: [SMException reportedOffset 0 is invalid
L 03
/19/2018 20:36:38: [SMBlamingrounditemgiver.smx
L 03
/19/2018 20:36:38: [SMCall stack trace:
L 03/19/2018 20:36:38: [SM]   [0GetEntDataEnt2
L 03
/19/2018 20:36:38: [SM]   [1Line 117C:\Users\User\Desktop\scripting\rounditemgiver.sp::HasClientSecundaryGun
L 03
/19/2018 20:36:38: [SM]   [2Line 72C:\Users\User\Desktop\scripting\rounditemgiver.sp::GiveP250
L 03
/19/2018 20:36:38: [SMException reportedOffset 0 is invalid
L 03
/19/2018 20:36:38: [SMBlamingrounditemgiver.smx
L 03
/19/2018 20:36:38: [SMCall stack trace:
L 03/19/2018 20:36:38: [SM]   [0GetEntDataEnt2
L 03
/19/2018 20:36:38: [SM]   [1Line 117C:\Users\User\Desktop\scripting\rounditemgiver.sp::HasClientSecundaryGun
L 03
/19/2018 20:36:38: [SM]   [2Line 72C:\Users\User\Desktop\scripting\rounditemgiver.sp::GiveP250
L 03
/19/2018 20:38:25: [SMException reportedOffset 0 is invalid
L 03
/19/2018 20:38:25: [SMBlamingrounditemgiver.smx
L 03
/19/2018 20:38:25: [SMCall stack trace:
L 03/19/2018 20:38:25: [SM]   [0GetEntDataEnt2
L 03
/19/2018 20:38:25: [SM]   [1Line 87C:\Users\User\Desktop\scripting\rounditemgiver.sp::HasClientKnife
L 03
/19/2018 20:38:25: [SM]   [2Line 59C:\Users\User\Desktop\scripting\rounditemgiver.sp::GiveKnife
L 03
/19/2018 20:39:25: [SMException reportedOffset 0 is invalid
L 03
/19/2018 20:39:25: [SMBlamingrounditemgiver.smx
L 03
/19/2018 20:39:25: [SMCall stack trace:
L 03/19/2018 20:39:25: [SM]   [0GetEntDataEnt2
L 03
/19/2018 20:39:25: [SM]   [1Line 117C:\Users\User\Desktop\scripting\rounditemgiver.sp::HasClientSecundaryGun
L 03
/19/2018 20:39:25: [SM]   [2Line 72C:\Users\User\Desktop\scripting\rounditemgiver.sp::GiveP250 
__________________
My Github & Sourcemod work.
If you like my work and if you want to support me, you can through PayPal.

Official SourceMod CZ/SK Discord: https://discord.gg/Qvar55a

Last edited by Javierko; 03-19-2018 at 18:19. Reason: Update
Javierko is offline
xerox8521
Senior Member
Join Date: Sep 2011
Old 03-19-2018 , 18:37   Re: CreateTimer and using own cvar, it doesnt work, why?
Reply With Quote #9

m_hMyWeapons is never populated with the correct offset (which the error tells you).

Use FindSendPropInfo or FindDataMapInfo (not sure which works for m_hMyWeapons)

It should be enough todo this once in OnPluginStart

Last edited by xerox8521; 03-19-2018 at 18:38.
xerox8521 is offline
Javierko
AlliedModders Donor
Join Date: Sep 2017
Location: Czech republic
Old 03-20-2018 , 17:22   Re: CreateTimer and using own cvar, it doesnt work, why?
Reply With Quote #10

Some edits and it works.

Thanks, solved.
__________________
My Github & Sourcemod work.
If you like my work and if you want to support me, you can through PayPal.

Official SourceMod CZ/SK Discord: https://discord.gg/Qvar55a
Javierko is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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