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

New API and Syntax


Post New Thread Reply   
 
Thread Tools Display Modes
404UserNotFound
BANNED
Join Date: Dec 2011
Old 06-12-2017 , 16:47   Re: New API and Syntax
Reply With Quote #891

Quote:
Originally Posted by Fyren View Post
Data is automatically initialized to zero anyway unless you use decl.
Ah, so I should be using decl if I'm initializing an integer/float/what-have-you with a value other than 0/null? decl was one of those things in old syntax that I was confused about and never used.

Last edited by 404UserNotFound; 06-12-2017 at 16:48.
404UserNotFound is offline
nergal
Veteran Member
Join Date: Apr 2012
Old 06-12-2017 , 16:56   Re: New API and Syntax
Reply With Quote #892

Quote:
Originally Posted by 404UserNotFound View Post
Ah, so I should be using decl if I'm initializing an integer/float/what-have-you with a value other than 0/null? decl was one of those things in old syntax that I was confused about and never used.
decl doesn't work in new syntax so you don't really need to worry about it.
__________________
nergal is offline
404UserNotFound
BANNED
Join Date: Dec 2011
Old 06-12-2017 , 18:24   Re: New API and Syntax
Reply With Quote #893

Quote:
Originally Posted by nergal View Post
decl doesn't work in new syntax so you don't really need to worry about it.
Ohhhh. I learn something new every day
404UserNotFound is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 01-06-2018 , 01:09   Re: New API and Syntax
Reply With Quote #894

How would one write this bool under new syntax?

PHP Code:
new bool:MyTestBool[100]; 
__________________
Spirit_12 is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 01-06-2018 , 01:13   Re: New API and Syntax
Reply With Quote #895

Quote:
Originally Posted by Spirit_12 View Post
How would one write this bool under new syntax?

PHP Code:
new bool:MyTestBool[100]; 
PHP Code:
bool MyTestBool[100]; 
headline is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 01-06-2018 , 01:21   Re: New API and Syntax
Reply With Quote #896

Quote:
Originally Posted by Spirit_12 View Post
How would one write this bool under new syntax?

PHP Code:
new bool:MyTestBool[100]; 
https://wiki.alliedmods.net/SourcePa...itional_Syntax

bool MyTestBool[100];

OR

bool[] MyTestBool = new bool[SIZE_OF_ARRAY]

The difference between the two is documented in the "Arrays" section of the wiki page I linked to. Since you've explicitly indicated the exact size of the array within the code, then in this case you'd use the former.

EDIT: I should learn to refresh before I post a reply to a thread I opened up ten minutes prior...
__________________

Last edited by ddhoward; 01-06-2018 at 01:24.
ddhoward is offline
kot4404
Senior Member
Join Date: Mar 2013
Old 01-13-2018 , 04:38   Re: New API and Syntax
Reply With Quote #897

Quote:
stock bool HasIdlePlayer(int bot)
{
new userid = GetEntData(bot, FindSendPropInfo("SurvivorBot", "m_humanSpectatorUserID"));
new client = GetClientOfUserId(userid);

if(client)
{
// Do not count bots
// Do not count 3rd person view players
if(IsClientInGame(client) && !IsFakeClient(client) && (GetClientTeam(client)!=2))
return true;
}
return false;
}
How can I fix the
Quote:
new userid = GetEntData(bot, FindSendPropInfo("SurvivorBot", "m_humanSpectatorUserID"));
new client = GetClientOfUserId(userid);
?
kot4404 is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 01-13-2018 , 07:07   Re: New API and Syntax
Reply With Quote #898

Quote:
Originally Posted by kot4404 View Post
How can I fix the
?
PHP Code:
int client GetClientOfUserId(GetEventInt(event"userid")); 
Or if you're using this: https://sm.alliedmods.net/new-api/events/Event/GetInt

Use this:
PHP Code:
int client GetClientOfUserId(event.GetInt("userid")); 


Not sure if this even works:
PHP Code:
stock bool bIsPlayerIdle(int client)
{
    if (
GetEntProp(clientProp_Data"m_humanSpectatorUserID"1))
    {
        return 
true;
    }

    return 
false;

__________________
Psyk0tik is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 01-13-2018 , 15:03   Re: New API and Syntax
Reply With Quote #899

Actually, both of those variables are integers. You would simply want to replace new with int.

PHP Code:
new userid GetEntData(botFindSendPropInfo("SurvivorBot""m_humanSpectatorUserID"));
new 
client GetClientOfUserId(userid); 
^ Becomes

PHP Code:
int userid GetClientOfUserId(event.GetInt("userid"));
int client GetClientOfUserId(userid); 
__________________
Spirit_12 is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 01-17-2018 , 01:04   Re: New API and Syntax
Reply With Quote #900

I use this check to exclude idle players from seeing vote menus:

PHP Code:
bool bIsPlayerIdle(int client)
{
    if (
GetClientTeam(client) != 1)
    {
        return 
false;
    }

    for (
int iPlayer 1iPlayer <= MaxClientsiPlayer++)
    {
        if (
bIsSurvivor(iPlayer) && IsFakeClient(iPlayer))
        {
            if (
GetClientOfUserId(GetEntProp(iPlayerProp_Send"m_humanSpectatorUserID")) == client)
            return 
true;
        }
    }

    return 
false;

Seems to work for me.
__________________

Last edited by Psyk0tik; 01-17-2018 at 03:12.
Psyk0tik 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:49.


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