AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Fatal Error (https://forums.alliedmods.net/showthread.php?t=48983)

The Specialist 12-24-2006 20:32

Fatal Error
 
I get a fata error when I enter my server "no edicts available" , then I get a run time error ,"Invalid return type " . Heres my code with my inc file .

Code:
  #include <amxmodx> #include <amxmisc> #include <rail_gun> #define MAX_PLAYERS 32 #define MAX_AMMO_SLOTS 100 new g_Switch; new g_Price; new g_Money; new g_WeaponEnt; new g_AdminFree; new Float:g_Angle[3]; new Float:g_Origin[3]; new Float:g_MinBox[3] = {-1.0, -1.0, -1.0}; new Float:g_MaxBox[3] = {1.0, 1.0, 1.0}; new Float:global_Time; new Float: g_ROF = 0.5; new Float: g_NextAttack[32]; new g_Bullet; new g_AmmoPrice; new g_ArenaMode; new bool:g_restart_attempt[MAX_PLAYERS + 1]; new Class[32]; new Model[32]; new HitZones; new Float: EndOrigin[3]; new trace; new nomonsters; new Sprite; new Float: W_Origin[3]; new damage; new model = 0; new g_Ammo; public plugin_init() { register_plugin("The Rail Gun","0.1","The Specialist"); g_Switch = register_cvar("rg_switch","1"); g_Price = register_cvar("rg_gun_price","3000"); g_AdminFree = register_cvar("rg_admin_gun_free","1"); g_AmmoPrice = register_cvar("rg_ammo_price","500"); g_ArenaMode = register_cvar("rg_arena_on","0");   register_clcmd("say /buy_gun","buy_rail_gun"); register_clcmd("say_team /buy_gun","buy_rail_gun"); register_clcmd("say /buy_ammo","buy_rail_ammo"); register_clcmd("say_team /buy_ammo","buy_rail_ammo"); register_clcmd("drop","drop_rail_gun"); register_clcmd("fullupdate", "clcmd_fullupdate"); register_clcmd("say /trg_arena","arena_mode",ADMIN_KICK,"Starts An Arena"); register_clcmd("say /trg_end_arena","end_arena_mode",ADMIN_KICK,"Ends An Arena"); register_concmd("trg_buy_gun","buy_rail_gun"); register_concmd("trg_start_arena","arena_mode",ADMIN_KICK,"Starts An Arena"); register_concmd("trg_end_arena","end_arena_mode",ADMIN_KICK,"Ends An Arena");   register_forward(FM_PlayerPreThink,"rail_gun_bullets"); register_forward(FM_Touch,"entity_touch"); register_forward(FM_TraceLine,"calculate_hitzone");   register_event("ResetHUD", "event_hud_reset", "be"); register_event("TextMsg", "event_restart_attempt", "a", "2=#Game_will_restart_in"); register_logevent("remove_rail_guns", 2, "1=Round_End"); } public plugin_precache() { engfunc(EngFunc_PrecacheModel,"models/w_railgun.mdl"); engfunc(EngFunc_PrecacheModel,"models/v_railgun.mdl"); engfunc(EngFunc_PrecacheModel,"models/p_railgun.mdl"); engfunc(EngFunc_PrecacheSound,"weapons/rg_hum.wav"); engfunc(EngFunc_PrecacheSound,"weapons/rg_shoot.wav"); engfunc(EngFunc_PrecacheSound,"items/weapondrop1.wav"); Sprite = engfunc(EngFunc_PrecacheModel,"sprites/laserbeam.spr" ); } // client commands to buy a railgun public buy_rail_gun(id) { if(get_pcvar_num(g_Switch)) { g_Money = get_player_money(id);   if(g_Money < get_pcvar_num(g_Price) && (get_user_flags(id) != ADMIN_KICK || get_pcvar_num(g_AdminFree)==0)) { client_print(id,print_chat,"[Rail Gun] You Do Not Have Enough Money!"); return 1;   }else if(get_user_flags(id)== ADMIN_KICK && get_pcvar_num(g_AdminFree)) { client_print(id,print_chat,"[Rail Gun] You Get A Free Gun Admin!"); give_rail_gun(id); ammo_handle(id,100); return 0; }else{ set_player_money(id,g_Money - get_pcvar_num(g_Price)); client_print(id,print_chat,"[Rail Gun] You Have Just Bought A Rail Gun!"); give_rail_gun(id); ammo_handle(id,100); return 0; } } return 0; } // gives the user id a railgun entity public give_rail_gun(id) { g_WeaponEnt = engfunc(EngFunc_CreateEntity,"info_target");   if(pev_valid(g_WeaponEnt)) { set_pev(g_WeaponEnt,pev_classname,"weaponbox"); set_pev(g_WeaponEnt,pev_movetype,MOVETYPE_FOLLOW); set_pev(g_WeaponEnt,pev_solid,SOLID_NOT); set_pev(g_WeaponEnt,pev_aiment,id); set_pev(g_WeaponEnt,pev_viewmodel2,"models/v_railgun.mdl"); set_pev(g_WeaponEnt,pev_weaponmodel2,"models/p_railgun.mdl"); engfunc(EngFunc_EmitSound,id,CHAN_AUTO, "items/gunpickup2.wav", 1.0, ATTN_NORM, 0, PITCH_NORM); drop_primary_weapon(id); return; } } // handles attack buttons , making bullets ,and rate of fire (playerprethink) public rail_gun_bullets(id) { set_world_model(); is_reloading(id,Model,g_Ammo); weapon_holster(id);   if(pev(id,pev_button) & IN_ATTACK | IN_ATTACK2 && holding_rail_gun(Model) && pev(id,pev_waterlevel)!=3 && !is_reloading(id,Model,g_Ammo)) { g_Bullet = engfunc(EngFunc_CreateEntity,"info_target"); global_get(glb_time, global_Time); if(pev_valid(g_Bullet) && global_Time < g_NextAttack[id]) { pev(id,pev_origin,g_Origin);   if(pev(id,pev_flags) & FL_DUCKING) { g_Origin[2] += 12.0; }else{ g_Origin[2] += 17.0; } set_pev(g_Bullet,pev_classname,"DURounds"); engfunc(EngFunc_SetModel,g_Bullet,"models/shell.mdl"); pev(id,pev_v_angle,g_Angle); set_pev(g_Bullet,pev_absmin,g_MinBox); set_pev(g_Bullet,pev_absmax,g_MaxBox); set_pev(g_Bullet,pev_origin,g_Origin); set_pev(g_Bullet,pev_angles,g_Angle); set_pev(g_Bullet,pev_effects,EF_BRIGHTLIGHT); set_pev(g_Bullet,pev_solid,SOLID_BBOX); set_pev(g_Bullet,pev_movetype,MOVETYPE_FLY); set_pev(g_Bullet,pev_owner,id); set_pev(g_Bullet,pev_velocity,2500); set_pev(g_Bullet,pev_renderfx,kRenderFxGlowShell , 255,0,0,kRenderNormal,100); engfunc(EngFunc_EmitSound,id,CHAN_AUTO, "weapons/rg_shoot.wav", 1.0, ATTN_NORM, 0, PITCH_NORM); ++g_Ammo; g_NextAttack[id] = global_Time + g_ROF;   if(pev(id,pev_button) & IN_ATTACK2) { message_begin(MSG_BROADCAST ,SVC_TEMPENTITY); write_byte(0); engfunc(EngFunc_WriteCoord,g_Origin[0]); engfunc(EngFunc_WriteCoord,g_Origin[1]); engfunc(EngFunc_WriteCoord,g_Origin[2]); engfunc(EngFunc_WriteCoord,EndOrigin[0]); engfunc(EngFunc_WriteCoord,EndOrigin[1]); engfunc(EngFunc_WriteCoord,EndOrigin[2]); write_short(Sprite); write_byte(0); write_byte(0); write_byte(50); write_byte(10); write_byte(10); write_byte(0); write_byte(0); write_byte(250); write_byte(127); write_byte(0); message_end();   g_Ammo += 3; } } } return 1; } // handles buying rail ammo from a client command public buy_rail_ammo(id) { if(get_pcvar_num(g_Switch)) { g_Money = get_player_money(id);   if(g_Money < get_pcvar_num(g_AmmoPrice) && (get_user_flags(id) != ADMIN_KICK || get_pcvar_num(g_AdminFree)==0)) { client_print(id,print_chat,"[Rail Gun] You Do Not Have Enough Money!"); return 1;   }else if(get_user_flags(id)== ADMIN_KICK && get_pcvar_num(g_AdminFree)) { client_print(id,print_chat,"[Rail Gun] You Have Been Given Ammo For Free Admin!"); engfunc(EngFunc_EmitSound,id,CHAN_AUTO, "items/9mmclip1.wav", 1.0, ATTN_NORM, 0, PITCH_NORM); ammo_handle(id,100); return 0; }else{ set_player_money(id,g_Money - get_pcvar_num(g_AmmoPrice)); client_print(id,print_chat,"[Rail Gun] You Have Just Bought More Ammo!"); engfunc(EngFunc_EmitSound,id,CHAN_AUTO, "items/9mmclip1.wav", 1.0, ATTN_NORM, 0, PITCH_NORM); ammo_handle(id,100); return 0; } } return 1; } // handles ammo for the rail gun public ammo_handle(id,ammo) { g_Ammo -= ammo;   if(g_Ammo == MAX_AMMO_SLOTS) { engfunc(EngFunc_EmitSound,id,CHAN_AUTO, "weapons/rg_hum.wav", 1.0, ATTN_NORM, 0, PITCH_NORM); ++g_Ammo; return; }else if(g_Ammo > MAX_AMMO_SLOTS) { set_pev( id, pev_button, pev(id,pev_button) & ~IN_ATTACK ); return; } } // if weapon is not being used set models to 0 else set the railgun models public weapon_holster(id) { if(no_weapon_set(id)) { set_pev(g_WeaponEnt,pev_viewmodel2,"models/v_railgun.mdl"); set_pev(g_WeaponEnt,pev_weaponmodel2,"models/p_railgun.mdl"); }else{ set_pev(g_WeaponEnt,pev_viewmodel2,model); set_pev(g_WeaponEnt,pev_weaponmodel2,model); } return; } // get touch for player touching ground gun , bullets touching players or world public entity_touch(ptr,ptd) { pev(ptr,pev_classname,Class,31); pev(ptr,pev_model,Model); if(is_rail_bullet(Class)) { pev(ptr,pev_origin,EndOrigin); calculate_hitzone(g_Origin,EndOrigin,nomonsters,ptd,trace,damage); engfunc(EngFunc_RemoveEntity,ptr); return FMRES_HANDLED; }else if( contain(Model,"w_railgun.mdl")) { give_rail_gun(ptd); engfunc(EngFunc_RemoveEntity,ptr); engfunc(EngFunc_EmitSound,ptd,CHAN_AUTO, "items/gunpickup2.wav", 1.0, ATTN_NORM, 0, PITCH_NORM); return FMRES_HANDLED; }else if (contain(Model,"laserbeam.spr")) { calculate_hitzone(g_Origin,EndOrigin,nomonsters,ptd,trace,10); engfunc(EngFunc_RemoveEntity,ptr); return FMRES_HANDLED; } return FMRES_HANDLED; } // get hitzones using trace then do damage public calculate_hitzone(Float:start[3],Float:end[3],noMonsters,id,trace,damage) { HitZones = get_tr(TR_iHitgroup);   if(is_user_connected(id)) { switch(HitZones) { case HIT_CHEST :fake_damage(id,75 + damage,50 + damage); case HIT_STOMACH : fake_damage(id,55 + damage ,30 + damage); case HIT_HEAD : fake_damage(id,120 + damage,100 + damage); case HIT_LEFTARM , HIT_RIGHTARM :fake_damage(id,25 + damage ,10 + damage); case HIT_LEFTLEG , HIT_RIGHTLEG : fake_damage(id,20 + damage,0 + damage); } } return 1; } // catch the client command "drop" and drop the railgun to hte floor public drop_rail_gun(id) { pev(id,pev_viewmodel2,Model); if(holding_rail_gun(Model)) { engfunc(EngFunc_DropToFloor,g_WeaponEnt); engfunc(EngFunc_EmitSound,id,CHAN_AUTO,"items/weapondrop1.wav" , 1.0, ATTN_NORM, 0, PITCH_NORM); return 1; } return 1; } // if the rail gun entity is on the ground set the w model public set_world_model() { if(pev(g_WeaponEnt,pev_flags) & FL_ONGROUND) { set_pev(g_WeaponEnt,pev_model,"models/w_railgun.mdl"); W_Origin[1] = 0.0; W_Origin[2] = 0.0; set_pev(g_WeaponEnt,pev_origin,W_Origin[1] ); set_pev(g_WeaponEnt,pev_origin,W_Origin[2]); set_pev(g_WeaponEnt,pev_movetype,MOVETYPE_TOSS); set_pev(g_WeaponEnt,pev_solid,SOLID_TRIGGER); return; } } // remove the railguns on the ground every round end public remove_rail_guns() { if(pev(g_WeaponEnt,pev_flags) & FL_ONGROUND) { engfunc(EngFunc_RemoveEntity,g_WeaponEnt); return; } } public client_putinserver(id) { if(get_pcvar_num(g_Switch)) { g_NextAttack[id] = 0.0; g_Ammo = 0; return; } } public client_disconnect(id) { if(get_pcvar_num(g_Switch)) { g_NextAttack[id] = 0.0 g_Ammo = 0; return; } } // start an arena public arena_mode(id,level,cid) { if(cmd_access(id,level,cid,0) && get_pcvar_num(g_Switch)) { set_cvar_string("sv_restartround","1"); set_cvar_string("rg_arena_on","1"); return 1; } return 1; } // end arena public end_arena_mode(id,level,cid) { if(cmd_access(id,level,cid,0)) { set_cvar_string("sv_restartround","1"); set_cvar_string("rg_arena_on","0"); return 1; } return 1; } public clcmd_fullupdate() { return 1; } public event_restart_attempt() { new players[32], num get_players(players, num, "a") for (new i; i < num; ++i) { g_restart_attempt[players[i]] = true; } } public event_hud_reset(id) { if (g_restart_attempt[id]) { g_restart_attempt[id] = false; return; } event_player_spawn(id) } public event_player_spawn(id) { if(get_pcvar_num(g_ArenaMode)) { give_rail_gun(id); return; } }
Heres my inc file
Code:
  #if !defined _fakemeta_included #include <fakemeta> #endif #if defined _rail_gun_included #endinput #endif #define _rail_gun_included   #if cellbits == 32 #define OFFSET_MONEY 115 #else #define OFFSET_MONEY 140 #endif #define OFFSET_LINUX 5 stock set_player_money(id,money) { set_pdata_int(id,OFFSET_MONEY,money,OFFSET_LINUX); message_begin(MSG_ONE,get_user_msgid("Money"),{0,0,0},id); write_long(money); write_byte(1); message_end(); } stock get_player_money(id) { return get_pdata_int(id,OFFSET_MONEY,OFFSET_LINUX); } stock holding_rail_gun(Model[32]) { if(contain(Model,"v_railgun.mdl")) { return true; } return false; } stock is_rail_bullet(Class[32]) { if(contain(Class,"DURounds")) { return true; } return false; } stock rail_gun_kill(id) { new Float: frags   if (is_user_alive(id)) { pev(id, pev_frags, frags); set_pev(id, pev_frags, ++frags); dllfunc(DLLFunc_ClientKill, id); return; } } stock fake_damage(id,health,armor) { new Float: g_Health; new Float: g_Armor;   pev(id,pev_health,g_Health); set_pev(id,pev_health,g_Health - health);   pev(id,pev_armorvalue,g_Armor); set_pev(id,pev_armorvalue,g_Armor - armor);   set_pev(id,pev_dmg,DMG_BULLET | DMG_ENERGYBEAM); return; } stock is_reloading(id,Model[32],g_Ammo) { if(pev(id,pev_button) & IN_RELOAD && holding_rail_gun(Model)) { set_pev(id, pev_weaponanim, CSW_M249); message_begin(MSG_ONE, SVC_WEAPONANIM, {0, 0, 0}, id); write_byte(CSW_M249); write_byte(pev(id, pev_body)); message_end(); g_Ammo -= 100;   return true; } return false; } stock drop_primary_weapon(id) { new clip,bpammo; new Weapon = get_user_weapon(id,clip,bpammo);   if(Weapon == CSW_SCOUT | CSW_XM1014 | CSW_MAC10 | CSW_AUG | CSW_UMP45 | CSW_SG550 | CSW_GALIL | CSW_FAMAS | CSW_AWP | CSW_MP5NAVY | CSW_M249 | CSW_M3 | CSW_M4A1 | CSW_TMP | CSW_G3SG1 | CSW_SG552 | CSW_AK47 | CSW_P90 ) { client_cmd(id,"+drop"); } } stock no_weapon_set(id) { new clip,bpammo; new Weapon = get_user_weapon(id,clip,bpammo);   if(Weapon == CSW_P228 | CSW_SCOUT | CSW_HEGRENADE | CSW_XM1014 | CSW_C4 | CSW_MAC10 | CSW_AUG | CSW_SMOKEGRENADE | CSW_ELITE | CSW_FIVESEVEN | CSW_UMP45 | CSW_SG550 | CSW_GALI | CSW_GALIL | CSW_FAMAS | CSW_USP | CSW_GLOCK18 | CSW_AWP | CSW_MP5NAVY | CSW_M249 | CSW_M3 | CSW_M4A1 | CSW_TMP | CSW_G3SG1 | CSW_FLASHBANG | CSW_DEAGLE | CSW_SG552 | CSW_AK47 | CSW_KNIFE | CSW_P90 ) { return false; }else{ return true; } return 1; }

teame06 12-24-2006 20:59

Re: Fatal Error
 
If you use FM_Traceline on pre without the fun module. Your going to have to SUPERCEDE the function and run your traceline. If your just using as aim and you do not use pre then do

register_forward(FM_TraceLine,"calculate_hitz one", 1);


Code:
public traceline(const Float:v1[3], const Float:v2[3], noMonsters, pentToSkip, TraceResultPtr) {     engfunc(EngFunc_TraceLine, v1, v2, noMonsters, pentToSkip, TraceResultPtr)     // Do your stuff     return FMRES_SUPERCEDE; }

The Specialist 12-24-2006 21:27

Re: Fatal Error
 
Thanks Team06.I added that , But Im still getting this error "Fatal Error : ED_ALLOC NO FREE EDICTS". And also this runtime error .:cry:
Code:

L 12/24/2006 - 20:26:22: Start of error session.
L 12/24/2006 - 20:26:22: Info (map "de_dust_cz") (logfile "error_122406.log")
L 12/24/2006 - 20:26:22: [FAKEMETA] Invalid return type
L 12/24/2006 - 20:26:22: [AMXX] Displaying debug trace (plugin "rail_gun.amxx")
L 12/24/2006 - 20:26:22: [AMXX] Run time error 10: native error (native "pev")
L 12/24/2006 - 20:26:22: [AMXX]    [0] rail_gun.sma::entity_touch (line 283)


jim_yang 12-24-2006 23:47

Re: Fatal Error
 
don't do this
if( a== 1 | 2 | 3 | 4 | 5 ...)
you can
switch(a)
case 1,2,3,4,5: return true
default: return false

The Specialist 12-25-2006 00:18

Re: Fatal Error
 
Are you talking about the check all weapon function I did ? With the | . I was looking for a more efficiiant way to do that . I can use a switch with that many choices on one case ?

Ok what about the fatal error "NO FREE EDICTS" . Any ideas ?

EDIT: why wont this work ?
Code:
stock drop_primary_weapon(id) {  new clip,bpammo;  new Weapon = get_user_weapon(id,clip,bpammo);    switch(Weapon)  {   case  CSW_SCOUT,CSW_XM1014,CSW_MAC10,CSW_AUG,CSW_UMP45,CSW_SG550,CSW_GALIL,CSW_FAMAS,CSW_AWP,   CSW_MP5NAVY,CSW_M249,CSW_M3,CSW_M4A1,CSW_TMP,CSW_G3SG1,CSW_SG552,CSW_AK47,   CSW_P90:  client_cmd(id,"+drop") return true;   default: return false;  } }

jim_yang 12-25-2006 01:15

Re: Fatal Error
 
Code:
stock g_WeaponSlots[] = {         0,         2,        //CSW_P228         0,         1,        //CSW_SCOUT         4,        //CSW_HEGRENADE         1,        //CSW_XM1014         5,        //CSW_C4         1,        //CSW_MAC10         1,        //CSW_AUG         4,        //CSW_SMOKEGRENADE         2,        //CSW_ELITE         2,        //CSW_FIVESEVEN         1,        //CSW_UMP45         1,        //CSW_SG550         1,        //CSW_GALIL         1,        //CSW_FAMAS         2,        //CSW_USP         2,        //CSW_GLOCK18         1,        //CSW_AWP         1,        //CSW_MP5NAVY         1,        //CSW_M249         1,        //CSW_M3         1,        //CSW_M4A1         1,        //CSW_TMP         1,        //CSW_G3SG1         4,        //CSW_FLASHBANG         2,        //CSW_DEAGLE         1,        //CSW_SG552         1,        //CSW_AK47         3,        //CSW_KNIFE         1        //CSW_P90 }; stock drop_primary_weapon(id) {         new clip,bpammo;         new Weapon = get_user_weapon(id,clip,bpammo);         if(g_WeaponSlots[Weapon] == 1)         {                 client_cmd(id,"+drop")                 return true;         }         else return false; }
besides get_user_weapon only return player current holding weapon
so if you want to drop primary weapons, you need to get_user_weapons, then loop to check and drop

The Specialist 12-25-2006 02:17

Re: Fatal Error
 
Thanks Jim :up: Your the greatest . I had to use magic numbers (cstrike enumeration numbers) for the other function. But it is way more efficiant then the way I had it .

So my last questions are , What is cuasing the fatal errors . And I need a way to convert my current ammo and weapon index system, into a multi-dimensional array or enum or something. But I have never used them , I need to store the g_WeaponENt(index)[ammo in gun] .

cybermind 12-25-2006 04:30

Re: Fatal Error
 
The "NO FREE EDICTS" error means there are too many entities.

jopmako 12-25-2006 08:43

Re: Fatal Error
 
Code:

g_Bullet = engfunc(EngFunc_CreateEntity,"info_target")
Code:

g_Bullet = engfunc(EngFunc_CreateEntity,engfunc(EngFunc_AllocString,"info_target"))
Is this a problem?

The Specialist 12-25-2006 11:09

Re: Fatal Error
 
I dont think so . The engine does the alloc handling itself . I think . But its kinda impossable that I have to many entities , It happens connect.


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

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