AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Function Crashing (https://forums.alliedmods.net/showthread.php?t=47840)

The Specialist 11-27-2006 19:04

Function Crashing
 
Ok. I have this almost working correctly. It brings up m menu blocks my use button . And I think It un-blocks it the way i want. But when it cmes to either the explosion or the removing the bomb it crashes. And theres no errors in my logs. Any ideas ? Thank You.

Code:
  #include <amxmodx> #include <fakemeta> #define TE_EXPLOSION 3 new keys = MENU_KEY_0|MENU_KEY_1|MENU_KEY_2|MENU_KEY_3; new g_Switch; new i; new Sprite; public plugin_init() {  register_plugin("Cut The Right Wire","0.1","The Speicialist");  g_Switch = register_cvar("ctrw_switch","1");  register_menucmd(register_menuid("menu_show"),1023,"menu_choose");  register_logevent("bomb_defuse_no_kit", 3, "2=Begin_Bomb_Defuse_Without_Kit");  register_logevent("bomb_defuse_no_kit", 3, "2=Begin_Bomb_Defuse_With_Kit");  register_forward(FM_PlayerPreThink,"block_buttons"); } // detect defusing public bomb_defuse_no_kit() {  new id = get_loguser_index();    if(get_pcvar_num(g_Switch)==0)  {   return 0;  }else{   new menu[192];   format(menu,191,"Choose The Right Wire Or Die!^n1. Red^n2. Blue^n3. Green^n^n0. Die");   show_menu(id,keys,menu,-1,"menu_show");   ++i;   return PLUGIN_CONTINUE;  }  return PLUGIN_CONTINUE; } // remove use button and show menu public menu_choose(id,key) {  new const Time = get_cvar_num("mp_c4timer");  new wire = random(2);  switch(key)  {   case 0 :   {    if( wire == 0 )    {     --i     set_cvar_num("mp_c4timer",(Time + 10));     return PLUGIN_HANDLED;    }else{     bomb_explosion();     return PLUGIN_HANDLED;    }   }   case 1:   {    if( wire == 1)    {     --i     set_cvar_num("mp_c4timer",(Time + 10 ));     return PLUGIN_HANDLED;    }else{     bomb_explosion();     return PLUGIN_HANDLED;    }   }   case 2 :   {    if( wire == 2 )    {     --i     set_cvar_num("mp_c4timer",(Time + 10 ));     return PLUGIN_HANDLED;    }else{     bomb_explosion();     return PLUGIN_HANDLED;    }   }  }  set_cvar_num("mp_c4timer",Time);  return PLUGIN_HANDLED; } // block the users use button public block_buttons(id) {  if( i == 0 )  {   return FMRES_HANDLED;  }else{   set_pev( id, pev_button, pev(id,pev_button) & ~IN_USE);  }  return PLUGIN_HANDLED; } //bomb explosion public bomb_explosion() {  new Bomb = fm_find_ent_by_model(-1,"grenade","models/c4.mdl");  new Location = pev(Bomb, pev_origin);  message_begin(MSG_BROADCAST,SVC_TEMPENTITY)  write_byte(TE_EXPLOSION)  write_coord(Location)  write_coord(Location)  write_coord(Location)  write_short(Sprite)  write_byte(1)  write_byte(0)  write_byte(0)  message_end()  engfunc(EngFunc_RemoveEntity, Bomb); } // function to get index from log events public get_loguser_index() {  new loguser[80], name[32];  read_logargv(0, loguser, 79);  parse_loguser(loguser, name, 31);  return get_user_index(name); } // finding entity by model public  fm_find_ent_by_model(index, const classname[], const model[]) {  new ent = index, mdl[72];  while ((ent = engfunc(EngFunc_FindEntityByString, index, "classname", classname)))  {   pev(ent, pev_model, mdl, 71);   if (equal(mdl, model))   {    return ent;   }  }  return 0 } //precache sprites for exloasion public plugin_precache() {  Sprite = precache_model("sprites/zerogxplode.spr"); }

Zenith77 11-27-2006 21:05

Re: Function Crashing
 
Check to make sure you found a valid entity in bomb_explosion(). A simple check such as:

Code:
if (!myent) {      // Code... }

or

Code:
if (!pev_valid(myent))      return;

The Specialist 11-27-2006 21:47

Re: Function Crashing
 
Thanks For the help Zenith . Is this the right way to use pev_valid ??
Code:
#include <amxmodx> #include <fakemeta> #define TE_EXPLOSION 3 new keys = MENU_KEY_0|MENU_KEY_1|MENU_KEY_2|MENU_KEY_3; new g_Switch; new i; new Sprite; public plugin_init() {  register_plugin("Cut The Right Wire","0.1","The Speicialist");  g_Switch = register_cvar("ctrw_switch","1");  register_menucmd(register_menuid("menu_show"),1023,"menu_choose");  register_logevent("bomb_defuse_no_kit", 3, "2=Begin_Bomb_Defuse_Without_Kit");  register_logevent("bomb_defuse_no_kit", 3, "2=Begin_Bomb_Defuse_With_Kit");  register_forward(FM_PlayerPreThink,"block_buttons"); } // detect defusing public bomb_defuse_no_kit() {  new id = get_loguser_index();    if(get_pcvar_num(g_Switch)==0)  {   return 1;  }else{   new menu[192];   format(menu,191,"Choose The Right Wire Or Die!^n1. Red^n2. Blue^n3. Green^n^n0. Die");   show_menu(id,keys,menu,-1,"menu_show");   ++i;   return 0;  }  return 0; } // remove use button and show menu public menu_choose(id,key) {  new const Time = get_cvar_num("mp_c4timer");  new wire = random(2);  switch(key)  {   case 0 :   {    if( wire == 0 )    {     --i     set_cvar_num("mp_c4timer",(Time + 10));     return 1;    }else{     bomb_explosion();     return 1;    }   }   case 1:   {    if( wire == 1)    {     --i     set_cvar_num("mp_c4timer",(Time + 10 ));     return 1;    }else{     bomb_explosion();     return 1    }   }   case 2 :   {    if( wire == 2 )    {     --i     set_cvar_num("mp_c4timer",(Time + 10 ));     return 1;    }else{     bomb_explosion();     return 1;    }   }  }  set_cvar_num("mp_c4timer",Time);  return 1; } // block the users use button public block_buttons(id) {  if( i == 0 )  {   return 1;  }else{   set_pev( id, pev_button, pev(id,pev_button) & ~IN_USE);  }  return 1; } //bomb explosion public bomb_explosion() {  new Bomb = fm_find_ent_by_model(-1,"grenade","models/c4.mdl");  new Location = pev(Bomb, pev_origin);  if( pev_valid(Bomb))  {   message_begin(MSG_BROADCAST,SVC_TEMPENTITY);   write_byte(TE_EXPLOSION);   write_coord(Location);   write_coord(Location);   write_coord(Location);   write_short(Sprite);   write_byte(1);   write_byte(0);   write_byte(0);   message_end();   engfunc(EngFunc_RemoveEntity, Bomb);   return 0;  }  return 1; } // function to get index from log events public get_loguser_index() {  new loguser[80], name[32];  read_logargv(0, loguser, 79);  parse_loguser(loguser, name, 31);  return get_user_index(name); } // finding entity by model public  fm_find_ent_by_model(index, const classname[], const model[]) {  new ent = index, mdl[72];  while ((ent = engfunc(EngFunc_FindEntityByString, index, "classname", classname)))  {   pev(ent, pev_model, mdl, 71);   if (equal(mdl, model))   {    return ent;   }  }  return 0; } //precache sprites for exloasion public plugin_precache() {  Sprite = precache_model("sprites/zerogxplode.spr"); }

If so then it didnt work becasue it still crashed my server . Its only crashing during explosion/bomb removal stll . :cry:

jim_yang 11-28-2006 00:28

Re: Function Crashing
 
Code:
new Float:Location[3] pev(Bomb,pev_origin,Location)   engfunc(EngFunc_WriteCoord,Location[0]) engfunc(EngFunc_WriteCoord,Location[1]) engfunc(EngFunc_WriteCoord,Location[2])

The Specialist 11-28-2006 08:00

Re: Function Crashing
 
hmmm. That crashed too. Is there something wrong with the way I removed the bomb ? Or my find entity by model function ?:cry:

Orangutanz 11-28-2006 08:21

Re: Function Crashing
 
Code:
new Float:Location[3] pev(Bomb, pev_origin, Location); if( pev_valid(Bomb)) {   message_begin(MSG_BROADCAST,SVC_TEMPENTITY);   write_byte(TE_EXPLOSION);   write_coord(floatround(Location[0]));   write_coord(floatround(Location[1]));   write_coord(floatround(Location[2]));   write_short(Sprite);   write_byte(1);   write_byte(0);   write_byte(0);   message_end();   engfunc(EngFunc_RemoveEntity, Bomb);   return 0; }

The Specialist 11-28-2006 09:35

Re: Function Crashing
 
Ok i got it to stop crashing . But now the probem seems to be that my function bomb_explosion is not being executed. Or maybee the first statement is and then its canceled. It doesnt explode or remove the bomb . But it doesnt crash. So why isnt it executing the second statement in my exlosion_function ?
Code:
#include <amxmodx> #include <fakemeta_util> #define TE_EXPLOSION 3 new keys = MENU_KEY_0|MENU_KEY_1|MENU_KEY_2|MENU_KEY_3; new g_Switch; new i; new Sprite; new Float:  Location[3]; public plugin_init() {  register_plugin("Cut The Right Wire","0.1","The Speicialist");  g_Switch = register_cvar("ctrw_switch","1");  register_menucmd(register_menuid("menu_show"),1023,"menu_choose");  register_logevent("bomb_defuse_no_kit", 3, "2=Begin_Bomb_Defuse_Without_Kit");  register_logevent("bomb_defuse_no_kit", 3, "2=Begin_Bomb_Defuse_With_Kit");  register_forward(FM_PlayerPreThink,"block_buttons"); } // detect defusing public bomb_defuse_no_kit() {  new id = get_loguser_index();    if(get_pcvar_num(g_Switch)==0)  {   return 1;  }else{   new menu[192];   format(menu,191,"Choose The Right Wire Or Die!^n1. Red^n2. Blue^n3. Green^n^n0. Die");   show_menu(id,keys,menu,-1,"menu_show");   ++i;   return 0;  }  return 0; } // remove use button and show menu public menu_choose(id,key) {  new wire = random(2);  switch(key)  {   case 0 :   {    if( wire == 0 )    {     --i;     return 1;    }else{     bomb_explosion();     return 1;    }   }   case 1:   {    if( wire == 1)    {     --i;     return 1;    }else{     bomb_explosion();     return 1    }   }   case 2 :   {    if( wire == 2 )    {     --i;     return 1;    }else{     bomb_explosion();     return 1;    }   }  }  return 1; } // block the users use button public block_buttons(id) {  if( i == 0 )  {   return 1;  }else{   set_pev( id, pev_button, pev(id,pev_button) & ~IN_USE);  }  return 1; } //bomb explosion public bomb_explosion() {  new Bomb = fm_find_ent_by_model(-1,"grenade","models/c4.mdl");  pev(Bomb, pev_origin,Location);  if( !pev_valid(Bomb))  {   return 1;  }else{   message_begin(MSG_BROADCAST,SVC_TEMPENTITY);   write_byte(TE_EXPLOSION);   write_coord(floatround(Location[0]));   write_coord(floatround(Location[1]));   write_coord(floatround(Location[2]));   write_short(Sprite);   write_byte(1);   write_byte(0);   write_byte(0);   message_end();   engfunc(EngFunc_RemoveEntity, Bomb);   i = 0;   return 1;  }  return 1; } // function to get index from log events public get_loguser_index() {  new loguser[80], name[32];  read_logargv(0, loguser, 79);  parse_loguser(loguser, name, 31);  return get_user_index(name); } //precache sprites for exloasion public plugin_precache() {  Sprite = precache_model("sprites/zerogxplode.spr"); }

Zenith77 11-28-2006 12:00

Re: Function Crashing
 
Some suggestions, put your pev_valid() check before you get the origin, and use EngFunc_WriteCoord as suggested before.

The Specialist 11-28-2006 14:14

Re: Function Crashing
 
Ok. I remved the pev_valid() and now my explosion works. apprenatly my bomb entity wasnt valid. So i wont check it . now how can I make the explosion as big as the c4 explosion and make it do damage ??? And its still not removing the bomb :cry: thanks again .

Zenith77 11-28-2006 17:09

Re: Function Crashing
 
This can easily found out with the following.
  1. Use a logging tool to catch the TE_EXPLOSION message, or it could also be another message and see what size CS puts for it.
  2. Look at other plugins and use their damage code to simulate the bomb. Or, this will take some investigative work, figure out how the bomb knows when to explode. It could be set off by thinking (unlikely because it beeps), or by storing a value in it's pev feild and decrement it.


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

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