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"