AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Zombie Plague: Redux [rewrite version] (https://forums.alliedmods.net/showthread.php?t=338016)

happy_2012 05-31-2022 11:21

Zombie Plague: Redux [rewrite version]
 
Hello,

I am rewriting the original Zombie Plague 5.0.8a from scratch, with some changes in the code, and I am stuck with a problem that I am almost 100% sure I have done everything right, and I just can't seem to find what's wrong with the code that it bugs like that!

Latest source code is on both main and development branches:
- Main: https://github.com/theycallmeyuzdi/z...edux/tree/main
- Development: https://github.com/theycallmeyuzdi/z...ee/development
- Resource files: https://downloads.rvrealm.com/game-s...-resources.zip

The problem is basically as follows:
- When someone becomes the first zombie in an infection game mode, if they were killed, they spawn as zombie the next round although it has been reset
- When the first zombie infects other humans, the same problem will occur for them the next round, unless they terminate all humans
- When there are two players in the server, the one that is already zombie will stay as zombie, and the other player may turn into a zombie, no one can kill the other and the round won't end, and on the next round the two players will be zombies

Maybe a more experienced coder can help out? What's the problem? What did I do wrong? How to fix it?

zXCaptainXz 05-31-2022 12:03

Re: Zombie Plague: Redux [rewrite version]
 
Hi, I would be happy to help but there's 3 problems with your request:
1. You're rewriting an (almost) perfectly fine version of ZP, any reason why you're doing that?
2. There are many sketchy parts in your code, I won't bother pointing them out if you don't give a good reason why you're re-writing ZP in the first place.
3. You should attach your resources (models/sounds/sprites) so we can test the plugin out at least...

happy_2012 05-31-2022 12:24

Re: Zombie Plague: Redux [rewrite version]
 
Rewriting reasons:
1. Better and more extended API
2. Fixing bugs present in the original mode
3. Giving the plugin API and subplugins more customizability
4. Trying to make zombie classes and human classes more customizable by removing or adding necessary stuff to make it less unified and more diverse instead

Sketchy parts? Buggy parts? Just point them out, or your messages and replies are no good here! That's the whole reason I am posting a "Scripting Help", also if you don't like my "rewrite" version, then do not use it, simple!

Resource files: https://downloads.rvrealm.com/game-s...-resources.zip

zXCaptainXz 05-31-2022 14:39

Re: Zombie Plague: Redux [rewrite version]
 
PHP Code:

public zp_fw_core_cure_posti_Client /* , i_Attacker, i_Force */ )
{
    if( !
is_user_valid_alivei_Client ) )
    {
        return;
    }


You should not check if the user is alive in any of your plugins when calling the cure/infect forwards. Remove that check and it will solve your problem.
I didn't plan to use your version in the first place, I'm just trying to save you some time because I believe ZP 5.0.8a is perfect as it is (99% of the time). I will point out some mistakes you are making throughout your plugins though.

Ham spawn should be registered as post
PHP Code:

    RegisterHamHam_Spawn"player""fwHamSpawnPost"truetrue ); 

You should check if the user is alive, not connected in Ham_Spawn, or it will throw nefarious results

PHP Code:

public fwHamSpawnPosti_Client )
{
    if(
is_user_alive(i_Client)
    
bitsum_setg_bIsAlivei_Client );


Ham_Killed should be registered as Post
PHP Code:

RegisterHamHam_Killed"player""fwHamKilledPost"truetrue ); 

You should not check if the player is connected/alive in Ham_Killed
PHP Code:


public fwHamKilledPosti_Victimi_Attacker )
{
    
bitsum_delg_bIsAlivei_Victim );


Now in zp_game_mode_infection, apart of the fact that you are using pre not post for ham_killed
PHP Code:

public fwHamKilledPrei_Victim /* , i_Attacker */ )
{
    if( 
g_iGMPlayer == i_Victim )
    {
        
g_iGMPlayer ftGetRandomAliverandom_num1ftGetCountAlive( ) ) );
    }


This code does literally nothing, only a bunch of useless calculations.

I doubt this is all that's wrong in there, you should avoid unnecessary checks and look up how to do things the proper way, or things will be prone to fail. If you don't know where to look, then ZP50 source code is a great place to start.

happy_2012 05-31-2022 16:45

Re: Zombie Plague: Redux [rewrite version]
 
Thank you so very much, pointing out my mistakes taught me better coding and fixed the bug!

Updated the code on GitHub!


All times are GMT -4. The time now is 21:21.

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