hello how can i create new button ?
i need thread script on key : 5
PHP Code:
self UseButtonPressed()
self MeleeButtonPressed()
self AttackButtonPressed()
Printable View
hello how can i create new button ?
i need thread script on key : 5
PHP Code:
self UseButtonPressed()
self MeleeButtonPressed()
self AttackButtonPressed()
The answer is you can't, you could of course use libcod which has build in these functions but there's an easier way.
1. Create a menu file and do something like2. On connect open the menu on each player so that it binds the right response to right key (eventually can do this as well on respawn to prevent players from changing it)PHP Code:
bind k "openscriptmenu keys key_K"
3. In menus.gsc make a new response likeThen... execute your script.PHP Code:
if(menu == "-1" && response == "key_K")
Code untested, there might be an obvious to fix mistake but you should be able to fix it if any occurs.
Just make clientcmd menu.
Code:self setclientcvar("clientcmd","bind 5 openscriptmenu ks doc4");
self openMenu ("clientcmd");
self closemenu();
self waittill("menuresponse", menu, response);
if(response == "doc4")
{
how to put a button f5, f6 , f7 or another 5,6,7,8 etc....
started to sentrygun (button)
in this sense somehow
self iprintlnbold("^2Press f1 for Sentry!");
if(self f1ButtonPressed())
self thread sentrygun();
if(!isAlive(self))
I have no idea how to do it
demo:
http://www.youtube.com/watch?v=y2K9P...Lspy_faMU3O-jg
Code:sentrygun()
{
self thread sentrygunrelogio();
if( isDefined(self.turret_gun) && isDefined(self.turret_bip) )
{
self.turret_gun destroy();
self.turret_bip destroy();
self notify("kill_turret");
}
self.gotTurret = false;
self endon("kill_turret");
self endon("joined_spectators");
self endon("disconnect");
self endon("death");
self endon("killed");
self.turret_gun = spawn("script_model", self.origin + (40,0,35));
self.turret_gun setmodel("xmodel/caspi_minigun_head");
self.turret_gun setContents(1);
self.turret_gun.ammo = 200;
self.turret_gun.owner = self;
self.turret_gun thread CheckForPlayers();
self.turret_gun thread moveShoot();
self.turret_bip = spawn("script_model", self.origin+ (40,0,0));
self.turret_bip setmodel("xmodel/sentry_gun_4pod");
self.turret_bip setContents(1);
level.sentryMP=1;
}
CheckForPlayers()
{
self endon("joined_spectators");
self endon("disconnect");
self endon("death");
self endon("killed");
self endon("powerdown");
self endon("kill_turret");
self.targetPlayer = undefined;
while(1)
{
closestDist = undefined;
closestPlayer = undefined;
players = getentarray("player", "classname");
for(i = 0; i < players.size; i++)
{
player = players[i];
if(player.pers["team"] == "axis" && isAlive(player) && player.sessionstate == "playing" && !player.spawnprotected)
{
res = self IsInView(player);
if(res >= 0)
{
if(!isDefined(closestDist) || res < closestDist)
{
closestDist = res;
closestPlayer = player;
}
}
}
}
if(isDefined(closestPlayer))
self.targetPlayer = closestPlayer;
else if(!isDefined(closestPlayer))
self rotateyaw(randomfloat(360),2);
while(isDefined(closestPlayer) && isAlive(closestPlayer) && closestPlayer.sessionstate == "playing" && self IsInView(closestPlayer) >= 0)
{
self.targetPlayer = closestPlayer;
wait 0.05;
}
self.targetPlayer = undefined;
wait 0.2;
}
}
vector_scale (vec, scale){vec = (vec[0] * scale, vec[1] * scale, vec[2] * scale);
return vec;
}
moveShoot()
{
self endon("joined_spectators");
self endon("disconnect");
self endon("death");
self endon("killed");
self endon("powerdown");
self endon("kill_turret");
rotating=-1;
angle=int(self.angles[1])+180;
while(1)
{
while( isDefined(self.targetPlayer) && !self.targetPlayer.spawnprotected && self.ammo > 0 )
{
self.ammo--;
flash = anglesToForward( self.angles );
flash = vector_scale( flash, 43 );
shell = anglesToRight( self.angles );
shell = vector_scale( shell, 7 );
playFx( level.fx_turretflash, self.origin + flash + (0,0,7) );
playFx( level.fx_turretshelleject, self.origin + shell + (0,0,6) );
self playsound("Flak20_fire");
self.targetPlayer thread [[level.callbackPlayerDamage]](self, self.owner, (30 + RandomInt(30)), 0, "MOD_RIFLE_BULLET", "sentry_mp", self.origin, vectornormalize(self.targetPlayer.origin + (0,0,0) - self.origin), "none", 0);
aim = vectortoangles(self.targetPlayer getEye() + (0,0,-10) - self.origin);
self rotateto((aim[0],aim[1] + 0,0), 0.3);
wait 0.2;
if( self.ammo <= 0 )
self notify("ammo_deployed");
}
wait 0.5;
}
}
IsInView(target)
{
dist = distanceSquared(self.origin,target.origin);
if(dist < 400000)
{
tracer = bullettrace(self.origin + (0,0,30) , target getEye() , false, self);
if(tracer["fraction"] == 1)
return dist;
}
return -1;
}
sentrygunrelogio()
{
self.Sentrygun destroy();
self.Sentrygun = newClientHudElem(self);
self.Sentrygun.alignx = "center";
self.Sentrygun.x = 390;
self.Sentrygun.y = 10;
self.Sentrygun.fontscale = 0.9;
self.Sentrygun.label = &"^2S^7entry ^2T^7ime^2:^7";
temposentry=60;
while(1)
{
temposentry-=0.1;
self.Sentrygun setvalue(int(temposentry));
if(temposentry <=0 || self.pers["team"]!="allies" || !isAlive(self) )
{
if(isDefined(self.Sentrygun))self.Sentrygun destroy();
self.turret_bip hide();
self.turret_gun hide();
self.turret_bip playsound("sentrygun_winddown");
self playlocalsound("sentrygun_gone");
self.turret_bip delete();
self.turret_gun delete();
self notify("powerdown");
self.turret_gun notify("powerdown");
level.sentryMP=0;
self thread sentrydelay();
break;
}
wait 0.1;
}
}
sentrydelay()
{
self.sentrydelay=1;
if(isdefined(self.Sentry_huddelay))
self.Sentry_huddelay destroy();
self.Sentry_huddelay = newClientHudElem(self);
self.Sentry_huddelay.alignx = "center";
self.Sentry_huddelay.x = 390;
self.Sentry_huddelay.y = 10;
self.Sentry_huddelay.fontscale = 0.9;
self.Sentry_huddelay.label = &"ER_DELAY_SENTRY";
self.Sentry_huddelay settimer(getcvarint("sv_sentry_delay"));
wait(getcvarint("sv_sentry_delay"));
self.sentrydelay=0;
self.Sentry_huddelay destroy();
}
you need to bind a player key on connect then
bind KEY openscriptmenu -1 BUTTON_PRESSED_5
(use clientcmd.menu to do that - search forum if you don't know what is it)
PHP Code:
if(response == "BUTTON_PRESSED_5")
self thread spawnSentry();
COD2 only monitors certain keys in the engine - attackbuttonpressed() meleebuttonpressed() usebuttonpressed(). Any other key cannot be detected by the engine. If you want a key such as 5 to be used for something you have to create a work-around, where you use a menu and scriptmenuresponse and monitor for it. And then it is just a single push of the button. The game will not detect you holding a key down for a certain period.
All this has been posted on this site numerous times. I suggest you get to know the "search" button at the top of the forum, and learn to use it to find all the threads that are on this subject.
Exactly that I wanted to try some days ago and I wasn't able to implement that, though had some nice idea. :D
In Counter-Strike Source this is possible:
When pressing "Alt-Key" now, the sensitivity is really slow, hence good aiming on far distance.PHP Code:
alias +sens "sensitivity 1"
alias -sens "sensitivity 3"
bind alt +sens
I wanted to make that for CoD 2 starting with:
That fails already, because cvar-keys are not allowed to have "+" in it. But there is a way around:PHP Code:
set +sens "sensitivity 1"
That looked for me, that it could already work, but the result is kinda strange:PHP Code:
// set +sens is not possible, illegal name
set sens_p "sensitivity 1; say test_a"
set sens_m "sensitivity 3; say test_b"
// they didnt check in setfromdvar though :)
setfromdvar +sens sens_p
setfromdvar -sens sens_m
// the actual binding:
bind o +sens
Well, "bind o +sens" kinda "executes" a cvar, so I tried stuff likePHP Code:
// pressing o results in:
// +sens = "111 -1471273609"
// -sens = "111 -1471273546"
// the last number is always random, but often starts with -147
, but that doesn't worked also :S Would be nice if somebody push the idea with +/- further for new state-keys like attackButtonPressed().PHP Code:
bind o "vstr +sens"
You can FAKE a button and check if its pressed or not, i'll provide the bind when im at home. However this is not as good and save as useButtonPressed() and its counterparts
syntax is similar to:
bind F5 "openscriptmenu test start_f5; +speed; openscriptmenu test stop_f5;-speed"
speed and some other available in cod2, but not used binds only can be used and not all of them reset themselfes with -speed
this will trigger a menuresponse when pressed and also when released the F5-key
as already said, its not this safe and smooth, but it kind of works!
correct syntax:
PHP Code:
bind F5 "+holdbreath;-holdbreath;openscriptmenu clientcmd custombutton1;-holdbreath"
bind F6 "+strafe;-strafe;openscriptmenu clientcmd custombutton2;-strafe"
bind F7 "+speed;-speed;openscriptmenu clientcmd custombutton3;-speed"
bind F8 "+mlook;-mlook;openscriptmenu clientcmd custombutton4;-mlook"
Thought I would use this thread instead of creating a new one.
I'm trying to bind a key so it will execute multiple commands, just like:
Example:
This can be done easily if you were to type that command manually into console.Code:bind m "+scores;say A;"
However I need the server to bind the key instead of every user having to bind the key themselves.
The normal way of doing this would be using something like "execClientCommand" or "setClientCvar" but none work in my situation.
With "execClientCommand", you can't use double quotes in a string. Example:
I also tried using escape sequence's;Code:self execClientCommand("bind m "+scores;say test;"");
//Won't work.
But for some strange reason it will use single quotations instead of double:Code:self execClientCommand("bind m \"+scores;say test;\"");
Which won't work.Code://Output:
bind m '+scores;say test;'
//Won't work.
With "setClientCvar", I am able to do this;
However, using vstr will allow +scores to open normally, but it will not close normally (-scores) upon releasing the key. If I don't use vstr and manually type "bind m "+scores;say A;"" into console, it does open and close +scores correctly which is what I need.Code:self setClientCvar("scorebind", "+scores;say A;");
self execClientCommand("bind m vstr scorebind");
So, any ideas on how can I do it?
I use this. So maybe u can doPHP Code:
self setClientCvar ("clientcmd","disconnect; wait 20; reconnect");
self openMenu ("clientcmd");
self closeMenu ("clientcmd");
PHP Code:
self setClientCvar ("clientcmd","bind m +scores; wait 1; say A");
self openMenu ("clientcmd");
self closeMenu ("clientcmd");
maybe something like this
PHP Code:
player setClientCvar( "tmp" , "your;string;here;" );
player execClientCommand( "vstr tmp" );
Put the bind in a config file; execute the config file on the player when they are either in a team for the first time (it wont work onPlayerConnect), or when they spawn. Put the config file either on your server in raw format, or put it in your IWD file.
This is the config file I use to bind keys:
I name the config file "custombuttons.cfg".Code:bind I "openScriptMenu clientcmd ibutton"
bind L "openScriptMenu clientcmd lbutton"
bind M "openScriptMenu clientcmd mbutton"
bind K "openScriptMenu clientcmd kbutton"
This is the code I use to execute the config file:
Code:setUpButtons()
{
self ExecClientCommand( "exec custombuttons.cfg" );
}
Thanks to both.
I'm pretty sure I tried your solution serthy but I can't remember the results. I'll give it a go.
Also I didn't know you could include .cfg files in your .iwd's and exec them client side. Thanks for the info Tally.
Is there a function to make a player look to the right/left?
I'm editting the vehicles mod, and I would really like for the players to be able to pilot planes and jeeps using the directional keys.
I noticed that I can set these binds:
bind UPARROW "+lookup"
bind DOWNARROW "+lookdown"
bind RIGHTARROW "+mlook"
I noticed that +lookleft or +lookright won't work - are there any similar functions?
I don't know what "+mlook" does, can anybody tell me? It may be helpful.
So, what I'm thinking right now is to execute a script from each of the directional keys. This script would change the player's angles. Is this possible?
Editted: if there are functions to look to the right/left, I'll just use them with up/down and adjust player's sensivity when entering a vehicle.
Editted #2: I also noticed there is a +klook, trying to find out what that is.
Editted #3: Found out about "+right" and "+left". It's just what I needed. All I need now is to adjust the player's sensivity. I'm still accepting suggestions.
Little problem - how to restore the player's original sensivity after he leaves the vehicle? I think I'll write a .cfg file before changing sensivity, and execute it after he leaves the vehicle.
Editted #4: Looks like sensitivity only works with the mouse.
I guess that handling wouldnt be as smooth as it is the way it is right now, imho the result isnt worth the time spent
otherwise I'd go the way like Tally suggested it with 2 configs:
- when the player enters a vehicle, rebind their keys and remember the original setup (copy the config unfortunately i forgot the command)
- when the player exits the vehcile reset the config
If you're using an fs_game you could probably just bind the keys as they would reset to the original profile when restarting cod, although im not entirely sure of this
Yes that's exactly what I meant. I am using a fs_game, and, to save the player's original mouse sensitivity, I would just write a cfg and exec it after the player leaves the vehicle.
But, since sensitivity won't affect the keyboard commands, I'll just need to use functions to change the player's angles - and, like serthy said, it will probably not be smooth and therefore not worth the time spent, since I still need to adapt some stuff to be done with the TDM vehicle + bot mod.
I saw these functions in the para chute function:
bangles = self.angles;
self rotateTo( bangles, 0.5,0, 0.1);
rotateTo looks like an original COD function, since I couldn't find it anywhere in the file. Also, self.angles looks like an original COD variable, since it also wasn't defined anywhere in the file.
But unfortunately I don't think I'll have time for COD this week to test them.
both correct, original function and original vector
I'll still test it, but, even if I manage to rotate the player (update its position agreeing to the key being held) 5 times every second, it would still be like playing with 5 FPS.