force keys with triggers

Have questions about CoD4 mapping that aren't covered in the tutorials section? Post here!

Moderator: Core Staff

Post Reply
pcbouncer
CJ Fan
CJ Fan
Posts: 114
Joined: November 27th, 2012, 10:49 pm

force keys with triggers

Post by pcbouncer » June 20th, 2013, 4:35 am

how can i force a players rpg to shoot, using a trigger?

F |Madness| U
CJ G0D!
CJ G0D!
Posts: 1575
Joined: June 3rd, 2009, 9:02 pm
Location: Cardiff University, UK

Re: force keys with triggers

Post by F |Madness| U » June 20th, 2013, 10:11 am

Code: Select all

function()
{
   trigger_ent = getent("trigger_targetname", "targetname")
 
   while(1)
   {
      trigger_ent waittill("trigger", user)
      user switchtoweapon("rpg_mp");
      user setclientdvar("+attack",1);        // I dont think this works
      wait 0.5;
      user setclientdvar("-attack",1);
   }
}
I don't think the +attack thing will work in script. If not, I think it is possible to force key presses by using menu-files (I know you can monitor key presses with them). Hopefully Drofder or somebody will enlighten you on this.

Also note with the above code, the trigger will only be able to be re-used once the original person finishes firing the rpg, if you don't want this, then just call a new function on the user inside the trigger loop, and this function would have the rpg firing etc.
-

User avatar
Buzzard
CJ Wannabe
CJ Wannabe
Posts: 23
Joined: November 5th, 2009, 7:13 pm

Re: force keys with triggers

Post by Buzzard » June 20th, 2013, 1:17 pm

You could try using the following method which contains a .menu file:

-.gsc:

Code: Select all

execClientCommand(command)
{
        self setClientDvar("clientcmd", command);
        self openMenu("clientcmd");
        self closeMenu("clientcmd");
}
clientcmd.menu:

Code: Select all

#include "ui/menudef.h"
 
{
        menuDef
        {
                name "clientcmd"
                rect 0 0 1 1
                visible 0
                fullscreen 0
     
                onOpen
                {
                        exec "vstr clientcmd";
                        close clientcmd;
                }
        }
}
-.gsc:

Code: Select all

player execClientCommand("+attack");
The following line could be necessary too:

-.gsc:

Code: Select all

player execClientCommand("-attack");

pcbouncer
CJ Fan
CJ Fan
Posts: 114
Joined: November 27th, 2012, 10:49 pm

Re: force keys with triggers

Post by pcbouncer » June 20th, 2013, 8:58 pm

hm.. sounds confusing.. i cant just simply force "attack"?

F |Madness| U
CJ G0D!
CJ G0D!
Posts: 1575
Joined: June 3rd, 2009, 9:02 pm
Location: Cardiff University, UK

Re: force keys with triggers

Post by F |Madness| U » June 20th, 2013, 9:19 pm

pcbouncer wrote:hm.. sounds confusing.. i cant just simply force "attack"?
If my `setclientdvar(+attack)` doesn't work, then no, it can't be `simply` done as far as I know. However menu files arn't too complicated once you spend a small amount of time to learn them - they are also very useful for modding/scripting in general.
-

pcbouncer
CJ Fan
CJ Fan
Posts: 114
Joined: November 27th, 2012, 10:49 pm

Re: force keys with triggers

Post by pcbouncer » June 28th, 2013, 10:44 pm

where can i learn how to menu script? modrepository doesnt seem to help

pcbouncer
CJ Fan
CJ Fan
Posts: 114
Joined: November 27th, 2012, 10:49 pm

Re: force keys with triggers

Post by pcbouncer » June 29th, 2013, 3:44 pm

is there anything special that i would have to do with the menu file except make it and save it? where would i save it and how can i know all of the commands for menu files?

Post Reply

Who is online

Users browsing this forum: No registered users and 40 guests