AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HL1] Hooking Keyvalue on entities not in gametype (https://forums.alliedmods.net/showthread.php?t=229165)

HLM 11-02-2013 14:04

[HL1] Hooking Keyvalue on entities not in gametype
 
Hello, I am working on a plugin to add more support to my game for maps that were not originally meant for my game, HLDM maps are very popular in TFC as they are open world deathmatches, I am trying to hook all of the weapons that the engine drops (because no equivalent item is in the engine for this game) and implement the closest equivalent I can find.. the problem is, I cant seem to grab any entities other than those that are added to the game (weapon_grenade) and I do know for a fact that these entities are in the map (bsp file contains the entity info)

I am properly hooking the function in plugin_precache and can confirm that it is running, and it even sends my data to the logfile I specified, however it only works for entities that it would normally spawn.. is there any way to achieve what I am trying to do?

PHP Code:

public plugin_precache()
{
    
//
    
register_forward(FM_KeyValue"hook_KeyValue")
}

public 
hook_KeyValue(entIdkvd_id)
{
    
//
    
if(!pev_valid(entId))
        return 
FMRES_HANDLED;
    
    new 
className[64];
    
pev(entIdpev_classnameclassName63);
    
    if (
containi(className"weapon_") !=-1)
    {
        new 
model[64], Float:origin[3]
        
pev(entIdpev_modelmodelcharsmax(model));
        
pev(entIdpev_originorigin);
        
        
log_to_file("hldm.log""Found entity %s with model %s, location: {%f, %f, %f}"classNamemodelorigin[0], origin[1], origin[2])
    }
    return 
FMRES_IGNORED;


EDIT: I have achieved the value by using engine: http://forums.alliedmods.net/showthr...=205578&page=2

PHP Code:

public pfn_keyvalue(entid)
{
    new 
classname[32], key[32], value[32]
    
copy_keyvalue(classname31key31value31)

    if( (
equal(key"classname")) && (containi(value"weapon_") != -1) )
    {
        
log_to_file("hldm.log""Weapon_* Key: %s Value: %s"keyvalue);
        
//server_print("FOUND!")
        //DispatchKeyValue("classname", "func_wall")
    
}


how will I be able to use this to get ther other keyvalues on this entity? I am going to try and change the if to a while and hope for good results.

ConnorMcLeod 11-02-2013 16:01

Re: [HL1] Hooking Keyvalue on entities not in gametype
 
Just don't filter key = "classname" and you gonna catch other properties.

HLM 11-02-2013 20:32

Re: [HL1] Hooking Keyvalue on entities not in gametype
 
Quote:

Originally Posted by ConnorMcLeod (Post 2056126)
Just don't filter key = "classname" and you gonna catch other properties.

Got it, thanks.

Solution:
PHP Code:

public pfn_keyvalue(entid)
{
    new class[
32], key[32], value[32]
    
copy_keyvalue(class, 31key31value31)
    
    
log_to_file("ents.log","ClassName : %s  KeyName : %s  KeyValue : %s",class, keyvalue)
    
    if(
containi(class, "weapon_")!=-1)
        
log_to_file("weapon.log","ClassName : %s  KeyName : %s  KeyValue : %s",class, keyvalue)
    if(
containi(class, "ammo_")!=-1)
        
log_to_file("ammo.log","ClassName : %s  KeyName : %s  KeyValue : %s",class, keyvalue)



ConnorMcLeod 11-02-2013 20:47

Re: [HL1] Hooking Keyvalue on entities not in gametype
 
You wanna change ground weapons ?
What do you want to do exactly ?
Sounds like x y problem.

HLM 11-02-2013 22:36

Re: [HL1] Hooking Keyvalue on entities not in gametype
 
Yes, I am using hldm maps on my server, but my game doesnt have those weapons, I want to grab the info from the keyvalues and spawn the closest equivalent.. for example, weapon_shotgun -> tfc_wpn_supershotgun weapon_rpg -> tfc_wpn_rpg etc.

Please note: these entities are never created as the engine drops them because they do not exist in the game.

new question: I am using weapon_handgrenade to give users grenades, but only the first one they pick up disappears from the map, what controls them 'having' the grenade? I have tried many things but havent found anything yet. :/

PHP Code:

            if(equali(className"weapon_handgrenade"))
            {
                
//give nades or something
                
client_print(0print_chat"%d picked up a handgrenade"id);
                new 
nade1=tfc_getbammo(idTFC_AMMO_NADE1);
                new 
nade2=tfc_getbammo(idTFC_AMMO_NADE2);
                new class=
entity_get_int(idEV_INT_playerclass)
                if(
user_has_weapon(idHLW_HANDGRENADE))
                {
                    
client_print(0print_chat"User has grenade, removing.")
                    
user_has_weapon(idHLW_HANDGRENADE0)
                }
                
                if(class == 
2)
                    
nade2=9
                
if(nade1 nade2)
                {
                    
tfc_setbammo(idTFC_AMMO_NADE2nade2+1)
                    
client_print(0print_chat"nade1=%d NADE2=%d"tfc_getbammo(idTFC_AMMO_NADE1), tfc_getbammo(idTFC_AMMO_NADE2))
                }
                else
                {
                    
tfc_setbammo(idTFC_AMMO_NADE1nade1+1)
                    
client_print(0print_chat"NADE1=%d nade2=%d"tfc_getbammo(idTFC_AMMO_NADE1), tfc_getbammo(idTFC_AMMO_NADE2))
                }
            } 


ConnorMcLeod 11-03-2013 02:43

Re: [HL1] Hooking Keyvalue on entities not in gametype
 
So, you could use that : http://forums.alliedmods.net/showthread.php?p=1647630


All times are GMT -4. The time now is 23:15.

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