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

What do these codes do?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GlobalPlague
Senior Member
Join Date: Feb 2016
Location: Pluto
Old 06-01-2023 , 16:24   What do these codes do?
Reply With Quote #1

The codes i will show in this thread are codes meant to be used as mods in the source code of ZP, not to be compiled as separated plugins.

The codes are supposed to add a function that will make the radius around the center of the explosion of the infection grenade to be infective for X seconds, infecting humans who go inside this radius. Is this what the codes actually do, or are the codes just generalized codes that aren't specialized and are dysfunctional (not working)?

Here are the two codes:

Code:
new const Float:INFECTION_RADIUS = 200.0; // Adjust the radius as needed

public plugin_init()
{
    register_event("DeathMsg", "event_death", "b");
}

public event_death(victim, attacker, weapon)
{
    if (get_user_team(attacker) == CS_TEAM_ZOMBIE && weapon == ZP_WEAPON_INFECTION_GRENADE)
    {
        create_harmful_cloud(get_user_origin(attacker), INFECTION_RADIUS);
        infect_nearby_players(get_user_origin(attacker), INFECTION_RADIUS);
    }
    return PLUGIN_CONTINUE;
}

public create_harmful_cloud(position[], radius)
{
    new entity = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"));
    engfunc(EngFunc_SetOrigin, entity, position);
    engfunc(EngFunc_SetModel, entity, "sprites/green_cloud.spr"); // Replace with the path to your green cloud sprite file
    engfunc(EngFunc_SetSize, entity, Vector(-radius, -radius, -radius), Vector(radius, radius, radius));
    engfunc(EngFunc_SetRenderColor, entity, 0, 255, 0); // Adjust the color as desired
    
    set_task(10.0, "remove_harmful_cloud", entity); // Remove the cloud after 10 seconds
}

public remove_harmful_cloud(entity)
{
    engfunc(EngFunc_RemoveEntity, entity);
}

public infect_nearby_players(position[], radius)
{
    new Float:origin[3], distance;

    for (new i = 1; i <= get_max_players(); i++)
    {
        if (!is_user_connected(i) || get_user_team(i) != CS_TEAM_TERRORIST)
            continue;
        
        get_user_origin(i, origin);
        distance = get_distance(position, origin);
        
        if (distance <= radius)
        {
            set_user_team(i, CS_TEAM_ZOMBIE, true); // Infect the player
            set_user_godmode(i, true); // Make the infected player invulnerable temporarily
            set_task(10.0, "reset_godmode", i); // Reset the godmode after 10 seconds
        }
    }
}

public reset_godmode(player)
{
    set_user_godmode(player, false); // Reset godmode
}
Here is the second code:

Code:
new const Float:INFECTION_RADIUS = 200.0; // Adjust the radius as needed

public plugin_init()
{
    register_event("DeathMsg", "event_death", "b");
}

public event_death(victim, attacker, weapon)
{
    if (get_user_team(attacker) == CS_TEAM_ZOMBIE && weapon == ZP_WEAPON_INFECTION_GRENADE)
    {
        infect_nearby_players(get_user_origin(attacker), INFECTION_RADIUS);
        set_task(10.0, "reset_infected_players");
    }
    return PLUGIN_CONTINUE;
}

public infect_nearby_players(position[], radius)
{
    new Float:origin[3], distance;

    for (new i = 1; i <= get_max_players(); i++)
    {
        if (!is_user_connected(i) || get_user_team(i) != CS_TEAM_TERRORIST)
            continue;
        
        get_user_origin(i, origin);
        distance = get_distance(position, origin);
        
        if (distance <= radius)
        {
            set_user_team(i, CS_TEAM_ZOMBIE, true); // Infect the player
            set_user_godmode(i, true); // Make the infected player invulnerable temporarily
            set_task(10.0, "reset_godmode", i); // Reset the godmode after 10 seconds
        }
    }
}

public reset_godmode(player)
{
    set_user_godmode(player, false); // Reset godmode
}

public reset_infected_players()
{
    for (new i = 1; i <= get_max_players(); i++)
    {
        if (!is_user_connected(i) || get_user_team(i) != CS_TEAM_ZOMBIE)
            continue;
        
        set_user_team(i, CS_TEAM_TERRORIST, true); // Reset infected players to human team
    }
}

