Raised This Month: $89 Target: $400
 22% 

[KeyValues] All Messages sent in same moment


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SpirT
Member
Join Date: Sep 2018
Location: PT FixingMyGF(int time)
Old 07-17-2019 , 12:57   [KeyValues] All Messages sent in same moment
Reply With Quote #1

Hey!

Today i decided to improve my experience with SourcPawn by starting to do KeyValues. So, to test it out, i tried to do a "Advertisements SpirT's version" hahahha.

The problem is that it sends all the messages on the file. So I have this.

KeyValues Config File:
Code:
"SomeAds"
{
	"1"
	{
		"message" "{blue}This is the first message"
	}
	"2"
	{
		"message" "{red}This is the second message"
	}
}
SP file:
PHP Code:
#pragma semicolon 1

#define DEBUG

char file[512];

#define PLUGIN_AUTHOR "SpirT"
#define PLUGIN_VERSION "1.0"

#include <sourcemod>
#include <sdktools>
#include <colors>

#pragma newdecls required

public Plugin myinfo 
{
    
name "[Ads] SpirT",
    
author PLUGIN_AUTHOR,
    
description "",
    
version PLUGIN_VERSION,
    
url ""
};

public 
void GetKeyValuesFile()
{
    
BuildPath(Path_SMfilesizeof(file), "configs/SomeAds.cfg");
}

public 
void OnMapStart()
{
    
CreateTimer(10.0Timer_DisplayAds_TIMER_REPEAT);
}

public 
Action Timer_DisplayAds(Handle timerHandle hndl)
{
    
SendAds();
}

