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

if model name...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
undead52
Senior Member
Join Date: Dec 2016
Old 06-07-2018 , 12:52   if model name...
Reply With Quote #1

my problem is it works for custom models too for different named.. i use custom models too and i need to check custom models. what could i do ?
PHP Code:
GetModelNameByIndex(GetClientViewModelIndex(client), ModelNamesizeof(ModelName))
if (
strcmp(ModelName,"*/weapons/v_snip_awp.mdl"))//i use v_test.mdl for awp model for example still get it v_snip_awp.mdl
    
{
        
PrintToChatAll("TEST")
        return 
Plugin_Stop
    
}

edit:it works for all weapons, how can i check what model does he using ? can somebody show me ?

Last edited by undead52; 06-07-2018 at 16:14.
undead52 is offline
akcaliberg
Senior Member
Join Date: Nov 2011
Location: Istanbul
Old 06-08-2018 , 20:09   Re: if model name...
Reply With Quote #2

strcmp() returns 0 for equal strings. So the condition will always be true unless the ModelName equals "*/weapons/v_snip_awp.mdl".

You should change it like this:

PHP Code:
if (strcmp(ModelName,"*/weapons/v_snip_awp.mdl") == 0)
{
    
PrintToChatAll("TEST")
    return 
Plugin_Stop

or just use StrEqual() function: https://sm.alliedmods.net/new-api/string/StrEqual

PHP Code:
if (StrEqual(ModelName,"*/weapons/v_snip_awp.mdl"))
{
    
PrintToChatAll("TEST")
    return 
Plugin_Stop

akcaliberg is offline
undead52
Senior Member
Join Date: Dec 2016
Old 06-09-2018 , 20:29   Re: if model name...
Reply With Quote #3

is there any problem there, my friend sent me that code for learn viewmodel name. the problem is condition always false.

also when try this shows empty
PHP Code:
GetModelNameByIndex(GetClientViewModelIndex(client), ModelNamesizeof(ModelName))
PrintToChatAll("TEST %s"ModelName
PHP Code:
int GetClientViewModelIndex(int client)
{
    
int viewmodel GetEntPropEnt(clientProp_Send"m_hViewModel")
    if(
viewmodel != -1)
        return 
GetEntProp(viewmodelProp_Send"m_nModelIndex")
    return 
0
}

bool GetModelNameByIndex(int idxchar[] sBufferint size)
{
    static 
int _tableIndex
    
if(!_tableIndex)
        
_tableIndex FindStringTable("modelprecache")
    if(
GetStringTableNumStrings(_tableIndex) >= idx)
        return 
false
    ReadStringTable
(_tableIndexidxsBuffersize)
    return 
true


Last edited by undead52; 06-09-2018 at 20:42.
undead52 is offline
akcaliberg
Senior Member
Join Date: Nov 2011
Location: Istanbul
Old 06-12-2018 , 04:15   Re: if model name...
Reply With Quote #4

There is a logic error in the code here:

PHP Code:
if(GetStringTableNumStrings(_tableIndex) >= idx
GetStringTableNumStrings(_tableIndex) will return the number of models in the modelprecache table. So it will always be a larger value than the model indices. What you should be checking is the exact opposite.

Change it like this:

PHP Code:
if(GetStringTableNumStrings(_tableIndex) <= idx
akcaliberg 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 14:43.


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