Last edited by GlobalPlague; 06-01-2023 at 16:25.
GlobalPlague is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 06-02-2023 , 09:05   Re: What do these codes do?
Reply With Quote #2

i never made a plugin for zombie plague, i will just give an opinion of what i see

expecting the infection grenade plugin is calling death event on user from a certain area, first plugin it's looking like it's checking if it's killed with the infection grenade (as far as i know, there are some native in zp like zp_user_infected_post/pre and you shouldn't use death event to check if player is infected).

the infection area of the grenade is made around attacker origin, not the origin of the bomb

take a look of how the author is creating the "harmful cloud". he's using attacker origin.

Code:
public event_death(victim, attacker, weapon) {     if (get_user_team(attacker) == CS_TEAM_ZOMBIE && weapon == ZP_WEAPON_INFECTION_GRENADE)     {
        create_harmful_cloud(get_user_origin(attacker), INFECTION_RADIUS);
        infect_nearby_players(get_user_origin(attacker), INFECTION_RADIUS);     }     return PLUGIN_CONTINUE; }

Code:
native get_user_origin(index, origin[3], mode = 0) /** * Retrieves an origin related to the client. * * @note For a list of possible modes see the Origin_* constants in amxconst.inc. *
* @param index     Client index
* @param origin    Array to store origin in * @param mode      What type of origin to retrieve: *                    Origin_Client - current position *                    Origin_Eyes - position of eyes (and weapon) *                    Origin_AimEndClient - aim end position from client position *                    Origin_AimEndEyes - aim end position from eyes (hit point for weapon) *                    Origin_CS_LastBullet - position of last bullet hit (only for Counter-Strike) * * @return          1 on success, 0 if client is not connected * @error           If the client index is not within the range of 1 to *                  MaxClients, an error will be thrown. */

also, the infection event for players of the area created by this plugin is made only one time, function infect_nearby_players should be in a task of 1s of 0.5s.

after typing the above text, i'm thinking that you want to check the experience of someone in making plugins, is this right?

because the plugin it's not looking like someone with a good experience made it. in death event it's checking if team of the infected player is CS_TEAM_ZOMBIE and in infect_nearby_players it's checking if it's CS_TEAM_TERRORIST, so he's using different constants for same thing and this doesn't make sense (at least for me)

the second plugin is so wrong that i think someone changed the code only to break it, it's infecting players around the zombie that used infection grenade and after 10 second it's "reseting infected players"

Code:
public reset_infected_players() // idk what this should reset, look below
{     for (new i = 1; i <= get_max_players(); i++)     {         @@if (!is_user_connected(i) || get_user_team(i) != CS_TEAM_ZOMBIE) // it's checking if the player is zombie             continue;                 set_user_team(i, CS_TEAM_TERRORIST, true); // Reset infected players to human team -> BUT it's setting user team to cs_team_terrorist that (as far as i know) should be zombie team     } }


so, after this, my opinion is that these codes have been changed by someone who wanted to break the plugin or want to fool someone to buy them trying to make a plugin. it's looking like he know what he's doing, but he's not

Last edited by lexzor; 06-02-2023 at 10:05.
lexzor is offline
GlobalPlague
Senior Member
Join Date: Feb 2016
Location: Pluto
Old 06-07-2023 , 15:25   Re: What do these codes do?
Reply With Quote #3

Quote:
Originally Posted by lexzor View Post
after typing the above text, i'm thinking that you want to check the experience of someone in making plugins, is this right?

because the plugin it's not looking like someone with a good experience made it.
Ok, you caught me... I used ChatGPT to try to generate a ZP plugin that creates an invisible infection around the point of explosion of the infection grenade. My goal was to have a plugin that creates the invisible infective radius around the point, so i can add a .spr file (greenish cloud) that spawns at the explosion and spreads in a radius, so all humans can be infected once they go within the radius. The cloud and the invisible infector have to last for X seconds.

Ok, it seems that ChatGPT can't make working plugin, so i will try to do it by myself...
GlobalPlague is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-07-2023 , 23:36   Re: What do these codes do?
Reply With Quote #4

ChatGPT is not to be trusted and don't try to use it as a crutch, it will likely make things worse for you learning anything correctly.
__________________
fysiks 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 01:40.


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