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

Solved Passing arguments to consolecmd, warning with enum and problem with decal


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hh2
AlliedModders Donor
Join Date: Sep 2010
Old 10-12-2016 , 15:00   Passing arguments to consolecmd, warning with enum and problem with decal
Reply With Quote #1

1. What is the best idea to passing arguments to consolecmd, example below:
PHP Code:
RegConsoleCmd("sm_test"Command_Test);
public 
Action Command_Test(int clientint args)
{
    
char arg[128];
    
GetCmdArg(1argsizeof(arg));
    
    
int value StringToInt(arg);
}
void test(client)
{
    
Command_Test(client1);  //how to pass custom value to function?

Is FakeClientCommand are only way to do it?

2. What causes this warning?
PHP Code:
enum Colors {
    
RED,
    
BLUE,
    
GREEN,
    
    
MAX_COLORS
}
int g_iSelectedColor[MAXPLAYERS 1];

void func(int client)
{
     
g_iSelectedColor[client]++;
     if ( 
g_iSelectedColor[client] >= MAX_COLORS )  //warning 213: tag mismatch
     
{
           
g_iSelectedColor[client] = 0;
     }

3. Code below gives me small black dot, instead of my texture. What is wrong? Textures are ok, because i copied it from other server.
PHP Code:
int g_iSprite = -1;

public 
void OnMapStart()
{
    
AddFileToDownloadsTable("materials/test.vtf");
    
AddFileToDownloadsTable("materials/test.vmt");
    
    
g_iSprite PrecacheDecal("materials/test"true);
}

void TE_SetupBSPDecal(float vecOrigin[3], int index
{
    
TE_Start("World Decal");
    
TE_WriteVector("m_vecOrigin"vecOrigin);
    
TE_WriteNum("m_nIndex"index);
}

void setup(float pos[3])
{    
    
TE_SetupBSPDecal(posg_iSprite);
    
TE_SendToAll();

Thanks for any help!

Last edited by hh2; 10-13-2016 at 14:41.
hh2 is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 10-12-2016 , 15:05   Re: Passing arguments to consolecmd, warning with enum and problem with decal
Reply With Quote #2

what is test.vtf and test.vmt, those seem like the issue and not the code.
Mitchell is offline
hh2
AlliedModders Donor
Join Date: Sep 2010
Old 10-12-2016 , 15:20   Re: Passing arguments to consolecmd, warning with enum and problem with decal
Reply With Quote #3

Quote:
Originally Posted by Mitchell View Post
what is test.vtf and test.vmt, those seem like the issue and not the code.
I have written that this is texture, which I copied from another server on which it works, so i dont think thats a problem. Path is a bit different, this is only example to show how i make it.

Last edited by hh2; 10-12-2016 at 15:20.
hh2 is offline
API
Veteran Member
Join Date: May 2006
Old 10-12-2016 , 15:25   Re: Passing arguments to consolecmd, warning with enum and problem with decal
Reply With Quote #4

BUILT-IN SOLUTION BUT LEAST PERFORMANT
I see, you want to call the callback manually. Instead just invoke the command with FakeClientCommand:
Code:
void test(client)
{
    FakeClientCommand("sm_test %d", client);
    // instead of:    Command_Test(client, 1);
}
So yeah, to answer your question, you are best off just using FakeClientCommand()... AFAIK there is no abstraction on this process. You could also do this instead:

PERFORMANT AND TESTABLE SOLUTION BUT SLIGHTLY MORE CODE
Code:
RegConsoleCmd("sm_test", Command_Test);
public Action Command_Test(int client, int args)
{
    char arg[128];
    GetCmdArg(1, arg, sizeof(arg));
    
    int value = StringToInt(arg);
    return Command_Test_Internal(client, value);
}

public Action Command_Test_Internal(int client, int firstArg)
{
   // do your thing
}
void test(client)
{
    int someValue = 1234;
    Command_Test_Internal(client, someValue);
}
I tend to do this a lot since I like being able to unit test my code.

TAG MISMATCH ISSUE
As for your question about the tag mismatch... here you go:
Code:
if ( view_as<Colors>(g_iSelectedColor[client]) >= MAX_COLORS )
you could also go this too:
Code:
if ( g_iSelectedColor[client] >= view_as<int>(MAX_COLORS) )
Casting with view_as is easy
__________________

Last edited by API; 10-12-2016 at 15:37.
API is offline
Send a message via AIM to API
hh2
AlliedModders Donor
Join Date: Sep 2010
Old 10-12-2016 , 16:28   Re: Passing arguments to consolecmd, warning with enum and problem with decal
Reply With Quote #5

Thank you pimpinjuice, nice solution with passing arguments
Still need help with decal problem.

Last edited by hh2; 10-12-2016 at 16:29.
hh2 is offline
API
Veteran Member
Join Date: May 2006
Old 10-12-2016 , 17:47   Re: Passing arguments to consolecmd, warning with enum and problem with decal
Reply With Quote #6

Dumb question, but have you tried PrecacheModel() instead of PrecacheDecal()? AFAIK, it used to be how I always pre-cached texture files. Also, make sure you include .vmt in the call to PrecacheModel()

eg:
GOOD
Code:
g_iSprite = PrecacheModel("materials/test.vmt", true);
BAD
Code:
g_iSprite = PrecacheModel("materials/test", true);
If that doesn't work, maybe try this?
Code:
g_iSprite = PrecacheDecal("materials/test.vmt", true);
__________________

Last edited by API; 10-12-2016 at 17:49.
API is offline
Send a message via AIM to API
API
Veteran Member
Join Date: May 2006
Old 10-12-2016 , 18:01   Re: Passing arguments to consolecmd, warning with enum and problem with decal
Reply With Quote #7

Oh, I think I just realized something. You say you copied the textures from another server, but you don't look like you are using the same paths If you open the VMT, you will notice the first line (or second, I don't remember) is a path to the VMF file. You must make sure this is correct.
__________________
API is offline
Send a message via AIM to API
hh2
AlliedModders Donor
Join Date: Sep 2010
Old 10-12-2016 , 18:57   Re: Passing arguments to consolecmd, warning with enum and problem with decal
Reply With Quote #8

pimpinjuice, thanks for your help.
Paths are same as original, so thats not it.

I solved this problem by deleting "materials" from path string and it works
hh2 is offline
API
Veteran Member
Join Date: May 2006
Old 10-12-2016 , 19:01   Re: Passing arguments to consolecmd, warning with enum and problem with decal
Reply With Quote #9

Awesome, happy to hear this was resolved.
__________________
API is offline
Send a message via AIM to API
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 11:24.


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