AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Log Event Bomb Drop [SOLVED] (https://forums.alliedmods.net/showthread.php?t=47572)

The Specialist 11-21-2006 05:28

Log Event Bomb Drop [SOLVED]
 
Ok, I am adding an update to my "Follow The Bomb" plugin , a suggestion was made by K007 to add a punsihemnt for droppign the bomb. I used a log event to detect the bomb being dropped but theres no message or punsihing happening when i drop the bomb . any ideas whats wrong .
Code:
#include <amxmodx> #include <engine> #include <fun> #include <cstrike> // Global Variables new g_iFollow_Bomb; new g_iPunish; new  g_iRadius; new g_Mode[8]; new Float:c4origin[3]; new  Float:pOrigin[3]; new players[32], num, i; public plugin_init() {     register_plugin("Follow The Bomber","0.7","The Speicialist");     register_event("ResetHUD","reset_hud","be");     register_event("BarTime", "bomb_planting", "be", "1=3");     register_logevent("bomb_is_planted", 3, "2=Planted_The_Bomb");     register_logevent("bomb_is_dropped", 3, "2=Dropped_The_Bomb");     g_iFollow_Bomb = register_cvar("ftb_switch","1");     g_iPunish = register_cvar("ftb_punishment","a");     g_iRadius = register_cvar("ftb_radius","1000");     set_task(2.0,"find_bomb",0,"",0,"b"); } // reset hud event public reset_hud(id) {       // show message to follow the bomb terrorists         if( cs_get_user_team(id) == CS_TEAM_T  &&  find_ent_by_class(-1 , "weapon_c4"))     {         set_hudmessage(255, 255, 255, -1.0, 0.38, 0, 6.0, 12.0);         show_hudmessage(id, "Follow The Bomb");     } } // find bomb and players in and out of range public find_bomb(id) {     // find the bomb         new g_iBomb = find_ent_by_class(-1,"weapon_c4");         // if cvar is off OR if there is no bomb end function         if(get_pcvar_num(g_iFollow_Bomb)==0 || g_iBomb == 0)     {         return PLUGIN_HANDLED;     }else{              // find the origin of the bomb                 entity_get_vector(g_iBomb,EV_VEC_origin,c4origin);         // get all terrorists                 get_players(players,num,"ace","TERRORIST");         for(i=0;i<num;i++)         {             // find the origin of alive terrorists                         entity_get_vector(players[i],EV_VEC_origin,pOrigin);                         // get distance from alive t's to the bomb                         new Float:  g_Dist = get_distance_f(c4origin,pOrigin);                         new g_iDist = floatround(g_Dist);                         // show hud display of how far you are from the bomb                         set_hudmessage(255, 255, 255, -1.0, 0.79, 0, 6.0, 2.0);             show_hudmessage(id, "You Are %i Units From The Bomb",g_iDist);                         // if alive terrorists are out of range then punish             if( g_Dist > get_pcvar_num(g_iRadius))             {                 punish_mode(players[i]);             }         }     }     return PLUGIN_HANDLED; } // punishment function public punish_mode(players) {     // get string for cvars         get_pcvar_string(g_iPunish,g_Mode,7);         // read flags from string cvar         new g_iMode = read_flags(g_Mode);     new g_iArmor = get_user_armor(players);     new g_iMoney = cs_get_user_money(players);     new g_iHealth = get_user_health(players);         // dispaly hud messages for leaving bomb         set_hudmessage(255, 255, 255, -1.0, 0.34, 0, 6.0, 2.0);     show_hudmessage(players, "Your Leaving The Bomb");         // punish based on flags from cvar string         if(g_iMode  & 1 )  // flag a     {         // slap the user                   user_slap(players,0);     }     if(g_iMode  &  2 )  // flag b     {         // -1 armor from user                 set_user_armor(players,(g_iArmor - 1));     }     if(g_iMode  & 4 )  // flag c     {         // strip the weapons from that user                 strip_user_weapons(players);     }     if(g_iMode & 8 ) // flag d     {         // take away money from user                 cs_set_user_money(players,(g_iMoney - 10));     }     if(g_iMode & 16)  // flag e     {               // kill the user                 user_kill(players);     }           if(g_iMode  & 32 ) // flag f     {         // no punishment                 return PLUGIN_HANDLED;     }     if(g_iMode & 64) // flag g     {         // take 1 health from user                 set_user_health(players,(g_iHealth - 1));     }     return PLUGIN_HANDLED; } // bar time  event detects planting public bomb_planting(id) {     // get user who is planting the bomb     new i;     new g_Name[32];         get_user_name(id,g_Name,31);         // get alive terrorist         get_players(players,num,"ace","TERRORIST");         for(i = 0; i < num ; ++i)     {         // display message to alive terroist             set_hudmessage(255, 255, 255, -1.0, 0.35, 0, 6.0, 12.0);         show_hudmessage(id, "%s Is Planting The Bomb Cover Him!",g_Name);         return PLUGIN_HANDLED;     }     return PLUGIN_HANDLED; } // logevent cathces bomb is planted message public bomb_is_planted(id) {     // get alive terrorist         get_players(players,num,"ace","TERRORIST");         for(i = 0; i < num ; ++i)     {         // display message to alive terroist             set_hudmessage(255, 255, 255, -1.0, 0.34, 0, 6.0, 12.0);         show_hudmessage(id, "Bomb Is Planted Defend It !");         return PLUGIN_HANDLED;     }     return PLUGIN_HANDLED; } // detects if the bomb was dropped public bomb_is_dropped(players) {     if(get_pcvar_num(g_iFollow_Bomb)==1)     {         punish_mode(players);                       // display mssage to who ever dropped teh bomb                 set_hudmessage(255, 255, 255, -1.0, 0.34, 0, 6.0, 12.0);         show_hudmessage(players, "Pick The Bomb Back Up !");     } }

thank you for your help :up:

VEN 11-21-2006 06:32

Re: Log Event Bomb Drop
 
player id isn't passed to the logevent hook, you should get it from the name or the userid in the logmessage.

get_loguser_index function is here: http://forums.alliedmods.net/showthr...dex#post343295

The Specialist 11-21-2006 07:30

Re: Log Event Bomb Drop
 
:cry: now i got it to work but im getting a run time error for the drop_bomb function.
Code:

L 11/21/2006 - 07:31:31: Start of error session.
L 11/21/2006 - 07:31:31: Info (map "de_dust_cz") (logfile "error_112106.log")
L 11/21/2006 - 07:31:31: [CSTRIKE] Invalid player 2
L 11/21/2006 - 07:31:31: [AMXX] Displaying debug trace (plugin "follow_the_bomb.amxx")
L 11/21/2006 - 07:31:31: [AMXX] Run time error 10: native error (native "cs_get_user_money")
L 11/21/2006 - 07:31:31: [AMXX]    [0] follow_the_bomb.sma::punish_mode (line 139)
L 11/21/2006 - 07:31:31: [AMXX]    [1] follow_the_bomb.sma::bomb_is_dropped (line 244)

Heres my whole code now

Code:
#include <amxmodx> #include <engine> #include <fun> #include <cstrike> // Global Variables new g_iFollow_Bomb; new g_iPunish; new  g_iRadius; new g_Mode[8]; new Float:c4origin[3]; new  Float:pOrigin[3]; new players[32], num, i; public plugin_init() {     register_plugin("Follow The Bomber","0.7","The Speicialist");     register_event("ResetHUD","reset_hud","be");     register_event("BarTime", "bomb_planting", "be", "1=3");     register_logevent("bomb_is_planted", 3, "2=Planted_The_Bomb");     register_logevent("bomb_is_dropped", 3, "2=Dropped_The_Bomb");     register_logevent("bomb_defuse_no_kit", 3, "2=Begin_Bomb_Defuse_Without_Kit");     register_logevent("bomb_defuse_kit", 3, "2=Begin_Bomb_Defuse_With_Kit");     g_iFollow_Bomb = register_cvar("ftb_switch","1");     g_iPunish = register_cvar("ftb_punishment","a");     g_iRadius = register_cvar("ftb_radius","1000");     set_task(2.0,"find_bomb",0,"",0,"b"); } // reset hud event public reset_hud(id) {       // show message to follow the bomb terrorists         if( cs_get_user_team(id) == CS_TEAM_T  &&  find_ent_by_class(-1 , "weapon_c4"))     {         set_hudmessage(255, 255, 255, -1.0, 0.31, 0, 6.0, 12.0);         show_hudmessage(id, "Follow The Bomb Within %i Units^n Or Be Punished!",get_pcvar_num(g_iRadius));         return PLUGIN_HANDLED;     }     return PLUGIN_HANDLED; } // find bomb and players in and out of range public find_bomb(id) {     // find the bomb         new g_iBomb = find_ent_by_class(-1,"weapon_c4");         // if cvar is off OR if there is no bomb end function         if(get_pcvar_num(g_iFollow_Bomb)==0 || g_iBomb == 0)     {         return PLUGIN_HANDLED;     }else{              // find the origin of the bomb                 entity_get_vector(g_iBomb,EV_VEC_origin,c4origin);         // get all terrorists                 get_players(players,num,"ace","TERRORIST");         for(i=0;i<num;i++)         {             // find the origin of alive terrorists                         entity_get_vector(players[i],EV_VEC_origin,pOrigin);                         // get distance from alive t's to the bomb                         new Float:  g_Dist = get_distance_f(c4origin,pOrigin);                         new g_iDist = floatround(g_Dist);                         // show hud display of how far you are from the bomb                         set_hudmessage(255, 255, 255, -1.0, 0.79, 0, 6.0, 2.0);             show_hudmessage(id, "You Are %i Units From The Bomb",g_iDist);                         // if alive terrorists are out of range then punish             if( g_Dist > get_pcvar_num(g_iRadius))             {                 punish_mode(players[i]);             }         }     }     return PLUGIN_HANDLED; } // punishment function public punish_mode(players) {     // get string for cvars         get_pcvar_string(g_iPunish,g_Mode,7);         // read flags from string cvar         new g_iMode = read_flags(g_Mode);     new g_iArmor = get_user_armor(players);     new g_iMoney = cs_get_user_money(players);     new g_iHealth = get_user_health(players);         // dispaly hud messages for leaving bomb         set_hudmessage(255, 255, 255, -1.0, 0.34, 0, 6.0, 2.0);     show_hudmessage(players, "Your Leaving The Bomb");         // punish based on flags from cvar string         if(g_iMode  & 1 )  // flag a     {         // slap the user                   user_slap(players,0);     }     if(g_iMode  &  2 )  // flag b     {         // -1 armor from user                 set_user_armor(players,(g_iArmor - 1));     }     if(g_iMode  & 4 )  // flag c     {         // strip the weapons from that user                 strip_user_weapons(players);     }     if(g_iMode & 8 ) // flag d     {         // take away money from user                 cs_set_user_money(players,(g_iMoney - 10));     }     if(g_iMode & 16)  // flag e     {               // kill the user                 user_kill(players);     }           if(g_iMode  & 32 ) // flag f     {         // no punishment                 return PLUGIN_HANDLED;     }     if(g_iMode & 64) // flag g     {         // take 1 health from user                 set_user_health(players,(g_iHealth - 1));     }     return PLUGIN_HANDLED; } // bar time  event detects planting public bomb_planting(id) {     // get user who is planting the bomb     new i;     new g_Name[32];         get_user_name(id,g_Name,31);         // get alive terrorist         get_players(players,num,"ace","TERRORIST");         for(i = 0; i < num ; ++i)     {         // display message to alive terroist             set_hudmessage(255, 255, 255, -1.0, 0.35, 0, 6.0, 12.0);         show_hudmessage(id, "%s Is Planting The Bomb Cover Him!",g_Name);         return PLUGIN_HANDLED;     }     return PLUGIN_HANDLED; } // logevent cathces bomb is planted message public bomb_is_planted(id) {     // get alive terrorist         get_players(players,num,"ace","TERRORIST");         for(i = 0; i < num ; ++i)     {         // display message to alive terroist             set_hudmessage(255, 255, 255, -1.0, 0.34, 0, 6.0, 12.0);         show_hudmessage(id, "Bomb Is Planted Defend It !");         return PLUGIN_HANDLED;     }     return PLUGIN_HANDLED; } // detects if the bomb was dropped public bomb_is_dropped(players) {     new players = get_loguser_index();         punish_mode(players);           // display mssage to who ever dropped teh bomb     set_hudmessage(255, 255, 255, -1.0, 0.19, 0, 6.0, 12.0);     show_hudmessage(players, "Pick The Bomb Back Up!"); } // detects if the bomb is being defused with no kit public bomb_defuse_no_kit(id) {     // see who is defusing     new id  = get_loguser_index();         new g_Name[33];     get_user_name(id,g_Name,32);         get_players(players,num,"ace","CT");         // display message to all ct's alive         for(new i = 0 ; i < num ; ++i)     {         set_hudmessage(255, 255, 255, -1.0, 0.3, 0, 6.0, 12.0);         show_hudmessage(id, "%s Is Defusing The Bomb Wih No Kit ^n Cover Hiim!",g_Name);     }       } // detects if the bomb is being defused with a kit public bomb_defuse_kit(id) {     // see who is defusing     new id = get_loguser_index();         new g_Name[33];         get_user_name(id,g_Name,32);         get_players(players,num,"ace","CT");         // display message to all ct's alive         for(new i = 0 ; i < num ; ++i)     {         set_hudmessage(255, 255, 255, -1.0, 0.3, 0, 6.0, 12.0);         show_hudmessage(id, "%s Is Defusing The Bomb Wih A Kit ^n Cover Hiim!",g_Name);     }       } // function to get index from log events stock get_loguser_index() {     new loguser[80], name[32];         read_logargv(0, loguser, 79);     parse_loguser(loguser, name, 31);     return get_user_index(name); }

Thanks for the help

jim_yang 11-21-2006 08:55

Re: Log Event Bomb Drop
 
i suggest that you'd better not declare "i" as a global var.
declare it when you need it.

The Specialist 11-21-2006 21:32

Re: Log Event Bomb Drop
 
lol. wow that actaully worked . huh . thanks man u rock !:up: ++karma

Amxx-PluginCreator 11-21-2006 21:54

Re: Log Event Bomb Drop
 
Quote:

Originally Posted by jim_yang (Post 405594)
i suggest that you'd better not declare "i" as a global var.
declare it when you need it.

This is true, it might interup with other VARS.

[ --<-@ ] Black Rose 11-22-2006 06:18

Re: Log Event Bomb Drop [SOLVED]
 
show_hudmessage(id... probably should be show_hudmessage(players[i]... In all hud msgs..

The Specialist 11-22-2006 07:03

Re: Log Event Bomb Drop [SOLVED]
 
not neccesarily. Some of the hud messages are being displayed inside of log events. some arnt. log events dont have id's . therefore making them an exception to your rule. They have to be called by index found from there name parsed in the log. And some of the messages i didnt use get_players() .

[ --<-@ ] Black Rose 11-22-2006 07:15

Re: Log Event Bomb Drop [SOLVED]
 
public bomb_defuse_kit() <- remove "id", loop should be "players[i]"
bomb_defuse_no_kit(id) <- same as above
bomb_is_planted(id) <- same as above
find_bomb(id) <- same as above
bomb_planting(id) <- loop should be "players[i]"
bomb_is_dropped(players) <- remove "players"

The Specialist 11-22-2006 07:54

Re: Log Event Bomb Drop [SOLVED]
 
well it works exactly like it shuld the way i did it . so why change it ?


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

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