AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Specific player can touch only specific entity (https://forums.alliedmods.net/showthread.php?t=242409)

Bladell 06-19-2014 05:21

Specific player can touch only specific entity
 
I have this plugin
PHP Code:

/*
Name: [ZP] Addon: Bonus Box
Author: PomanoB & STRELOK
Version 1.0

Based on [ZP] DM Item's by PomanoB
*/
#include <superheromod>
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <fakemeta_util>
#include <hamsandwich>

#define PLUGIN "[ZP] Addon: Bonus Box"
#define VERSION "1.0"
#define AUTHOR "PomanoB & Accelerator"

new const item_class_name[] = "dm_item"

new g_models[][] = {"models/shero/presents.mdl"}

public 
plugin_precache()
{
    for (new 
0sizeof g_modelsi++)
        
precache_model(g_models[i])    
}


public 
round_start()
{
    new 
ent FM_NULLENT
    
static string_class[] = "classname"
    
while ((ent engfunc(EngFunc_FindEntityByStringentstring_classitem_class_name))) 
        
set_pev(entpev_flagsFL_KILLME)
}

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_forward(FM_Touch"fwd_Touch")
    
    
register_event("HLTV""round_start""a""1=0""2=0")
    
    
RegisterHam(Ham_Killed"player""fw_PlayerKilled")
    
    
register_dictionary("bonus_box.txt")
}

public 
show_hud()
{
    new 
Player[32], playerCount
    
    get_players
(PlayerplayerCount"c")
    
    
set_hudmessage(225000.990.15clamp(102), 6.01800.06.06.0, -1)
    
    for(new 
id=1id <= playerCountid++)
    {
        if(!
is_user_alive(Player[id]))
            
ShowSyncHudMsg(Player[id], CreateHudSyncObj(), "Bonus boxes event!")
    }
}

public 
fwd_Touch(touchertouched)
{
    if (!
is_user_alive(toucher) || !pev_valid(touched))
        return 
FMRES_IGNORED
    
    
new classname[32]    
    
pev(touchedpev_classnameclassname31)
    if (!
equal(classnameitem_class_name))
        return 
FMRES_IGNORED
    
    
    
    shgive_item
(toucher)
    
set_pev(touchedpev_effectsEF_NODRAW)
    
set_pev(touchedpev_solidSOLID_NOT)
    
    return 
FMRES_IGNORED
    
}

public 
fw_PlayerKilled(victimattackershouldgib)
{
    if (!
is_user_connected(attacker) || !is_user_connected(victim) || attacker == victim || !attacker)
        return 
HAM_IGNORED
    
    
    
new random random_num(09)
    
    new 
hour[3]
    
    
get_time("%H"hour2)
    
    if(
str_to_num(hour) == 20)
    {
        if (
random <= 5)
        {
            new 
origin[3]
            
get_user_origin(victimorigin0)
            
            
addItem(origin)
            
            if(!
task_exists(2212))
                
set_task(1.0"show_hud"2212__"b")
        }
    }
    else if(
random == 5)
    {
        new 
origin[3]
        
get_user_origin(victimorigin0)
        
        
addItem(origin)
        
        if(
task_exists(2212))
            
remove_task(2212)
    }
        
    return 
HAM_IGNORED
}

public 
removeEntity(ent)
{
    if (
pev_valid(ent))
        
engfunc(EngFunc_RemoveEntityent)
}

