AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   distance between 2 players (https://forums.alliedmods.net/showthread.php?t=184497)

striker07 05-05-2012 18:53

distance between 2 players
 
how can i code that when a terrorist comes into the kniferange of a counterterrorist he gets slapped and when he leaves from his kniferange he stops being slapped.
and in what function could i use that best becous it should constantly check this.

kniferange being an amount in units set up through a cvar

Xalus 05-05-2012 19:01

Re: distance between 2 players
 
Try it ;)

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <fun>

#define PLUGIN "Slap Radius"
#define VERSION "1.0"
#define AUTHOR "Xalus"

new cStatuscRadiuscPower

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
// Register: Cvars
    
cStatus        register_cvar("radiusslap_status""1");
    
cRadius        register_cvar("radiusslap_radius""30");
    
cPower        register_cvar("radiusslap_power""15");
}
public 
client_PreThink(id) {
    if( 
is_user_alive(id) && get_user_team(id) == 
    
&& get_pcvar_num(cStatus) ) {
        static 
Float:plOrigin[3]
        
entity_get_vector(idEV_VEC_originplOrigin)
        
        new 
ent = -1plList[32], plAmount
        plAmount 
find_sphere_class(ent"player"get_pcvar_float(cRadius), plListcharsmax(plList), plOrigin)
        
        if( !
plAmount )
            return
        
        for(new 
0plAmounti++)
            if(
is_user_alive(plList[i]) 
            && 
get_user_team(plList[i]) == 1)
                
user_slap(plList[1], get_pcvar_num(cPower))
    }



Exolent[jNr] 05-05-2012 21:45

Re: distance between 2 players
 
Quote:

Originally Posted by Xalus (Post 1702936)
Try it ;)

PHP Code:

for(new 0find_sphere_class(ent"player"get_pcvar_float(cRadius), plListcharsmax(plList), plOrigin); i++) 


Wow.
You know that the condition is called after every loop iteration, so you are calling that function as many times as the number of entities it returns.
Very inefficient.

Call it once before the loop and store the return in a variable. Then use the variable in the condition.

Xalus 05-06-2012 07:31

Re: distance between 2 players
 
Hm ur right, stupid..

Anyway, updated.

striker07 05-06-2012 09:40

Re: distance between 2 players
 
Nice thx it works but i think it might have some issues, look this is what happend when (i think) he got slapped to much. also I was on terrorist team and a bot was on ct team and the bot got slapped. is that only with bots? if it is then there is no problem :)
Tested it on my local dedicated server (windows).

I'm not sure but this might be solved if we change the uberslap to normal slap not sure though

[IMG]http://img571.**************/img571/6942/slapradius.png[/IMG]

also can you make it so that along with the slap a bit turns high when a player is inside the range and low again if he leaves the range.

merci voor de hulp ;)
greets.

Xalus 05-06-2012 09:55

Re: distance between 2 players
 
Firewall shouldn't have anything todo with it, I think.

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <fun>

#define PLUGIN "Slap Radius"
#define VERSION "1.1"
#define AUTHOR "Xalus"

/* Changelog:
    [v1.0]
        - Beta Version
        
    [v1.1]
        - Added 'Terrorist Slap' Delay
*/

new cStatuscRadiuscPowercDelay
new Float:playerDelay[33]

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
// Register: Cvars
    
cStatus        register_cvar("radiusslap_status""1");
    
cRadius        register_cvar("radiusslap_radius""30.0");
    
cPower        register_cvar("radiusslap_power""15");
    
    
cDelay        register_cvar("radiusslap_delay""0.5");
}
public 
client_PreThink(id) {
    if( 
is_user_alive(id) && get_user_team(id) == 
    
&& get_pcvar_num(cStatus) ) {
        static 
Float:plOrigin[3]
        
entity_get_vector(idEV_VEC_originplOrigin)
        
        new 
ent = -1plList[32], plAmount
        plAmount 
find_sphere_class(ent"player"get_pcvar_float(cRadius), plListcharsmax(plList), plOrigin)
        
        if( !
plAmount )
            return
        
        new 
Float:gTime get_gametime()
        for(new 
0plAmounti++) {
            if(
is_user_alive(plList[i]) 
            && 
get_user_team(plList[i]) == 1
            
&& !is_user_bot(plList[i])
            && 
playerDelay[plList[i]] < gTime) {
                
user_slap(plList[1], get_pcvar_num(cPower))
                
playerDelay[plList[i]] = gTime get_pcvar_float(cDelay)
            }
        }
    }


I added a delay, for Terrorist Slap.

I didn't rlly get what u needed, if u want. Just type in in 'Dutch' for me :p

striker07 05-06-2012 10:07

Re: distance between 2 players
 
ok nice thx.
I'l explain in dutch then ;)

waarvoor ik die code uiteindelijk wil gebruiken is voor een anti freekill systeem voor jailbreak.
als een terrorist in de buurt komt van een cipier(ct) dan moet een bit hoog worden dat die terrorist aan het rebellen is zodanig dat als de cipier hem dood hij niet gestraft word voor freekilling snapje?
Ik weet wel niet hoe je de bit terug laag moet maken als de ter uit de range van de ct komt.
alsje wil kan ik mijn hele jb plugin doorsturen als dat zou helpen.
Ik moet je nieuwe code nog testen maar ik denk dat het al aardig goed zal lukken. zal vanavond nog testen, moet straks ergens naartoe.

Ik hoop dat dat een beetje goed uitgelegd is :), anders moet je het maar vragen he.

