AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Server crash with loop (https://forums.alliedmods.net/showthread.php?t=184901)

jasondoyle 05-10-2012 08:33

Server crash with loop
 
Hi, I've been working on a plug-in for a while now and it is all working except one crucial element.

The plug-in itself shows a menu to each user as spawn for the first time, they can choose to let the server change some of their client settings or disconnect from the server.

The problem is after the plug-in changes the settings(If they agree) they can change it back themselves using the console. At the moment the only compromise that I can do is change the settings during every freezetime, but if they want to they can change it back and play the round with the incorrect setting.

I tried using a "while" loop and the server crashed. Is there a way to preform a constant check without crashing the server, or lock the command in some way so they cannot change it.

PHP Code:

public Interp(id){
    new 
y=1;
    while ((
is_user_alive(id))){
        if(
== 1){
            
client_cmd(id"ex_interp ^"0.01^"0.01");
            
client_print(idprint_chat"Your ex_interp has been changed to 0.01");
        }
    }
    return 
PLUGIN_HANDLED;


Any ideas?



(If this is considered slow hacking then delete the post, I was under the impression its not slow hacking if they are told and agreed to it.
)

Pattinho 05-10-2012 08:48

Re: Server crash with loop
 
Why do you use a while loop ? Because if you just wanna ask one person with it, it makes no sense.

jasondoyle 05-10-2012 08:59

Re: Server crash with loop
 
Quote:

Originally Posted by Pattinho (Post 1706128)
Why do you use a while loop ? Because if you just wanna ask one person with it, it makes no sense.

Well the idea is to keep each players ex_interp set to 0.01. If a player is on the server they have agreed to be monitored.

Would it work better if I tried a "for" loop?

Diegorkable 05-10-2012 09:04

Re: Server crash with loop
 
Quote:

Originally Posted by jasondoyle (Post 1706131)
Well the idea is to keep each players ex_interp set to 0.01. If a player is on the server they have agreed to be monitored.

Would it work better if I tried a "for" loop?

It's better if you register a forward. think that each loop is occuring at every possible milisecond (I dont really know the times but it's very fast), so this is killing the server's CPU, making it crash. A forward will be called with a delay. Try to find the right forward to call that and make sure that if player agreed that his settings will be saved, it will be kept in a boolean array (true:agreed, false:did not agree).

Pattinho 05-10-2012 09:07

Re: Server crash with loop
 
ye that would be much better something like that.

PHP Code:

public Interp(){
    new 
maxplayers get_maxplayers();
    for(new 
id 1id <= maxplayersid++){
         if(
is_user_alive(id)){
                if(
agreed[id]  == true){
                     
client_cmd(id"ex_interp 0.01")
                     
client_print(id,print_chat,"Your ex_interp has been changed to 0.01")
                }
         }
    }
    return 
PLUGIN_HANDLED;


agreed is a bool array and in it you have to put the result of the question

jasondoyle 05-10-2012 09:11

Re: Server crash with loop
 
Quote:

Originally Posted by Diegorkable (Post 1706134)
It's better if you register a forward. think that each loop is occuring at every possible milisecond (I dont really know the times but it's very fast), so this is killing the server's CPU, making it crash. A forward will be called with a delay. Try to find the right forward to call that and make sure that if player agreed that his settings will be saved, it will be kept in a boolean array (true:agreed, false:did not agree).

I tried to user a "for" loop and it almost works, it is only changing the command when the trigger an event(spawn, take damage etc).

PHP Code:

public ClientCommands(id){
    new 
y;
    if(
is_user_alive(id)){ 
        
y=1;
        }else{
        
y=0;
    }
    for (
y=1y==1y+-){
        
client_cmd(id"ex_interp ^"0.01^"0.01");
        
client_print(idprint_chat"Your ex_interp has been changed to 0.01");
    }
    return 
PLUGIN_HANDLED;


I would like to try use a forword but I have no idea how, could you link me to a tutorial or anything?

Pattinho 05-10-2012 09:19

Re: Server crash with loop
 
So you want a plugin which turns the interp to 0.01 after they joined your server and agreed ?

jasondoyle 05-10-2012 09:31

Re: Server crash with loop
 
Hmm, I googled around abit and I'm still unsure as to how to register a forward, I found this method and it has worked.
PHP Code:

/* slowhacking code */ 


Exolent[jNr] 05-10-2012 09:35

Re: Server crash with loop
 
Use one of the existing Cvar Checkers on these forums that ask for client permission to change cvars or to kick them if they don't agree.

jasondoyle 05-10-2012 10:32

Re: Server crash with loop
 
Using the code in #8 everything works but it is lagging the server(constant choke etc). Any suggestions to solve this?


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

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