public 
addItem(origin[3])
{
    new 
ent fm_create_entity("info_target")
    
set_pev(entpev_classnameitem_class_name)
    
    
engfunc(EngFunc_SetModel,entg_models[random_num(0sizeof g_models 1)])

    
set_pev(ent,pev_mins,Float:{-10.0,-10.0,0.0})
    
set_pev(ent,pev_maxs,Float:{10.0,10.0,25.0})
    
set_pev(ent,pev_size,Float:{-10.0,-10.0,0.0,10.0,10.0,25.0})
    
engfunc(EngFunc_SetSize,ent,Float:{-10.0,-10.0,0.0},Float:{10.0,10.0,25.0})

    
set_pev(ent,pev_solid,SOLID_BBOX)
    
set_pev(ent,pev_movetype,MOVETYPE_FLY)
    
    new 
Float:fOrigin[3]
    
IVecFVec(originfOrigin)
    
set_pev(entpev_originfOrigin)
    
    
set_pev(ent,pev_renderfx,kRenderFxGlowShell)
    switch(
random_num(1,4))
    {
        case 
1set_pev(ent,pev_rendercolor,Float:{0.0,0.0,255.0})
        case 
2set_pev(ent,pev_rendercolor,Float:{0.0,255.0,0.0})
        case 
3set_pev(ent,pev_rendercolor,Float:{255.0,0.0,0.0})
        case 
4set_pev(ent,pev_rendercolor,Float:{255.0,255.0,255.0})
    }


When somebody dies a box is let behind and if someone touch it will receive something. It want to change this plugin... only the player who killed the victim can touch the box left by victim and receive the bonus, or at least the toucher id team != victim id team

I know that function shgive_item is missing, there is nothing that I could change to make this plugin as I want.

Nextra 06-19-2014 06:47

Re: Specific player can touch only specific entity
 
Set pev_owner to the user that should be able to pick it up and then compare pev_owner in the touch forward. Also why do you set EF_NODRAW and SOLID_NOT and only delete the entities on new round? You should delete them immediately.

/edit: SpeeDeeR is correct. You would probably want to use pev_iuser.

SpeeDeeR 06-19-2014 08:30

Re: Specific player can touch only specific entity
 
Setting pev_owner will make the box not interactable with the owner. You could use groupinfo or if you want all players to see the box, set the killers index in a costume pev, like iuser, and check it on touch.

Bladell 06-19-2014 09:39

Re: Specific player can touch only specific entity
 
@Nextra This plugin isn't made by me... box disappear automatically when somebody touch it.
@SpeeDeeR I have no ideea about what are you talking about, and example would be great.

aron9forever 06-19-2014 15:00

Re: Specific player can touch only specific entity
 
Quote:

Originally Posted by Bladell (Post 2154061)
@Nextra This plugin isn't made by me... box disappear automatically when somebody touch it.
@SpeeDeeR I have no ideea about what are you talking about, and example would be great.

post in the plugin's topic or in the request forum

Bladell 06-22-2014 08:40

Re: Specific player can touch only specific entity
 
That topic is dead, I can modify it...
I tried with pev_owner, but as far as I know, the entity will be automatically set set_pev(touched, pev_solid, SOLID_NOT) for owner. This mean that the owner can't touch the box, it will walk trough it.
Function public fwd_Touch(toucher, touched) will not work for owner, so the owner can't receive the bonus.

SpeeDeeR 06-22-2014 10:40

Re: Specific player can touch only specific entity
 
Quote:

Originally Posted by SpeeDeeR (Post 2154013)
Setting pev_owner will make the box not interactable with the owner. You could use groupinfo or if you want all players to see the box, set the killers index in a costume pev, like iuser, and check it on touch.


Bladell 06-22-2014 12:24

Re: Specific player can touch only specific entity
 
Thank you!

Compidence 06-22-2014 12:30

Re: Specific player can touch only specific entity
 
Quote:

Originally Posted by Bladell (Post 2154061)
@Nextra This plugin isn't made by me... box disappear automatically when somebody touch it.
@SpeeDeeR I have no ideea about what are you talking about, and example would be great.

What SpeeDeeR is saying is use pev_iuser1, like you would use pev_owner to store the owner of the entity. Or in your case, use it to store the id of the killer. Then on touch [when someone touches the entity] check if the id = pev_iuser1, if it does then you got your guy.

set_pev(ent, pev_iuser1, id);
if(pev(ent, pev_iuser1) == id);


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

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