Raised This Month: $ Target: $400
 0% 

When I try to test the plugin, it crashes the game


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Itz
Junior Member
Join Date: Apr 2021
Old 05-25-2021 , 07:37   Re: When I try to test the plugin, it crashes the game
Reply With Quote #5

Quote:
Originally Posted by fysiks View Post
One of the most important skills in programming is debugging. In this case, find out what code is executing when the plugin crashes the server. Comment out that code and see if it's still causing the crash. This will tell you what code is causing the issue.

However, there is a major issue in your code. All of your while loops are very likely causing infinite or near infinite loops. What you've implemented is a non-deterministic loop meaning that it's not guaranteed to execute in a predictable manner.

Also, using a random number based on the number of alive players as your "id" is wrong. To get a valid id of an alive player, you'd need to use something like get_players() and then index that array to get a valid id.
I realized that the error is when I add a new class to the plugin

PHP Code:
#include <zp50_class_knifer> 
PHP Code:
 cvar_nightmare_kni_hp_multi
cvar_nightmare_kni_hp_multi 
register_cvar("zp_nightmare_knife_hp_multi""0.25"
I believe the error is in that part
PHP Code:
//new knife_count = floatround(alive_count * 0.25, floatround_ceil)
new knife_count survivor_count

// Turn specified amount of players into Knifer
    
new iKnifeiMaxKnife knife_count
    
while (iKnife iMaxKnife)
    {
        
// Choose random guy
        
id GetRandomAlive(random_num(1alive_count))
        
        
// Already a survivor or nemesis?
        
if (zp_class_survivor_get(id) || zp_class_nemesis_get(id) || zp_class_sniper_get(id) || zp_class_knifer_get(id))
            continue;
        
        
// If not, turn him into one
        
zp_class_knifer_set(id)
        
iKnife++
        
        
// Apply Knife health multiplier
        
set_user_health(idfloatround(get_user_health(id) * get_pcvar_float(cvar_nightmare_kni_hp_multi)))
    } 
Without the class add the plugin works perfectly

Last edited by Itz; 05-25-2021 at 07:38.
Itz is offline
 



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 02:35.


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