View Single Post
Lux
Veteran Member
Join Date: Jan 2015
Location: Cat
Old 07-22-2019 , 23:29   Re: [L4D] L4DNoSmoking (v1.0.1, 2019-07-21)
Reply With Quote #8

It is a good idea to use new syntax, if you wish to use new add this directive
PHP Code:
#pragma newdecls required 
will bust your ass and not compile as it forces you to use new syntax.



Below i thought i would show you a better way of writing it removing what you don't need from how i understand your code, this could just break your whole thing.

PHP Code:
public void tongue_grab(Event event, const char[] namebool dontBroadcast)// don't need action since you are not changing the event
{
    
int victim GetClientOfUserId(GetEventInt(event"victim"));
    if(!
IS_VALID_SURVIVOR(victim))
        return;
    
    
int id GetClientOfUserId(GetEventInt(event"userid"));

    if (
IS_INFECTED_ALIVE(id))
    {
        for (
int i 1<= MaxClientsi++) 
        { 
            if (
IS_VALID_SURVIVOR(i) && != victim)// ignore the survivor getting smoked
            
{
                if(!
IsPlayerAlive(i))
                {
                    continue;
                }
                
                if (
l4dver == 1)
                {
                    if (
IsClientIncapacitatedl4d1(i) == false)
                    {
                        return;
                    }
                }
                else
                {
                    if (
IsClientIncapacitatedl4d2(i) == false)
                    {
                        return;
// no need to do anything if a survivor is up and about and no need to continue looping
                    
}
                }
                
            }
        }
        
        switch(
GetConVarInt(cvar_killorslap))// just get the val when you need
        
{
            case 
1:
            
PerformKill(idGetConVarInt(cvar_displaykillmessage));
            
            case 
2:
            
PerformSlap(idGetConVarInt(cvar_displaykillmessage));
        }    
    }
    return;
}

void PerformKill(int idint displaykillmessage)// 1 less param and does the same thing
{
    
ForcePlayerSuicide(id);
    switch (
displaykillmessage)
    {
        case 
1:
        
PrintCenterTextAll("[SM] %N was socked for smoking last."id);// don't need to pass clientname %N does it for you when formatting Prints
        
        
case 2:
        
PrintHintTextToAll("[SM] %N was socked for smoking last."id);
        
        case 
3:
        
PrintToChatAll("\x01\x04[SM] \x03%N \x01was socked for smoking last."id);
    }
}

void PerformSlap(int idint displaykillmessage)
{
    
float vpos[3];
    
GetEntPropVector(idProp_Data"m_vecOrigin"vpos);
    
vpos[2] += 30.0// just use the same array you created do what you wish no need for creating 2
    
    
TeleportEntity(idvposNULL_VECTORNULL_VECTOR);    
    switch (
displaykillmessage)
    {
        case 
1:
        
PrintCenterTextAll("[SM] %N was slapped for smoking last."id);
        
        case 
2:
        
PrintHintTextToAll("[SM] %N was slapped for smoking last."id);
        
        case 
3:
        
PrintToChatAll("\x01\x04[SM] \x03%N \x01was slapped for smoking last."id);
    }

Since you are using a switch for your different cvar options it's a good idea to clamp the cvar if someone were to set killorslap = 3 nothing would happen.
PHP Code:
cvar_killorslap CreateConVar("killorslap""1""1 kill smoker or 2 slap smoker"CVAR_FLAGStrue1.0true2.0); 
With the new syntax you have classes or methods whichever you call them this is nothing to think about now but you can write code faster with them here a small example instead of nesting functions.

PHP Code:
int id GetClientOfUserId(GetEventInt(event"userid"));
int id event.GetInt("userid")); 
Does require you to use the event tag thingy
e.g "Event event"
PHP Code:
public void tongue_grab(Event event, const char[] namebool dontBroadcast
Spoiler
__________________
Connect
My Plugins: KlickME
[My GitHub]

Commission me for L4D

Last edited by Lux; 07-22-2019 at 23:35.
Lux is offline