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

drop flag JCTF


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
yagami
Senior Member
Join Date: Jan 2021
Old 07-29-2023 , 14:14   drop flag JCTF
Reply With Quote #1

How to make paraplayer release the flag after a certain time, because there are players who keep the flag and do not deliver it, it spoils the gameplay of other players

PHP Code:
public player_dropFlag(id)
{
    new 
iOpTeam get_opTeam(g_iTeam[id])

    if(
id != g_iFlagHolder[iOpTeam])
        return

    new 
ent g_iFlagEntity[iOpTeam]

    if(!
is_valid_ent(ent))
        return

    
g_fLastDrop[id] = get_gametime() + 2.0
    g_iFlagHolder
[iOpTeam] = FLAG_HOLD_DROPPED

    entity_set_edict
(entEV_ENT_aiment, -1)
    
entity_set_int(entEV_INT_movetypeMOVETYPE_TOSS)
    
entity_set_int(entEV_INT_sequenceFLAG_ANI_DROPPED)
    
entity_set_int(entEV_INT_solidSOLID_TRIGGER)
    
entity_set_origin(entg_fFlagLocation[iOpTeam])

    new 
Float:fReturn get_pcvar_float(pCvar_ctf_flagreturn)

    if(
fReturn 0)
        
task_set(fReturn"flag_autoReturn"ent)

    if(
g_bAlive[id])
    {
        new 
Float:fVelocity[3]

        
velocity_by_aim(id200fVelocity)

        
fVelocity[z] = 0.0

        entity_set_vector
(entEV_VEC_velocityfVelocity)

        
player_updateSpeed(id)
        
player_updateRender(id)

        
message_begin(MSG_BROADCASTgMsg_ScoreAttrib)
        
write_byte(id)
        
write_byte(0)
        
message_end()
    }
    else
        
entity_set_vector(entEV_VEC_velocityFLAG_DROP_VELOCITY)

    new 
szName[32]

    
get_user_name(idszNamecharsmax(szName))

    
game_announce(EVENT_DROPPEDiOpTeamszName)

    
ExecuteForward(g_iFW_flagg_iForwardReturnFLAG_DROPPEDidiOpTeamfalse)

    
g_fFlagDropped[iOpTeam] = get_gametime()

    
log_message("<%s>%s dropped the ^"%s^" flag."g_szTeamName[g_iTeam[id]], szNameg_szTeamName[iOpTeam]) 
yagami is offline
yagami
Senior Member
Join Date: Jan 2021
Old 07-30-2023 , 12:41   Re: drop flag JCTF
Reply With Quote #2

This is the correct function


PHP Code:
public flag_think(ent)
{
    if(!
is_valid_ent(ent))
        return

    
entity_set_float(entEV_FL_nextthinkget_gametime() + FLAG_THINK)

    static 
id
    
static iStatus
    
static iFlagTeam
    
static iSkip[3]
    static 
Float:fOrigin[3]
    static 
Float:fPlayerOrigin[3]

    
iFlagTeam = (ent == g_iFlagEntity[TEAM_BLUE] ? TEAM_BLUE TEAM_RED)

    if(
g_iFlagHolder[iFlagTeam] == FLAG_HOLD_BASE)
        
fOrigin g_fFlagBase[iFlagTeam]
    else
        
entity_get_vector(entEV_VEC_originfOrigin)

    
g_fFlagLocation[iFlagTeam] = fOrigin

    iStatus 
0

    
if(++iSkip[iFlagTeam] >= FLAG_SKIPTHINK)
    {
        
iSkip[iFlagTeam] = 0

        
if(<= g_iFlagHolder[iFlagTeam] <= g_iMaxPlayers)
        {
            
id g_iFlagHolder[iFlagTeam]

            if(
szHuds[id])
            {
                
set_hudmessage(HUD_HELP)
                
ShowSyncHudMsg(idHUDINFO"%L"id"HUD_YOUHAVEFLAG")
            }

            
iStatus 1
        
}
        else if(
g_iFlagHolder[iFlagTeam] == FLAG_HOLD_DROPPED)
            
iStatus 2

        message_begin
(MSG_BROADCASTgMsg_HostagePos)
        
write_byte(0)
        
write_byte(iFlagTeam)
        
engfunc(EngFunc_WriteCoordfOrigin[x])
        
engfunc(EngFunc_WriteCoordfOrigin[y])
        
engfunc(EngFunc_WriteCoordfOrigin[z])
        
message_end()

        
message_begin(MSG_BROADCASTgMsg_HostageK)
        
write_byte(iFlagTeam)
        
message_end()

        static 
iStuck[3]

        if(
g_iFlagHolder[iFlagTeam] >= FLAG_HOLD_BASE && !(entity_get_int(entEV_INT_flags) & FL_ONGROUND))
        {
            if(++
iStuck[iFlagTeam] > 4)
            {
                
flag_autoReturn(ent)

                
log_message("^"%s^" flag is outside world, auto-returned."g_szTeamName[iFlagTeam])

                return
            }
        }
        else
            
iStuck[iFlagTeam] = 0
    
}

    for(
id 1id <= g_iMaxPlayersid++)
    {
        if(
g_iTeam[id] == TEAM_NONE || g_bBot[id])
            continue

        
/* Check flag proximity for pickup */
        
if(g_iFlagHolder[iFlagTeam] >= FLAG_HOLD_BASE)
        {
            
entity_get_vector(idEV_VEC_originfPlayerOrigin)

            if(
get_distance_f(fOriginfPlayerOrigin) <= FLAG_PICKUPDISTANCE)
                
flag_touch(entid)
        }

        
/* Send dynamic lights to players that have them enabled // ATIVA BRILHO DAS BANDEIRAS
        if(g_iFlagHolder[iFlagTeam] != FLAG_HOLD_BASE && g_bLights[id])
        {
            message_begin(MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, _, id)
            write_byte(TE_DLIGHT)
            engfunc(EngFunc_WriteCoord, fOrigin[x])
            engfunc(EngFunc_WriteCoord, fOrigin[y])
            engfunc(EngFunc_WriteCoord, fOrigin[z] + (g_iFlagHolder[iFlagTeam] == FLAG_HOLD_DROPPED ? 32 : -16))
            write_byte(FLAG_LIGHT_RANGE)
            write_byte(iFlagTeam == TEAM_RED ? 0 : 0)
            write_byte(0)
            write_byte(iFlagTeam == TEAM_BLUE ? 0 : 0)
            write_byte(FLAG_LIGHT_LIFE)
            write_byte(FLAG_LIGHT_DECAY)
            message_end()
        } */

        /* If iFlagTeam's flag is stolen or dropped, constantly warn team players */
        
if(iStatus && g_iTeam[id] == iFlagTeam)
        {
            if(
szHuds[id])
            {
                
set_hudmessage(HUD_HELP2)
                
ShowSyncHudMsg(idHUDINFO"%L"id, (iStatus == "HUD_ENEMYHASFLAG" "HUD_RETURNYOURFLAG"))
            }
        }
    }


Last edited by yagami; 07-30-2023 at 12:42.
yagami is offline
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 07-30-2023 , 18:45   Re: drop flag JCTF
Reply With Quote #3

you need to save the time in unix when flag was picked up and a clock that will drop it if player held it for to long.
maybe consider killing because dropping at the same spot will also trigger pickup function
__________________
bigdaddy424 is offline
yagami
Senior Member
Join Date: Jan 2021
Old 07-30-2023 , 20:17   Re: drop flag JCTF
Reply With Quote #4

Quote:
Originally Posted by bigdaddy424 View Post
you need to save the time in unix when flag was picked up and a clock that will drop it if player held it for to long.
maybe consider killing because dropping at the same spot will also trigger pickup function
the Problem and how to do this, I have no idea how to do this can you help me please
yagami is offline
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 07-30-2023 , 21:48   Re: drop flag JCTF
Reply With Quote #5

something like this

PHP Code:
new const TASKID_DROPFLAG MAX_PLAYERS MAX_PLAYERS
new const minutes 1

public client_disconnected(id){
    if (
task_exists(TASKID_DROPFLAG+id))
        
remove_task(TASKID_DROPFLAG+id)
}

// function flag pickup
    
if (task_exists(TASKID_DROPFLAG+id))
        
remove_task(TASKID_DROPFLAG+id)
    
set_task(float(minutes*60), "drop_flag"TASKID_DROPFLAG+id)

public 
drop_flag(id){
    
id -= TASKID_DROPFLAG
    
if (is_user_alive(id) && ??HAS_PLAYER_FLAG(id))
        
player_dropFlag(id)

__________________
bigdaddy424 is offline
yagami
Senior Member
Join Date: Jan 2021
Old 07-31-2023 , 01:18   Re: drop flag JCTF
Reply With Quote #6

Quote:
Originally Posted by bigdaddy424 View Post
something like this

PHP Code:
new const TASKID_DROPFLAG MAX_PLAYERS MAX_PLAYERS
new const minutes 1

public client_disconnected(id){
    if (
task_exists(TASKID_DROPFLAG+id))
        
remove_task(TASKID_DROPFLAG+id)
}

// function flag pickup
    
if (task_exists(TASKID_DROPFLAG+id))
        
remove_task(TASKID_DROPFLAG+id)
    
set_task(float(minutes*60), "drop_flag"TASKID_DROPFLAG+id)

public 
drop_flag(id){
    
id -= TASKID_DROPFLAG
    
if (is_user_alive(id) && ??HAS_PLAYER_FLAG(id))
        
player_dropFlag(id)

Can you use your own capture flag task to do this because it already has a task there like this

PHP Code:
enum 
{
    
FLAG_STOLEN 0,
    
FLAG_PICKED,
    
FLAG_DROPPED,
    
FLAG_MANUALDROP,
    
FLAG_RETURNED,
    
FLAG_CAPTURED,
    
FLAG_AUTORETURN,
    
FLAG_ADMINRETURN
}

if(
g_iFlagHolder[iFlagTeam] >= FLAG_HOLD_BASE && !(entity_get_int(entEV_INT_flags) & FL_ONGROUND))
        {
            if(++
iStuck[iFlagTeam] > 4)
            {
                
flag_autoReturn(ent)

                
log_message("^"%s^" flag is outside world, auto-returned."g_szTeamName[iFlagTeam])

                return
            }
        }


public 
flag_autoReturn(ent)
{
    
task_remove(ent)

    new 
iFlagTeam = (g_iFlagEntity[TEAM_BLUE] == ent TEAM_BLUE : (g_iFlagEntity[TEAM_RED] == ent TEAM_RED 0))

    if(!
iFlagTeam)
        return

    
flag_sendHome(iFlagTeam)

    
ExecuteForward(g_iFW_flagg_iForwardReturnFLAG_AUTORETURN0iFlagTeamfalse)

    
game_announce(EVENT_RETURNEDiFlagTeamNULL)

    
log_message("^"%s^" flag returned automatically"g_szTeamName[iFlagTeam])
}

if(
fReturn 0)
        
task_set(fReturn"flag_autoReturn"ent
yagami is offline
mlibre
Veteran Member
Join Date: Nov 2015
Location: return PLUGIN_CONTINUE
Old 07-31-2023 , 18:06   Re: drop flag JCTF
Reply With Quote #7

locate this and add TASK_FLAG here

Code:
enum (+= 64) {     TASK_RESPAWN = 64,     TASK_PROTECTION,     TASK_DAMAGEPROTECTION,     TASK_EQUIPAMENT = 64,     TASK_TEAMBALANCE,     TASK_ADRENALINE,     TASK_DEFUSE,     TASK_FLAG }

then at the end of the code

PHP Code:
new g_pFlag[33]

public 
task_flag(id
{
    
id += TASK_FLAG
    
    
if(g_pFlag[id] && get_user_health(id) > 0
    {
        
user_slap(id200)
        
        
task_set(15.0"task_flag"id TASK_FLAG)
            
        
client_print(id4"what the hell are you doing? hand over the flag!")
    }
}

public 
jctf_flag(eventidflagteambool:bAssist
{
    if( !
is_user_connected(id) ) 
        return
    
    switch(
event
    {
        case 
FLAG_STOLENFLAG_PICKED
        {
            
g_pFlag[id] = 1
                
            task_set
(30.0"task_flag"id TASK_FLAG)
        }
        case 
FLAG_DROPPEDFLAG_CAPTUREDFLAG_ADMINRETURNFLAG_MANUALDROP
        {
            
g_pFlag[id] = 0
            
            task_remove
(id TASK_FLAG)
            
        }
    }

__________________
mlibre is offline
yagami
Senior Member
Join Date: Jan 2021
Old 08-02-2023 , 15:03   Re: drop flag JCTF
Reply With Quote #8

Quote:
Originally Posted by mlibre View Post
locate this and add TASK_FLAG here

Code:
enum (+= 64) {     TASK_RESPAWN = 64,     TASK_PROTECTION,     TASK_DAMAGEPROTECTION,     TASK_EQUIPAMENT = 64,     TASK_TEAMBALANCE,     TASK_ADRENALINE,     TASK_DEFUSE,     TASK_FLAG }

then at the end of the code

PHP Code:
new g_pFlag[33]

public 
task_flag(id
{
    
id += TASK_FLAG
    
    
if(g_pFlag[id] && get_user_health(id) > 0
    {
        
user_slap(id200)
        
        
task_set(15.0"task_flag"id TASK_FLAG)
            
        
client_print(id4"what the hell are you doing? hand over the flag!")
    }
}

public 
jctf_flag(eventidflagteambool:bAssist
{
    if( !
is_user_connected(id) ) 
        return
    
    switch(
event
    {
        case 
FLAG_STOLENFLAG_PICKED
        {
            
g_pFlag[id] = 1
                
            task_set
(30.0"task_flag"id TASK_FLAG)
        }
        case 
FLAG_DROPPEDFLAG_CAPTUREDFLAG_ADMINRETURNFLAG_MANUALDROP
        {
            
g_pFlag[id] = 0
            
            task_remove
(id TASK_FLAG)
            
        }
    }

Here on the servers there is a competitive way to pick up flags, they are 10x10, is there anyone way to put a cvar like this where I can choose time and also the following
have the option of if the flag is not delivered in the stipulated time the team that has flag scores how to do this?

So it would be like this if the team does not deliver the flag in the stipulated time or player dies or takes slap or flag back to base

for competitive mode after player takes flag the team scores if the team can hold flag for a while

I tried to use else if for this but I think it is not how it is done

your code worked here perfectly
yagami is offline
yagami
Senior Member
Join Date: Jan 2021
Old 08-03-2023 , 07:33   Re: drop flag JCTF
Reply With Quote #9

Can anyone tell me where I went wrong?

if both flags are outside the base it returns to base

if only one flag is stolen it executes the task


PHP Code:
public task_flag(id
{
    
id += TASK_FLAG

    
for(new iFlagTeam TEAM_REDiFlagTeam <= TEAM_BLUEiFlagTeam++) // If both flags are off base
    
{
        new 
iTime get_systime();

        if(
iTime 0)
        {
            
ShowSyncHudMsg(idg_iSync[1], "THE FLAGS WILL RETURN TO THE BASE AND %d"iTime);
            
task_set(iTime"flag_autoReturn"id FLAG_AUTORETURN)
        }
    }
    
    if(
get_pcvar_num(pCvar_ctf_flagreturnplayer)) // If only one flag is stolen
    
{
        if(
g_pFlag[id] && get_user_health(id) > 0

            
task_set(30"task_flag"id FLAG_AUTORETURN)
            
user_slap(id200)
                
            
client_print(id4"What the hell are you doing? Hand over the flag!")
        }
    }   
}

public 
jctf_flag(eventidflagteambool:bAssist
{
    if(!
is_user_connected(id)) 
        return
    
    switch(
event
    {
        case 
FLAG_STOLENFLAG_PICKED
        {
            
g_pFlag[id] = 1

            
new iTime get_pcvar_num(pCvar_ctf_flagreturntime)
                
            
task_set(iTime"task_flag"id TASK_FLAG)
        }
        case 
FLAG_DROPPEDFLAG_CAPTUREDFLAG_ADMINRETURNFLAG_MANUALDROP
        {
            
g_pFlag[id] = 0
            
            task_remove
(id TASK_FLAG)
            
        }
    }

yagami 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 05:57.


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