AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Monster Mod (https://forums.alliedmods.net/showthread.php?t=109986)

solano 11-23-2009 13:13

Monster Mod
 
Hi im trying to make a fun mod for half life where you kill monsters and see who can kill the most for a set period of time.

There are three thing i need help with.First is how can i spawn the on specific points on the map and the second is how to see which player killed the monster and give him a frag and the third and final is how to monitor the monster count and if they are below a certain amount spawn some more.
Here is a script i have that has spawn,remove and other functions:
Code:

/***************************************************************************************************
                                AMX Monster
         
  Version: 0.3
  Author: KRoTaL (Translated from AMX to AMXX by ^Bend3R
 

    You have to install Monster Mod.



Commands:

  amx_monster <name, #userid, authid, @TERRORIST, @CT, * (all)> <monster> <number>

      monster: name of the monster you want to spawn (must be precached in the monster_precache.cfg file)
      number: number of monsters you want to spawn

  amx_findmonsters    -    displays in the console all the monsters which are on the map

  amx_removemonsters <monster> <number>

    name: name of the monster you want to remove (zombie, islave, agrunt...)
    number: number of monsters you want to remove (type 0 to remove all the monsters with this name)

  amx_monstermodel <model>

    Changes the models of all the monsters alive.
    model: path of the model without "models/" (droide.mdl, cow.mdl, ...)
    You have to precache the models in the plugin_precache function (at the bottom of this file).
    Use Half-Life models else monsters will be stuck in the ground.

 Examples:
 
  amx_monster joe snark 10
  amx_monster @CT zombie 3
  amx_removemonsters zombie 5
  amx_monstermodel droide.mdl        (droide.mdl is here: models/droide.mdl)


  You must have ADMIN_SLAY flag to use these commands.

***************************************************************************************************/

#include <amxmodx>
#include <amxmisc>
#include <Vexd_Utilities>

#define INTERVAL 0.3


public plugin_init()
{
    register_plugin("AMX Monster","0.3","KRoTaL")
    register_concmd("amx_monster","admin_monster",ADMIN_SLAY,"<name/id/authid/@CT/@TERRORIST/ * (all)> <monster> <number>")
    register_concmd("amx_findmonsters","find_monsters", ADMIN_SLAY, "displays all the monsters")
    register_concmd("amx_removemonsters","remove_monsters", ADMIN_SLAY, "amx_removemonsters <name> <number (0 for all)>")
    register_concmd("amx_monstermodel","monstermodel", ADMIN_SLAY, "<model>")

    return PLUGIN_CONTINUE
}

public admin_monster(id,level,cid)
{
    if (!cmd_access(id,level,cid,4))
    {
        return PLUGIN_HANDLED
    }

    new arg1[32], monster[32], arg3[9]
    read_argv(1,arg1,31)
    read_argv(2,monster,31)
    read_argv(3,arg3,8)
    new num_monsters
    num_monsters = str_to_num(arg3)
    if(num_monsters<1)
        num_monsters=1
    new i
    new admin_name[33]
    get_user_name(id, admin_name, 32)

    if(arg1[0] == '@')
    {
        new users[32], inum
        get_players(users, inum, "ae", arg1[1])
        if(inum == 0)
        {
              console_print(id, "No users in such team")
              return PLUGIN_HANDLED
        }
        for(i = 0; i < inum; ++i)
        {
            new param[34]
            copy(param,33,monster)
            param[32]=users[i]
            set_task(INTERVAL, "spawn_monster", 124512+users[i], param, 33, "a", num_monsters-1) 
        }
        switch(get_cvar_num("amx_show_activity"))
        {
            case 2: client_print(0,print_chat,"ADMIN %s: spawned %d %s%s on %s Team.",admin_name,num_monsters,monster,(num_monsters>1)?"s":"",arg1[1])
            case 1: client_print(0,print_chat,"ADMIN: spawned %d %s%s on %s Team.",num_monsters,monster,(num_monsters>1)?"s":"",arg1[1])
        }
        console_print(id,"You spawned %d %s%s on %s Team.",num_monsters,monster,(num_monsters>1)?"s":"",arg1[1])
    }
    else if(arg1[0] == '*')
    {
        new users[32], inum
        get_players(users, inum)
        if(inum == 0)
        {
              console_print(id, "No users in such team")
              return PLUGIN_HANDLED
        }   
        for(i = 0; i < inum; ++i)
        {
            new param[34]
            copy(param,33,monster)
            param[32]=users[i]
            set_task(INTERVAL, "spawn_monster", 124512+users[i], param, 33, "a", num_monsters-1) 
        }
        switch(get_cvar_num("amx_show_activity"))
        {
            case 2: client_print(0,print_chat,"ADMIN %s: spawned %d %s%s on everybody.",admin_name,num_monsters,monster,(num_monsters>1)?"s":"")
            case 1: client_print(0,print_chat,"ADMIN: spawned %d %s%s on everybody.",num_monsters,monster,(num_monsters>1)?"s":"")
        }
        console_print(id,"You spawned %d %s%s on everybody.",num_monsters,monster,(num_monsters>1)?"s":"")
    }
    else
    {
        new victim = cmd_target(id,arg1,6)
        if (!victim)
            return PLUGIN_HANDLED

        new victim_name[33]
        get_user_name(victim, victim_name, 32)

        new param[34]
        copy(param,33,monster)
        param[32]=victim

        set_task(INTERVAL, "spawn_monster", 124512+victim, param, 33, "a", num_monsters-1) 
        switch(get_cvar_num("amx_show_activity"))
        {
            case 2: client_print(0,print_chat,"ADMIN %s: spawned %d %s%s on %s.",admin_name,num_monsters,monster,(num_monsters>1)?"s":"",victim_name)
            case 1: client_print(0,print_chat,"ADMIN: spawned %d %s%s on %s.",num_monsters,monster,(num_monsters>1)?"s":"",victim_name)
        }
        console_print(id,"You spawned %d %s%s on %s.",num_monsters,monster,(num_monsters>1)?"s":"",victim_name)
    }

    return PLUGIN_HANDLED
}

public spawn_monster(param[])
{
    new monster[32]
    copy(monster,31,param)
    server_cmd("monster %s #%d", monster, param[32])
}

public find_monsters(id,level,cid)
{
    if (!cmd_access(id,level,cid,1))
    {
        return PLUGIN_HANDLED
    }

    new monsters_num = 0
    new monster = find_ent_by_class(-1, "func_wall")
    while(monster > 0)
    {
        if(entity_get_int(monster, EV_INT_movetype) == 4)
        {
            monsters_num++
            new model[32]
            entity_get_string(monster, EV_SZ_model, model, 31)
            while(replace(model, 31, "models/", "") && replace(model, 31, ".mdl", "")) {}
            console_print(id, "Monster #%i: %s", monsters_num, model)
        }
        monster = find_ent_by_class(monster, "func_wall")
    }
    return PLUGIN_HANDLED
}

public remove_monsters(id,level,cid)
{
    if (!cmd_access(id,level,cid,3))
    {
        return PLUGIN_HANDLED
    }

    new arg1[32]
    read_argv(1, arg1, 31)
    new arg2[32]
    read_argv(2, arg2, 31)

    new num_to_remove = str_to_num(arg2)

    new monsters_num = 0
    new bool:remove = true

    new monster = find_ent_by_class(-1, "func_wall")
    while(monster > 0 && remove)
    {
        new monster_model[32]
        entity_get_string(monster, EV_SZ_model, monster_model, 31)
        if(containi(monster_model, arg1) != -1)
        {
            monsters_num++
            remove_entity(monster)
            if(monsters_num == num_to_remove)
                remove = false
            monster = find_ent_by_class(-1, "func_wall")
        }
        else
        {
            monster = find_ent_by_class(monster, "func_wall")
        }
    }
    if(monsters_num > 0)
    {
        if(num_to_remove < 1)
            console_print(id, "All the %ss have been removed.", arg1)
        else
            console_print(id, "%d %s%s ha%s been removed.", num_to_remove, arg1, (num_to_remove>1)?"s":"", (num_to_remove>1)?"ve":"s")   
    }
    else
    {
        console_print(id, "There are no %ss.", arg1)
    }
    return PLUGIN_HANDLED
}

public monstermodel(id,level,cid)
{
    if (!cmd_access(id,level,cid,2))
    {
        return PLUGIN_HANDLED
    }

    new arg1[64]
    read_argv(1, arg1, 63)

    format(arg1, 63, "models/%s", arg1)

    new monster = find_ent_by_class(-1, "func_wall")
    while(monster > 0)
    {
        if(entity_get_int(monster, EV_INT_movetype) == 4)
        {
            entity_set_model(monster, arg1)
        }
        monster = find_ent_by_class(monster, "func_wall")
    }
    console_print(id, "You changed the models of all the monsters.")

    return PLUGIN_HANDLED
}

public plugin_precache()
{
    precache_model("models/hgrunt.mdl")
    precache_model("models/agrunt.mdl")
    precache_model("models/zombie.mdl")
    precache_model("models/houndeye.mdl")
}

i can also give you the source of the monster mod dll file.

Arkshine 11-23-2009 13:38

Re: Monster Mod
 
for HL ? Don't use MonsterMod so, because you have the monster entities already integrated into the game.

solano 11-23-2009 13:58

Re: Monster Mod
 
then what should i use create_entity ( "zombie" )
and what about creating them at certain locations and adding frags to the player who killed the monster

Arkshine 11-23-2009 14:06

Re: Monster Mod
 
Yes, monster_* entity.

Since you are not willing to code yourself the plugin, you should post in the Request section, though it would be nice if a moderator can move this thread.

solano 11-23-2009 14:09

Re: Monster Mod
 
no yoube got it wrong i am willing to code it myself its just i dont know the available functions.i went through some documentation but couldn't find the right functions and i dont know certain variables(spawn points, enteteis , hud messages,i hope you understand me)

EDIT:thanks for the entity guide it will be very helpfull
EDIT#2:
Code:

public plugin_init()

 
//Only called if killer is not worldspawn 
 
register_event("DeathMsg", "hook_death", "a", "1>0")
}

