Raised This Month: $51 Target: $400
 12% 

Creating zones & checking if client is inside a zone


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
BraveFox
AlliedModders Donor
Join Date: May 2015
Location: Israel
Old 03-28-2018 , 07:08   Creating zones & checking if client is inside a zone
Reply With Quote #1

Hey,
I'm starting to work with zones, and tried somethings out but nothing worked.
Can someone please help and post here a tutorial or something?
And please don't give me the "Dev Zones" because it's not helping me.
Thanks.
__________________
Contact Me:
Steam: NoyB
Discord: Noy#9999
Taking Private Requests

Last edited by asherkin; 10-25-2018 at 17:09. Reason: Restore to previous version.
BraveFox is offline
blaacky
Senior Member
Join Date: Oct 2012
Old 03-28-2018 , 07:26   Re: Creating zones & checking if client is inside a zone
Reply With Quote #2

https://forums.alliedmods.net/showthread.php?t=222822
__________________
blaacky is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 03-28-2018 , 07:35   Re: Creating zones & checking if client is inside a zone
Reply With Quote #3

See also: https://forums.alliedmods.net/showthread.php?p=2484926

Another method is also creating a trigger for the zone and hooking StartTouch and EndTouch
hmmmmm is offline
BraveFox
AlliedModders Donor
Join Date: May 2015
Location: Israel
Old 03-28-2018 , 08:03   Re: Creating zones & checking if client is inside a zone
Reply With Quote #4

Please Delete
__________________
Contact Me:
Steam: NoyB
Discord: Noy#9999
Taking Private Requests

Last edited by BraveFox; 10-25-2018 at 08:20.
BraveFox is offline
xFlane
AlliedModders Donor
Join Date: Nov 2017
Location: Israel
Old 03-28-2018 , 09:39   Re: Creating zones & checking if client is inside a zone
Reply With Quote #5

PHP Code:

public void CreateZoneEntity(int zoneIndex)
{
    
float fMiddle[3], fMins[3], fMaxs[3];
    
char sZoneName[64];

    
Array_Copy(g_mapZones[zoneIndex][PointA], fMins3); // fMins - PointA
    
Array_Copy(g_mapZones[zoneIndex][PointB], fMaxs3); // fMaxs - PointB

    
Format(sZoneNamesizeof(sZoneName), "%s"g_mapZones[zoneIndex][zoneName]);

    
int iEnt CreateEntityByName("trigger_multiple");

    if (
iEnt && IsValidEntity(iEnt)) {
        
SetEntityModel(iEntZONE_MODEL); // "models/props/de_train/barrel.mdl"
        // Spawnflags:    1 - only a player can trigger this by touch, makes it so a NPC cannot fire a trigger_multiple
        // 2 - Won't fire unless triggering ent's view angles are within 45 degrees of trigger's angles (in addition to any other conditions), so if you want the player to only be able to fire the entity at a 90 degree angle you would do ",angles,0 90 0," into your spawnstring.
        // 4 - Won't fire unless player is in it and pressing use button (in addition to any other conditions), you must make a bounding box,(max\mins) for this to work.
        // 8 - Won't fire unless player/NPC is in it and pressing fire button, you must make a bounding box,(max\mins) for this to work.
        // 16 - only non-player NPCs can trigger this by touch
        // 128 - Start off, has to be activated by a target_activate to be touchable/usable
        // 256 - multiple players can trigger the entity at the same time
        
DispatchKeyValue(iEnt"spawnflags""257");
        
DispatchKeyValue(iEnt"StartDisabled""0");

        
Format(sZoneNamesizeof(sZoneName), "sm_ckZone %i"zoneIndex);
        
DispatchKeyValue(iEnt"targetname"sZoneName);
        
DispatchKeyValue(iEnt"wait""0");

        if (
DispatchSpawn(iEnt))
        {
            
ActivateEntity(iEnt);
            
GetMiddleOfABox(fMinsfMaxsfMiddle);
            
TeleportEntity(iEntfMiddleNULL_VECTORNULL_VECTOR);

            
// Have the mins always be negative
            
for(int i 03i++){
                
fMins[i] = fMins[i] - fMiddle[i];
                if(
fMins[i] > 0.0)
                    
fMins[i] *= -1.0;
            }

            
// And the maxs always be positive
            
for(int i 03i++){
                
fMaxs[i] = fMaxs[i] - fMiddle[i];
                if(
fMaxs[i] < 0.0)
                    
fMaxs[i] *= -1.0;
            }

            
SetEntPropVector(iEntProp_Send"m_vecMins"fMins);
            
SetEntPropVector(iEntProp_Send"m_vecMaxs"fMaxs);
            
SetEntProp(iEntProp_Send"m_nSolidType"2);

            
int iEffects GetEntProp(iEntProp_Send"m_fEffects");
            
iEffects |= 0x020;

            
SetEntProp(iEntProp_Send"m_fEffects"iEffects);
            
SDKHook(iEntSDKHook_StartTouchStartTouchTrigger);
            
SDKHook(iEntSDKHook_EndTouchEndTouchTrigger);
        }
        else
        {
            
LogError("Not able to dispatchspawn for Entity %i in SpawnTrigger"iEnt);
        }
    }
}

stock void GetMiddleOfABox(const float vec1[3], const float vec2[3], float buffer[3])
{
    
float mid[3];
    
MakeVectorFromPoints(vec1vec2mid);
    
mid[0] = mid[0] / 2.0;
    
mid[1] = mid[1] / 2.0;
    
mid[2] = mid[2] / 2.0;
    
AddVectors(vec1midbuffer);

source code: https://github.com/nikooo777/ckSurf/...f/surfzones.sp

you can use this code to create an entity and check if the player inside by hooking StartTouch and EndTouch.
__________________
Taking private requests.
xFlane is offline
BraveFox
AlliedModders Donor
Join Date: May 2015
Location: Israel
Old 03-28-2018 , 17:37   Re: Creating zones & checking if client is inside a zone
Reply With Quote #6

Please Delete
__________________
Contact Me:
Steam: NoyB
Discord: Noy#9999
Taking Private Requests

Last edited by BraveFox; 10-25-2018 at 08:20.
BraveFox is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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