public 
void SendAds()
{
    
GetKeyValuesFile();
    
    
KeyValues kv = new KeyValues("SomeAds");
    
kv.ImportFromFile(file);
    
    
//Vamos para a primeira SubSection
    
if (!kv.GotoFirstSubKey())
    {
        
delete kv;
    }
    
    do
    {
        
char Ad[512];
        
kv.GetString("message"Adsizeof(Ad));
        
        
CPrintToChatAll(Ad);
        
    } while (
kv.GotoNextKey());
    
    
delete kv;
    
    if(!
kv.GotoNextKey())
    {
        
kv.GotoFirstSubKey();
    }

Is there any way to just send only a message for every 10 seconds?

Regards,

SpirT.
__________________

Last edited by SpirT; 07-22-2019 at 11:20. Reason: it is not solved yet
SpirT is offline
Ilusion9
Senior Member
Join Date: Jun 2018
Location: Romania
Old 07-17-2019 , 13:07   Re: [KeyValues] All Messages sent in same moment
Reply With Quote #2

You save the messages in an ArrayList and show the current index (you start from 0 on OnMapStart).
__________________
Ilusion9 is online now
I am inevitable
Member
Join Date: May 2019
Location: 0xA6DA34
Old 07-17-2019 , 13:32   Re: [KeyValues] All Messages sent in same moment
Reply With Quote #3

PHP Code:
#pragma semicolon 1

#define DEBUG

char file[512];

int g_iAd;

#define PLUGIN_AUTHOR "SpirT"
#define PLUGIN_VERSION "1.0"

#include <sourcemod>
#include <sdktools>
#include <colors>

#pragma newdecls required

public Plugin myinfo 
{
    
name "[Ads] SpirT",
    
author PLUGIN_AUTHOR,
    
description "",
    
version PLUGIN_VERSION,
    
url ""
};

public 
void GetKeyValuesFile()
{
    
BuildPath(Path_SMfilesizeof(file), "configs/SomeAds.cfg");
}

public 
void OnMapStart()
{
    
CreateTimer(10.0Timer_DisplayAds_TIMER_REPEAT);
}

public 
Action Timer_DisplayAds(Handle timerHandle hndl)
{
    
g_iAd++;
    
    
SendAds();
}

void SendAds()
{
    
KeyValues kv = new KeyValues("SomeAds");
    
    
kv.ImportFromFile(file);
    
    if (!
kv.JumpToKey(g_iAd))
        
g_iAd 0;
    
    else
    {
        
char Ad[256];
        
        
kv.GetString("message"Adsizeof(Ad));
        
        
CPrintToChatAll(Ad);
    }
    
    
delete kv;

__________________
I do make plugins upon requests, so hit me up on discord if you're interested: cucklord67xD#3823

Last edited by I am inevitable; 07-17-2019 at 13:34.
I am inevitable is offline
SpirT
Member
Join Date: Sep 2018
Location: PT FixingMyGF(int time)
Old 07-18-2019 , 05:45   Re: [KeyValues] All Messages sent in same moment
Reply With Quote #4

Quote:
Originally Posted by I am inevitable View Post
PHP Code:
#pragma semicolon 1

#define DEBUG

char file[512];

int g_iAd;

#define PLUGIN_AUTHOR "SpirT"
#define PLUGIN_VERSION "1.0"

#include <sourcemod>
#include <sdktools>
#include <colors>

#pragma newdecls required

public Plugin myinfo 
{
    
name "[Ads] SpirT",
    
author PLUGIN_AUTHOR,
    
description "",
    
version PLUGIN_VERSION,
    
url ""
};

public 
void GetKeyValuesFile()
{
    
BuildPath(Path_SMfilesizeof(file), "configs/SomeAds.cfg");
}

public 
void OnMapStart()
{
    
CreateTimer(10.0Timer_DisplayAds_TIMER_REPEAT);
}

public 
Action Timer_DisplayAds(Handle timerHandle hndl)
{
    
g_iAd++;
    
    
SendAds();
}

void SendAds()
{
    
KeyValues kv = new KeyValues("SomeAds");
    
    
kv.ImportFromFile(file);
    
    if (!
kv.JumpToKey(g_iAd))
        
g_iAd 0;
    
    else
    {
        
char Ad[256];
        
        
kv.GetString("message"Adsizeof(Ad));
        
        
CPrintToChatAll(Ad);
    }
    
    
delete kv;


Hey. Thanks for your reply. I wake up now and my mind is not ok for now. I'm not understanding what that the int g_iAd. What is that int doing?

EDIT: Hey, now, that my brain is ok, i now understand what was the int doing. Thanks for your help!

Regards,

SpirT.
__________________

Last edited by SpirT; 07-18-2019 at 10:27.
SpirT is offline
SpirT
Member
Join Date: Sep 2018
Location: PT FixingMyGF(int time)
Old 07-22-2019 , 11:20   Re: [KeyValues] All Messages sent in same moment
Reply With Quote #5

Quote:
Originally Posted by I am inevitable View Post
PHP Code:
#pragma semicolon 1

#define DEBUG

char file[512];

int g_iAd;

#define PLUGIN_AUTHOR "SpirT"
#define PLUGIN_VERSION "1.0"

#include <sourcemod>
#include <sdktools>
#include <colors>

#pragma newdecls required

public Plugin myinfo 
{
    
name "[Ads] SpirT",
    
author PLUGIN_AUTHOR,
    
description "",
    
version PLUGIN_VERSION,
    
url ""
};

public 
void GetKeyValuesFile()
{
    
BuildPath(Path_SMfilesizeof(file), "configs/SomeAds.cfg");
}

public 
void OnMapStart()
{
    
CreateTimer(10.0Timer_DisplayAds_TIMER_REPEAT);
}

public 
Action Timer_DisplayAds(Handle timerHandle hndl)
{
    
g_iAd++;
    
    
SendAds();
}

void SendAds()
{
    
KeyValues kv = new KeyValues("SomeAds");
    
    
kv.ImportFromFile(file);
    
    if (!
kv.JumpToKey(g_iAd))
        
g_iAd 0;
    
    else
    {
        
char Ad[256];
        
        
kv.GetString("message"Adsizeof(Ad));
        
        
CPrintToChatAll(Ad);
    }
    
    
delete kv;

Hey again! Seems that our work is not done yet!

When I try to compile it says (I tried even by copying and pasting the full code you sent):

Code:
if (!kv.JumpToKey(g_iAd)) -> Error 035: argument type mismatch (argument 2)
I already tried to if (!kv.JumpToKey(g_iAd, false)) but it does not work. By Sourcemod API, false means that it would not create a key with that name.

What's the fix?

Regards,

SpirT.
__________________
SpirT is offline
I am inevitable
Member
Join Date: May 2019
Location: 0xA6DA34
Old 07-22-2019 , 15:32   Re: [KeyValues] All Messages sent in same moment
Reply With Quote #6

yeah, my bad.

it's expecting a string, not an int
__________________
I do make plugins upon requests, so hit me up on discord if you're interested: cucklord67xD#3823
I am inevitable is offline
SpirT
Member
Join Date: Sep 2018
Location: PT FixingMyGF(int time)
Old 07-22-2019 , 16:26   Re: [KeyValues] All Messages sent in same moment
Reply With Quote #7

Quote:
Originally Posted by I am inevitable View Post
yeah, my bad.

it's expecting a string, not an int
~

Does this might work correctly?:

PHP Code:
int g_iAd;
...

char IntValue[64];
IntToString(g_iAdIntValuesizeof(IntValue));

if(!
kv.JumpToKey(IntValue))

... 
//other part of the code 
Regards,

SpirT.
__________________

Last edited by SpirT; 07-22-2019 at 16:27.
SpirT is offline
I am inevitable
Member
Join Date: May 2019
Location: 0xA6DA34
Old 07-22-2019 , 16:55   Re: [KeyValues] All Messages sent in same moment
Reply With Quote #8

Quote:
Originally Posted by SpirT View Post
~

Does this might work correctly?:

PHP Code:
int g_iAd;
...

char IntValue[64];
IntToString(g_iAdIntValuesizeof(IntValue));

if(!
kv.JumpToKey(IntValue))

... 
//other part of the code 
Regards,

SpirT.
that'll do just fine
__________________
I do make plugins upon requests, so hit me up on discord if you're interested: cucklord67xD#3823
I am inevitable 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 10:21.


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