Raised This Month: $12 Target: $400
 3% 

Solved Help creating a plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Pankrakles
New Member
Join Date: Jan 2018
Old 01-27-2018 , 11:18   Help creating a plugin
Reply With Quote #1

Hello, I am trying to creating a plugin which changes a convar every 25 mins, the convar (dm_headshot_only) is from this deathmatch plugin. But I can't figure out how to get the convar and then use it, please be aware this is my first attempt writing a plugin.

Current code

Quote:
#include <sourcemod>

public Plugin myinfo =
{
name = "HS Only timer test",
author = "Pankrakles",
description = "Changes to and from HS only every 25 mins",
version = "1.0",
};

new Handle:g_hhsonly;

public OnAllPluginsLoaded()
{
g_hhsonly = FindConVar("dm_headshot_only");

}

public void OnPluginStart()
{
CreateTimer(5.0, Timer_ChangeHSOnly, _, TIMER_REPEAT);
}

public Action Timer_ChangeHSOnly(Handle timer)
{
PrintToServer("Test every 5 seconds");
g_hhsonly.IntValue = "1";

return Plugin_Continue;

}
-The timer time is a placeholder just set to 5 seconds so I can see if it works

Would appreciate any help

Last edited by Pankrakles; 01-28-2018 at 12:23.
Pankrakles is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 01-27-2018 , 12:15   Re: Help creating a plugin
Reply With Quote #2

you are mixing old syntax with new syntax

following should be all in new syntax

PHP Code:
#include <sourcemod>

public Plugin myinfo 
{
name "HS Only timer test",
author "Pankrakles",
description "Changes to and from HS only every 25 mins",
version "1.0",
};

Handle g_hhsonly;

public 
void OnAllPluginsLoaded()
{
g_hhsonly FindConVar("dm_headshot_only");

}

public 
void OnPluginStart()
{
CreateTimer(5.0Timer_ChangeHSOnly_TIMER_REPEAT);
}

public 
Action Timer_ChangeHSOnly(Handle timer)
{
PrintToServer("Test every 5 seconds");
g_hhsonly.SetBool(true);

return 
Plugin_Continue;


also post https://forums.alliedmods.net/forumdisplay.php?f=107 here next time
__________________

Last edited by 8guawong; 01-27-2018 at 12:16.
8guawong is offline
Pankrakles
New Member
Join Date: Jan 2018
Old 01-27-2018 , 12:26   Re: Help creating a plugin
Reply With Quote #3

Quote:
Originally Posted by 8guawong View Post
you are mixing old syntax with new syntax

following should be all in new syntax


also post https://forums.alliedmods.net/forumdisplay.php?f=107 here next time
Oh thanks, for this post should I just wait for a moderator to move it to the correct place?

What would the best way to toggle the convar between true/false, also I get this error when trying to compile what you sent
PHP Code:
error 105cannot find method or property Handle.SetBool 

Last edited by Pankrakles; 01-27-2018 at 12:33.
Pankrakles is offline
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 01-27-2018 , 13:06   Re: Help creating a plugin
Reply With Quote #4

Handle g_hhsonly;

should be

ConVar g_hhsonly;

edit:
Quote:
Originally Posted by Pankrakles View Post
What would the best way to toggle the convar between true/false
PHP Code:
public Action Timer_ChangeHSOnly(Handle timer)
{
    
PrintToServer("Test every 5 seconds");

    if (
g_hhsonly.BoolValue)
        
g_hhsonly.SetBool(false);
    else 
g_hhsonly.SetBool(true);

    return 
Plugin_Continue;


__________________
coding & free software

Last edited by shanapu; 01-27-2018 at 13:13.
shanapu is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 01-27-2018 , 14:17   Re: Help creating a plugin
Reply With Quote #5

Quote:
Originally Posted by shanapu View Post
PHP Code:
public Action Timer_ChangeHSOnly(Handle timer)
{
    
PrintToServer("Test every 5 seconds");

    if (
g_hhsonly.BoolValue)
        
g_hhsonly.SetBool(false);
    else 
g_hhsonly.SetBool(true);

    return 
Plugin_Continue;


or
PHP Code:
public Action Timer_ChangeHSOnly(Handle timer

    
PrintToServer("Test every 5 seconds");

    
g_hhsonly.SetBool(!g_hhsonly.BoolValue);

    return 
Plugin_Continue


Last edited by headline; 01-27-2018 at 14:19.
headline is offline
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 01-27-2018 , 18:31   Re: Help creating a plugin
Reply With Quote #6

smart!
__________________
coding & free software
shanapu is offline
Reply



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 15:58.


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