public
hook_death()

  new
Killer = read_data(1)
  new
Victim = read_data(2)
  new frags=
get_user_frags(Killer)
    set_user_frags ( index, frags+1 ) 
}


Will this work?

Arkshine 11-23-2009 14:33

Re: Monster Mod
 
About creating at certain location, you would need to pre-create them. If you know CSDM Spawn Editor ; you would need something like that to save the origin/angles of the locations you want for one map. Then you could read one time this file for the current map, and spawing monsters at those locations. I suggest to see yourself the code to understand better. I'm lazy to show a full example when you have already some plugins which does such thing. :p

solano 11-23-2009 14:36

Re: Monster Mod
 
Thank you arkshine youve been very helpfull ill try the things you suggesting in your last post and will tell you the results

Arkshine 11-23-2009 14:38

Re: Monster Mod
 
About the frag, I'm not sure, but you can try this hook :

Code:
RegisterHam( Ham_Killed, "func_wall", "Monster_Killed", 1 ); public Monster_Killed ( const Monster, const Attacker ) {      if ( is_user_alive( Attacker ) )      {            set_user_frags( Attacker, get_user_frags( Attacker ) + 1 );      } }

if you use the DeathMsg event :

Code:
register_event( "DeathMsg", "Monster_Killed", "a", "1>0" ) public Monster_Killed () {      new Killer = read_data( 1 );      new Victim = read_data( 2 );      if ( is_user_alive( Killer ) && pev( Victim, pev_flags ) & FL_MONSTER ) )      {           set_user_frags( Attacker, get_user_frags( Attacker ) + 1 );      } }

solano 11-23-2009 16:13

Re: Monster Mod
 
i get these errors wheni try to compile :|
Edit ok i got them down to 2 errors
Edit2: ok 1 error now :D
/home/groups/amxmodx/tmp3/phpX9j5iC.sma(73) : error 017: undefined symbol "set_user_frags"

1 Error.
Could not locate output file /home/groups/amxmodx/public_html/websc3/phpX9j5iC.amx (compile failed).


line 71: if ( is_user_alive( Killer ) && pev( Victim, pev_flags ) & FL_MONSTER ) )
line 73: set_user_frags( Attacker, get_user_frags( Attacker ) + 1 );

Arkshine 11-23-2009 16:29

Re: Monster Mod
 
set_user_frags() is a native from "fun" module. So you have to add : #include <fun> ;
for pev() , it's from fakemeta ; you have to add : #include <fakemeta>


All times are GMT -4. The time now is 02:48.

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