Page 1 of 1

[HELP] Complicated script for cod4

Posted: June 18th, 2011, 8:19 pm
by XeloX
so what i want is a script that works using my GUID and allows me to post messages to the whole server.
This is the script that i have so far but it does not read the clientdvar value. Works only in localhost mode :(

Code: Select all

    onPlayerConnect()
    {
       for(;;)
       {
          level waittill("connected", player);
          player thread onPlayerSpawned();
       }
    }
         
    onPlayerSpawned()
    {
       for(;;)
       {
          self waittill("spawned_player");
          if(self getGuid() == "--------------------")//Guid Here!
          {
             self thread check_dvars();
             self thread xelox();
          }
       }
    }
     
    check_dvars()
    {
            while(1)
            {
                    if( getDvar( "mapsay" ) != "" )
                            thread _mapsay();
                    wait ( ( 0.05 / 20 ) * getDvarInt( "sv_fps" ) );
            }
    }
     
     
    _mapsay()
    {
            msg = getDvar( "mapsay" );
            setDvar( "mapsay", "" );
                    players = getentarray("player", "classname");
            for(i = 0; i < players.size; i++)      
                    players[i] playLocalSound( "bullet_impact_headshot_2" );       
            iPrintLnBold( msg );
    }
 
So yes, can anybody help me? I cant seem to get it to work for the life if me. And yes i did load the dvar in the main section.

Re: [HELP] Complicated script for cod4

Posted: June 18th, 2011, 9:16 pm
by Drofder2004
1. Are you testing locally or on a dedi-server?
2. What is and what is not working? (Sound/Msg)
3. Are there any errors?
4. Place some debug prints.

Re: [HELP] Complicated script for cod4

Posted: June 18th, 2011, 11:13 pm
by IzNoGoD
XeloX wrote:so what i want is a script that works using my GUID and allows me to post messages to the whole server.
This is the script that i have so far but it does not read the clientdvar value. Works only in localhost mode :(

    onPlayerConnect()
    {
       for(;;)
       {
          level waittill("connected", player);
          player thread onPlayerSpawned();
       }
    }
         
    onPlayerSpawned()
    {
self endon("disconnect"); //add this line to make sure this stops if the player disconnects
//also: try to check guid on connect, and only run this thread if the guid is correct
//because guids cannot change while a player is on the server

       for(;;)
       {
          self waittill("spawned_player");
          if(self getGuid() == "--------------------")//Guid Here!
          {
             self thread check_dvars();
             self thread xelox();
          }
       }
    }
     
    check_dvars()
    {
self endon("disconnect"); //added this to prevent this thread from running after the player disconnects
self endon("spawned_player"); //added this to avoid duplicate threads (cod2 rcon spec bug double save/load msgs anyone? :P)

            while(1)
            {
                    if( getDvar( "mapsay" ) != "" ) //you cannot get a client cvar/dvar. Just check serversided. No need to check guids too then...
                            thread _mapsay();
                    wait ( ( 0.05 / 20 ) * getDvarInt( "sv_fps" ) ); //whats this shit? Just use either 0.05 or 1/getdvarint("sv_fps")
            }
    }
     
     
    _mapsay()
    {
            msg = getDvar( "mapsay" ); ///again, you CAN NOT get client's dvars. Just check a serversided dvar. No need for guids
            setDvar( "mapsay", "" );
                    players = getentarray("player", "classname");
            for(i = 0; i < players.size; i++)      
                    players playLocalSound( "bullet_impact_headshot_2" );      
            iPrintLnBold( msg );
    }
So yes, can anybody help me? I cant seem to get it to work for the life if me. And yes i did load the dvar in the main section.


Edit: removed ]code] tags to avoid disappearing of the colors :(

Re: [HELP] Complicated script for cod4

Posted: June 18th, 2011, 11:22 pm
by Drofder2004
Failed to read text, didn't realise you were trying to send messages as a client and using DVARs.

The only way to do this is through menus or rcon.

Re: [HELP] Complicated script for cod4

Posted: June 19th, 2011, 10:48 am
by XeloX
Damn ok, well i guess ill give up on that then ;)