AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Limited Map Zone (https://forums.alliedmods.net/showthread.php?t=309524)

edon1337 07-29-2018 08:59

Limited Map Zone
 
I'm using this modified code originally created by Natsheh, to create a zone that would slap users who are outside of it, but it just kills me instantly as soon as I type /create.

PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <xs>

new const g_szSprite[ ] = "sprites/laserbeam.spr";

new 
g_iSprite;

public 
plugin_init( )
{    
    
register_clcmd"say /create""@CreateZone" );
}

public 
plugin_precache( ) 

    
g_iSprite precache_modelg_szSprite ); 


@
CreateZoneid )
{
    new 
Float:fOrigin_Center]
    
pevidpev_originfOrigin_Center );
    
    const 
iDivide 128;
    new 
Float:fOrigin]
    
//new Float:fAngle[ 3 ], Float:AngleMulScalar = ( 360.0 / iDivide ), Float:fVector[ 3 ];
    //const Float:iRadius = 500.0;
    
    
new Array:aTempArray ArrayCreatesizeof fOrigin);
    
    for( new 
iiDividei++ )
    {
        
//angle_vector( fAngle, ANGLEVECTOR_RIGHT, fVector );
        //xs_vec_mul_scalar( fVector, iRadius, fVector );
        //xs_vec_add( fOrigin_Center, fVector, fOrigin );
        
        
ArrayPushArrayaTempArrayfOrigin );
        
        
//fAngle[ 1 ] += AngleMulScalar;
        
CreateWallfOrigin /*,fAngle*/ );
    }
    
    new 
szPlayers32 ], iNumiTempID;
    
get_playersszPlayersiNum"ach" );
    
    for( new 
iFloat:fUserOrigin]; iNumi++ )
    {
        
iTempID szPlayers];
        
peviTempIDpev_originfUserOrigin );
        
        for( new 
xArraySizeaTempArray ); x++ )
        {
            
ArrayGetArrayaTempArrayxfOrigin );
            
            if( 
fUserOrigin] < fOrigin] || fUserOrigin] < fOrigin] ||
                    
fUserOrigin] > fOrigin] || fUserOrigin] < fOrigin] )
            {
                
user_slapiTempIDrandom_num210 ) )
            }
        }
    }
    
    
ArrayDestroyaTempArray );
}

CreateWallFloat:fOrigin]/*, Float:fAngle[ 3 ]*/)
{  
    
message_beginMSG_BROADCASTSVC_TEMPENTITY )
    
write_byteTE_BEAMPOINTS )
    
engfuncEngFunc_WriteCoordfOrigin] )
    
engfuncEngFunc_WriteCoordfOrigin] )
    
engfuncEngFunc_WriteCoordfOrigin] )
    
engfuncEngFunc_WriteCoordfOrigin] )
    
engfuncEngFunc_WriteCoordfOrigin] )
    
engfuncEngFunc_WriteCoordGetMaxHeight( ) )
    
write_shortg_iSprite 
    
write_byte
    
write_byte
    
write_byte10 
    
write_byte60 
    
write_byte
    
write_byte255 )
    
write_byte)
    
write_byte)
    
write_byte127 )
    
write_byte)
    
message_end( );
}  

Float:GetMaxHeight( )

    new  
pcCurrent;
    new 
Float:fStartPoint];
    
    while ( ( 
engfuncEngFunc_PointContents fStartPoint ) == CONTENTS_EMPTY ) || (  engfuncEngFunc_PointContents fStartPoint ) == CONTENTS_SOLID ) )
    {
        
fStartPoint] += 5.0
    }
    
    
pcCurrent engfuncEngFunc_PointContents fStartPoint ); 

    if( 
pcCurrent == CONTENTS_SKY )
    {
        return 
fStartPoint] -= 20.0;
    }
    return 
0.0



HamletEagle 07-29-2018 09:19

Re: Limited Map Zone
 
I think you should break after user_slap, probably it keeps slapping the player until he dies. Maybe you can use a task to periodically slap the player while he's in the zone.

edon1337 07-29-2018 09:27

Re: Limited Map Zone
 
Quote:

Originally Posted by HamletEagle (Post 2606805)
I think you should break after user_slap, probably it keeps slapping the player until he dies. Maybe you can use a task to periodically slap the player while he's in the zone.

Yea thanks I'm not dying instantly now, still no beam appears, am I setting it wrong?

Ghosted 07-29-2018 09:27

Re: Limited Map Zone
 
Code:

if( fUserOrigin[ 0 ] < fOrigin[ 0 ] || fUserOrigin[ 0 ] < fOrigin[ 0 ] ||
                    fUserOrigin[ 1 ] > fOrigin[ 1 ] || fUserOrigin[ 1 ] < fOrigin[ 1 ] )

Why that code checks same thing twice :crab:

edon1337 07-29-2018 12:45

Re: Limited Map Zone
 
I made something but it slaps me when I'm close to the beams, like, I'm within the radius but stay close to them, it slaps me. Also when I'm in the radius but in the sky.

PHP Code:

#include < amxmodx >
#include < fakemeta >
#include < xs >

new const g_szSprite[ ] = "sprites/laserbeam.spr";

new 
g_iSprite;