alvast bedankt!
greets.

Xalus 05-06-2012 11:47

Re: distance between 2 players
 
So you want, that when a Prisoner comes close to a Guard, he goes in the sky a lille?
When he goes back away from Guard, he goes back to the ground?

striker07 05-06-2012 15:54

Re: distance between 2 players
 
no not really the slap is a lil extra that im not sure yet if i will use it,
but if a terrorists comes close to the guard a bit have to be set and when the terrorist moves away, out of range of the ct the bit has to turn low again.
then when a guard has killed a terrorists I am gonna check first if that terrorist was close to that ct by checking the bit.

for example lets name that bit g_bRebelRange.

If that bit was high the moment the terrorists got killed by the ct then the ct did not freekill him, but if the bit for that terrorist was low and other conditions that check if he rebeled where low too then the ct has +1 freekill,
this is the function that I will add this statement to:
PHP Code:

public Event_DeathMsg() 

 new 
iKiller read_data(1); 
 new 
iVictim read_data(2);
 
 new 
freekill_slay get_pcvar_num(jb_slay_4freekills)
 new 
max_freekills get_pcvar_num(jb_max_freekills);
 new 
szVName[32], szKName[32]; 
 
get_user_name(iVictimszVNamecharsmax(szVName)); 
 
get_user_name(iKillerszKNamecharsmax(szKName));
 
clear_bit(g_bIsAliveiVictim);
 
 if( 
cs_get_user_teamiVictim ) == CS_TEAM_T 
 {  
  if( 
IsPlayeriKiller ) && cs_get_user_teamiKiller ) == CS_TEAM_CT 
  { 
   if( 
g_bRebel[iVictim] || g_bHasPrimaryiVictim ]/* || g_bRebelRange [iVictim]*/ 
   { 
    
fnColorPrint(0"Guard^4 %s ^1killed rebel^4 %s ^1!"szKNameszVName); 
   }
   else if( !
g_bRebel[iVictim] ) 
   {
    if( 
g_bHasPrimaryiVictim ] ) 
     return 
PLUGIN_HANDLED;
    
g_iFreekill[iKiller]++
 
    if(
g_iFreekill[iKiller] == 1)
    {
     
fnColorPrint(iKiller"^3Warning:^1 Freekilling will not be tolerated. ");
     
UTIL_ScreenFade(iKiller,{ 25510061 }, 2.02.085);
    }
    if(
g_iFreekill[iKiller] == 2)
    {
     
UTIL_ScreenFade(iKiller,{ 25510061 }, 2.52.595);
    }
    if(
g_iFreekill[iKiller] == freekill_slay)
    {
     
fnColorPrint(iKiller"^3Last warning:^1 Every freekill you make from now on, will result in slay and teamswitch");
     
UTIL_ScreenFade(iKiller,{ 2550}, 2.52.5175);
    }
    if(
g_iFreekill[iKiller] >= max_freekills)
    {
     
create_user_cztutor(0REDtutorsound16.5"Jailbreak - Insurgency: ^nYou have been transfered to prisoners team^nfor freekilling to much!");
     
set_task(7.0"tutor_remove_7sec"iKiller);
     
//formatex(Text,191,"Jailbreak - Insurgency: ^nGuard %s has been transfered to prisoners team^nfor freekilling to much", szKName);
     //MakeTutor(0,Text,RED,5.0) 
 
     
UTIL_ScreenFade(iKiller,{ 2550}, 2.52.5255);
     
cs_set_user_team(iKillerCS_TEAM_T);
     
user_kill(iKiller);
    }
   }
  } 
 }
 return 
PLUGIN_HANDLED;


btw the czero tutor does not work, tryed many diffrent ways but it doesnt work for windows servers. havent tested on linux yet

Xalus 05-06-2012 16:00

Re: distance between 2 players
 
Isn't it better then to check distance from killer & victim
and if distance between T & CT is lower then 100
it isn't freekill?


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

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