AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   need help understanding this. (https://forums.alliedmods.net/showthread.php?t=63135)

FiVeTeNMontrail 11-12-2007 21:59

need help understanding this.
 
i am trying to make a pluging so when you kill yourself like 4 times in one round, the server kicks you. It works but im trying to make it so when a new round starts, it resets everything. That is what im having trouble with. Which event would i use for a new round? I wasn't sure so i made it call 3 differen't events.. but when a new round starts, nothing is printed on the screen like i wanted it to. Any clue?

Code:

#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <core>
new attacker
new Float:countup[32]
new Float:countupleft[32]
public plugin_init()
{
 register_plugin("Anti-Death Kicker","1.0","FiVeTeN")
 register_event("Damage","tally","b")
 register_event("EndRound","endRound","a")
 register_event("RoundStat","roundStat","a")
 register_event("RndRes","roundRes","a")
}
public tally(id)
{
 attacker=get_user_attacker(id)
 if(is_user_alive(id)==0)
 {
  if(attacker>32)
  {
  countup[id]=countup[id]+1
  if(countup[id]==2)
  {
  client_print(id,print_chat,"[AMXX] Careful! You have 4 suicides left.",countupleft[id]);
  }
  else if(countup[id]==4)
  {
  client_print(id,print_chat,"[AMXX] Careful! You have 3 suicides left.",countupleft[id]);
  }
  else if(countup[id]==6)
  {
  client_print(id,print_chat,"[AMXX] Careful! You have 2 suicides left.",countupleft[id]);
  }
  else if(countup[id]==8)
  {
  client_print(id,print_chat,"[AMXX] Careful! You have 1 suicides left.",countupleft[id]);
  }
 }
 if(attacker==id)
 {
  countup[id]=countup[id]+1
  if(countup[id]==2){
  client_print(id,print_chat,"[AMXX] Careful! You have 4 suicides left.",countupleft[id]);
  }else if(countup[id]==4){
  client_print(id,print_chat,"[AMXX] Careful! You have 3 suicides left.",countupleft[id]);
  }else if(countup[id]==6){
  client_print(id,print_chat,"[AMXX] Careful! You have 2 suicides left.",countupleft[id]);
  }else if(countup[id]==8){
  client_print(id,print_chat,"[AMXX] Careful! You have 1 suicides left.",countupleft[id]);
  }
 }
 
 
 if(countup[id]>9)
 {
  new userid = get_user_userid(id)  ;
  server_cmd("banid 10 #%d kick",userid);
  countup[id]=0.0;
  countupleft[id]=0.0;
 }
 }
 return PLUGIN_HANDLED
}
public endRound()
{
 client_print(0,print_chat,"Round Ended");
 return PLUGIN_HANDLED
}
public roundStat()
{
 client_print(0,print_chat,"Round Status");
 return PLUGIN_HANDLED
}
public roundRes()
{
 client_print(0,print_chat,"Round RES?");
 return PLUGIN_HANDLED
}


Arkshine 11-12-2007 23:03

Re: need help understanding this.
 
I would do something like :

Code:
    #include <amxmodx>         #define MAX_CLIENTS 32     #define MAX_SUICIDE 10         new g_iSuicideCnt[ MAX_CLIENTS + 1 ] = { MAX_SUICIDE, ... };         public plugin_init()     {         register_plugin( "Anti-Death Kicker", "1.0", "FiVeTeN" );                 register_event( "DeathMsg", "onDeath", "a" );                                // Suicide         register_event( "TextMsg" , "eResetCount", "a", "2=#Game_will_restart_in" ); // Restart attempt         register_event( "HLTV"    , "eResetCount", "a", "1=0", "2=0" );              // New round     }         public onDeath()     {         new iKiller = read_data( 1 );         new iVictim = read_data( 2 );                 static sWeapon[6];         read_data( 4, sWeapon, sizeof sWeapon - 1 );                 if( iKiller == iVictim && equal( sWeapon, "world", 5 ) )         {             --g_iSuicideCnt[ iVictim ];                         if( !g_iSuicideCnt[ iVictim ] )                 server_cmd( "kick #%d Your message here", get_user_userid( iVictim ) );                         client_print( iVictim, print_chat, "[AMXX] Careful! You have %d suicide%s left.", g_iSuicideCnt[ iVictim ], g_iSuicideCnt[ iVictim ] < 2 ? "" : "s" );         }     }         public eResetCount()         arrayset( g_iSuicideCnt, MAX_SUICIDE, sizeof g_iSuicideCnt );         public client_disconnect( id )           g_iSuicideCnt[id] = MAX_SUICIDE;

FiVeTeNMontrail 11-13-2007 06:43

Re: need help understanding this.
 
Alright im not the best with coding so can you explain this?

What is this new iKiller = read_data( 1 );
i have never seen read_data.

This i also don't get

static sWeapon[6];
read_data( 4, sWeapon, sizeof sWeapon - 1 );

what does the read_data do on that part.

M249-M4A1 11-13-2007 07:36

Re: need help understanding this.
 
read_data reads the data returned by the message DeathMsg. read_data(1) will return the killer, and read_data(2) is the id of who died

Basically read_data does as it says
For more information:
http://www.amxmodx.org/funcwiki.php?go=func&id=132

Arkshine 11-13-2007 14:24

Re: need help understanding this.
 
Sorry I'm not good with explanations. -_-

Also DeathMsg event is called when a player is dead : http://wiki.alliedmods.net/Half-Life...vents#DeathMsg

FiVeTeNMontrail 11-13-2007 21:12

Re: need help understanding this.
 
The code does not work for some reason i changed this to see if the onDeath function is even called... and it doesn't seem like it is.


public onDeath()
{
client_print( 0, print_chat, "Testing yo");
new iKiller = read_data( 1 );
new iVictim = read_data( 2 );
static sWeapon[6];

It never prints out testing yo when anyone dies. so idk why this isn't working.

M249-M4A1 11-13-2007 21:28

Re: need help understanding this.
 
You need to hook the actual DeathMsg. Put this in your plugin_init()

PHP Code:

register_event"DeathMsg""onDeath""a" 


FiVeTeNMontrail 11-13-2007 21:59

Re: need help understanding this.
 
I already have that, i was just posting part of the code.

Code:

#include <amxmodx>
   
    #define MAX_CLIENTS 32
    #define MAX_SUICIDE 4
   
    new g_iSuicideCnt[ MAX_CLIENTS + 1 ] = { MAX_SUICIDE, ... };
   
    public plugin_init()
    {
        register_plugin( "Anti-Death Kicker", "1.0", "FiVeTeN" );
       
        register_event( "DeathMsg", "onDeath", "a" );                                // Suicide
        register_event( "TextMsg" , "eResetCount", "a", "2=#Game_will_restart_in" ); // Restart attempt
        register_event( "HLTV"    , "eResetCount", "a", "1=0", "2=0" );              // New round
    }
   
    public onDeath()
    {
 client_print( 0, print_chat, "Testing yo");
        new iKiller = read_data( 1 );
        new iVictim = read_data( 2 );
        static sWeapon[6];
        read_data( 4, sWeapon, sizeof sWeapon - 1 );
       
        if( iKiller == iVictim && equal( sWeapon, "world", 5 ))
        {
            --g_iSuicideCnt[ iVictim ];
           
            if( !g_iSuicideCnt[ iVictim ] )
                server_cmd( "kick #%d Your message here", get_user_userid( iVictim ) );
           
            client_print( iVictim, print_chat, "[AMXX] Careful! You have %d suicide%s left.", g_iSuicideCnt[ iVictim ], g_iSuicideCnt[ iVictim ] < 2 ? "" : "s" );
        }
    }
   
    public eResetCount()
        arrayset( g_iSuicideCnt, MAX_SUICIDE, sizeof g_iSuicideCnt );
   
    public client_disconnect( id ) 
        g_iSuicideCnt[id] = MAX_SUICIDE;


alien 11-13-2007 22:29

Re: need help understanding this.
 
It's working for me, mate ...
Make sure you have latest .amxx file in your plugins directory and server restarted.

FiVeTeNMontrail 11-13-2007 22:42

Re: need help understanding this.
 
Do you think it could be because im using this plugin for a mod called zombie panic?


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

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