AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Flag Problems?[SOLVED] (https://forums.alliedmods.net/showthread.php?t=47442)

The Specialist 11-18-2006 02:48

Flag Problems?[SOLVED]
 
I need some help . This code works sorta . I get run time errors. It finds the bomb perfectly. But for some reason it executes my code on CT's , but in reverse of the T's. for instance , it shows the essage to CT's get within 1000 units of the bomb. but T's it works for , but it doesnt do any of the punishments. I cant figure out if its my flags or the functions .
Code:
#include <amxmodx> #include <engine> #include <fun> // Global Variables new g_iFollow_Bomb; new g_iPunish,Player_Count; new  g_iRadius; new g_iEntlist[513]; new g_iPlayers[32]; new g_Mode[8]; // register plugin public plugin_init() {     register_plugin("Follow The Bomber","0.1","The Speicialist");     register_event("ResetHUD","reset_hud","be");     g_iFollow_Bomb = register_cvar("amx_follow_bomb","1");     g_iPunish = register_cvar("amx_punishment","ab");     g_iRadius = register_cvar("amx_radius","1000");     set_task(2.0,"find_bomb",0,"",0,"b"); } // reset hud event public reset_hud(id) {     // show message to follwo the bomb         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 players in the radious sphere of the bomb                 new g_In_Range  = find_sphere_class(g_iBomb,"player",get_pcvar_float(g_iRadius),g_iEntlist,512);                 // find all alive terrorists                 new g_All_Players = get_players(g_iPlayers,Player_Count,"ace","CS_TEAM_T");                 // if all alive terrorists arnt in range then punish                 if(g_All_Players != g_In_Range)         {             punish_mode(id);         }     }     return PLUGIN_HANDLED; } // punishment function public punish_mode(id) {     // 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(id);         // dispaly hud messages for leaving bomb         set_hudmessage(255, 255, 255, -1.0, 0.34, 0, 6.0, 2.0);     show_hudmessage(id, "Your Leaving The Bomb");         // punish based on flags from cvar string         if(g_iMode == 1 )     {         // slap with -1 haelth but dont move                 user_slap(id,1,0);     }     if(g_iMode ==2 )     {         // -1 armor from user                 set_user_armor(id,(g_iArmor - 1));     }     if(g_iMode == 4 )     {         // strip the weapons from that user                 strip_user_weapons(id);     }     return PLUGIN_HANDLED; }
thanks guys

XxAvalanchexX 11-18-2006 03:09

Re: Flag Problems?
 
You can't really compare your players like that. I'd do what VEN suggested in another one of your threads:

Code:
new Float:c4origin[3], Float:pOrigin[3]; entity_get_vector(g_iBomb,EV_VEC_origin,c4origin); new players[32], num, i; get_players(players,num,"ace","TERRORIST"); for(i=0;i<num;i++) {     entity_get_vector(players[i],EV_VEC_origin,pOrigin);     if(get_distance_f(c4origin,pOrigin) > get_pcvar_float(g_iRadus))         punish_mode(players[i]); }

This grabs the origin of the C4 entity, and then gets all of the alive non-bot terrorists. Note that the correct team name flag to get the terrorist team is "TERRORIST" (counter-terrorists are "CT" and spectators are "SPECTATOR"). CS_TEAM_T and CS_TEAM_CT are used for the cs_get/set_user_team natives. Then it goes through all of those terrorists we grabbed, and gets their origin. It sees if they are too far away, and if so calls the punish function.

The Specialist 11-18-2006 03:21

Re: Flag Problems?
 
im getting some errors now
Code:

Error: Undefined symbol "punish_mode" on line 97
Warning: Loose indentation on line 100
Warning: Loose indentation on line 105
Error: Invalid expression, assumed zero on line 105
Error: Undefined symbol "punish_mode" on line 105
Error: Expected token: "}", but found "-end of file-" on line 143

here my new code

Code:
#include <amxmodx> #include <engine> #include <fun> // Global Variables new g_iFollow_Bomb; new g_iPunish,Player_Count; new  g_iRadius; new g_iEntlist[513]; new g_iPlayers[32]; new g_Mode[8]; new Float:c4origin[3]; new  Float:pOrigin[3]; new players[32], num, i; // register plugin public plugin_init() {     register_plugin("Follow The Bomber","0.1","The Speicialist");     register_event("ResetHUD","reset_hud","be");     g_iFollow_Bomb = register_cvar("amx_follow_bomb","1");     g_iPunish = register_cvar("amx_punishment","ab");     g_iRadius = register_cvar("amx_radius","1000");     set_task(2.0,"find_bomb",0,"",0,"b"); } // reset hud event public reset_hud(id) {     // show message to follwo the bomb         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 players in the radious sphere of the bomb                 entity_get_vector(g_iBomb,EV_VEC_origin,c4origin);                 get_players(players,num,"ace","TERRORIST");         for(i=0;i<num;i++)         {         entity_get_vector(players[i],EV_VEC_origin,pOrigin);         if(get_distance_f(c4origin,pOrigin) > get_pcvar_float(g_iRadius))         {             punish_mode(id,players[i]);         }     }     return PLUGIN_HANDLED; } // punishment function public punish_mode(id,players[i]) {     // 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(id);         // dispaly hud messages for leaving bomb         set_hudmessage(255, 255, 255, -1.0, 0.34, 0, 6.0, 2.0);     show_hudmessage(id, "Your Leaving The Bomb");         // punish based on flags from cvar string         if(g_iMode == 1 )     {         // slap with -1 haelth but dont move                 user_slap(id,1,0);     }     if(g_iMode ==2 )     {         // -1 armor from user                 set_user_armor(id,(g_iArmor - 1));     }     if(g_iMode == 4 )     {         // strip the weapons from that user                 strip_user_weapons(id);     }     return PLUGIN_HANDLED; }

[ --<-@ ] Black Rose 11-18-2006 07:49

Re: Flag Problems?
 
Then fix them.
If you don't know what the errors is then search... it's pretty logical errors...

XxAvalanchexX 11-18-2006 12:27

Re: Flag Problems?
 
Code:
public punish_mode(id,players[i])

...?

The Specialist 11-18-2006 20:18

Re: Flag Problems?
 
can some one tell me why its not punishing me ? what is wrong with my flags here ? it displays the message but then in doesnt punish me slap me or anything. how do i use read_flags properly?
Code:
#include <amxmodx> #include <engine> #include <fun> // 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.1","The Speicialist");     register_event("ResetHUD","reset_hud","be");     g_iFollow_Bomb = register_cvar("amx_follow_bomb","1");     g_iPunish = register_cvar("amx_punishment","ab");     g_iRadius = register_cvar("amx_radius","1000");     set_task(2.0,"find_bomb",0,"",0,"b"); } // reset hud event public reset_hud(id) {     // show message to follwo the bomb         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 distance between players and bomb                         entity_get_vector(players[i],EV_VEC_origin,pOrigin);                         // if out of range execute punish mode             if(get_distance_f(c4origin,pOrigin) > 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);         // 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 )     {         // slap with -1 haelth but dont move                 user_slap(players,1,0);     }     if(g_iMode  == 2 )     {         // -1 armor from user                 set_user_armor(players,(g_iArmor - 1));     }     if(g_iMode == 4 )     {         // strip the weapons from that user                 strip_user_weapons(players);     }     return PLUGIN_HANDLED; }

please and thank you :|

XxAvalanchexX 11-18-2006 20:39

Re: Flag Problems?
 
Using read_flags, "a" becomes 1, "b" becomes 2, "c" becomes 4, "d" becomes 8, etcetera, etcetera. So, this is what I would do:

Code:
g_iMode = read_flags(g_Mode); if(g_iMode & 1) // flag A { } if(g_iMode & 2) // flag B { } if(g_iMode & 4) // flag C { }

Then you can combine multiple letters and have it perform multiple punishments.

The Specialist 11-18-2006 20:42

Re: Flag Problems?
 
oh ok. Can you tell my why & ? i thought a single & was a bitwise operator ? or is that only in C?

XxAvalanchexX 11-18-2006 21:34

Re: Flag Problems?
 
Yes, it is a bitwise operator. (1<<0) equals 1, (1<<1) equals 2, (1<<2) equals 4, etcetera. You can use those instead of standard integers if you'd like, the result will be the same.

The Specialist 11-18-2006 23:07

Re: Flag Problems?
 
thanks i got it working perfectly now . thanks for all thehelp av +karma:up:


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

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