public 
plugin_init( )
{
    
register_clcmd"say /sphere""OnSphere" );
    
register_clcmd"say /remove""OnRemove" );
}

public 
plugin_precache( ) 

    
g_iSprite precache_modelg_szSprite ); 



public 
OnSphereid )
{
    
set_task1.0"RenewSphere"666, .flags="b" );
}

public 
OnRemoveid )
{
    
remove_task666 );
}

public 
RenewSphere( )
{
    new 
Float:fOrigin_Center[3] = {-8.5, -0.0, -487.4};
    const 
divides 128
    new 
Float:fOrigin[3];
    new 
Float:fAngle[3], Float:AngleMulScalar = (360.0 divides), Float:fVector[3];
    const 
Float:Radius 2000.0;
    
    for(new 
idividesi++)
    {
        
angle_vector(fAngleANGLEVECTOR_RIGHTfVector);
        
xs_vec_mul_scalar(fVectorRadiusfVector);
        
xs_vec_add(fOrigin_CenterfVectorfOrigin);
        
        
CreateBeamfOrigin );
        
        
fAngle[1] += AngleMulScalar;
    }

    
// check if other players are out and slap them.
    
new ent = -1players[32], pnumignore[33];
    while( (
ent engfunc(EngFunc_FindEntityInSphereentfOrigin_CenterRadius)) > 0)
    {
        if(
is_user_alive(ent))
        {
            
ignore[ent] = true;
        }
    }

    
get_players(players,pnum,"a")
    for(new 
i,playerpnumi++)
    {
        
player players[i];
        if(
ignore[player]) continue;

        
user_slap(playerrandom_num(2,10));
    }  
}

CreateBeamFloat:fOrigin] )
{  
    
message_beginMSG_BROADCASTSVC_TEMPENTITY )
    
write_byteTE_BEAMPOINTS )
    
engfuncEngFunc_WriteCoordfOrigin] )
    
engfuncEngFunc_WriteCoordfOrigin] )
    
engfuncEngFunc_WriteCoordfOrigin] )
    
engfuncEngFunc_WriteCoordfOrigin] )
    
engfuncEngFunc_WriteCoordfOrigin] )
    
engfuncEngFunc_WriteCoord4000.0 )
    
write_shortg_iSprite 
    
write_byte
    
write_byte
    
write_byte30 
    
write_byte60 
    
write_byte
    
write_byte255 )
    
write_byte)
    
write_byte)
    
write_byte127 )
    
write_byte)
    
message_end( );



Ghosted 07-29-2018 14:53

Re: Limited Map Zone
 
Quote:

Originally Posted by edon1337 (Post 2606859)
Also when I'm in the radius but in the sky.

Yes cause it is checking origins in all three dimensions and if length is higher than radius it will slap

PS: What is the point of setting tasks with such ids

edon1337 07-29-2018 15:16

Re: Limited Map Zone
 
Quote:

Originally Posted by Ghosted (Post 2606883)
Yes cause it is checking origins in all three dimensions and if length is higher than radius it will slap

Yes, I figured as much, but there's something else, I don't know whether it's a normal thing or a miscalculation of the game:

It will be hard to understand, so make sure you read this twice:
- If I set the center origin of the zone in a high place, when you go close to the beams at the same height, you will get slapped as soon as you exceed the area, which is fine, but, if you go on a lower place, you'll get slapped even before touching the beam, is this a normal thing?

Something like this
https://image.ibb.co/gB6rTo/Miscalculation.png

Ghosted 07-29-2018 15:58

Re: Limited Map Zone
 
Quote:

Originally Posted by edon1337 (Post 2606888)
Yes, I figured as much, but there's something else, I don't know whether it's a normal thing or a miscalculation of the game:

It will be hard to understand, so make sure you read this twice:
- If I set the center origin of the zone in a high place, when you go close to the beams at the same height, you will get slapped as soon as you exceed the area, which is fine, but, if you go on a lower place, you'll get slapped even before touching the beam, is this a normal thing?

Something like this
https://image.ibb.co/gB6rTo/Miscalculation.png

Thats when you checking height in length too (FIND ENT IN SPHERE Does That), if you don't want then it must be coded manually and distance will be calculated with SquareRootOf(Origin[0] * Origin[0] + Origin[1] * Origin[1])

EDIT

it will be like:

while (ent = find_ent_by_classname(ent, "player"))
{
// get user origin
// create origin which will be : playerOrigin - centerOrigin
// calculate its 2D length with that formula
// check if it is higher than ur radius
}

edon1337 07-29-2018 16:07

Re: Limited Map Zone
 
Wouldn't saving every beams origin when it is created and then checking with a task work?
PHP Code:

get_distance_f(PlayerOriginBeamOrigin) <= 0.0


Ghosted 07-29-2018 16:12

Re: Limited Map Zone
 
Quote:

Originally Posted by edon1337 (Post 2606903)
Wouldn't saving every beams origin when it is created and then checking with a task work?
PHP Code:

get_distance_f(PlayerOriginBeamOrigin) <= 0.0


(4got get_distance) get_distance_f is same thing as i said there, just check distance between center origin and player and if its higher than radius slap him. Why you need to check with beams, this one is way smooth


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

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