Weapon Script

I’ve got most of the script working . my problem is linking the spacebar to the firing of the weapon . any help would be appreciated .

why spacebar?

because i was taught on shaded legends . all their scripts work the same way “d” to activate or deactivate it and space bar to fire it . on occasion they used the “s” and “a” keys but not very often . i like to make it work that way before i have to change them all to use the “s” and “a” keys .

edit : i tryed to replace “if(keydown2(83,true) && strequals(#w,Pistol)){” with “if(keydown(5) && strequals(#w,Pistol)){” and it wouldnt fire the bullet still . the bottom half is where im having problems , i finaly got the bullet to shoot right but i cant get it to fire when i want .

keydown(5) = S = Spacebar

but its not working . and if you use “if(weaponfired){” it only works for “d” . i dont know why but if i use “if(keydown(5)){” i get nothing when i hit the spacebar .

Edit: never mind i found the problem . for anyone who may come here looking for an answer to this problem .

“if(keypressed && keydown(5)){” - works for the space bar .

Good Job

gives MysticalNinja a bag of cookies

is there like…a list of keyID’s for all the keys on the keyboard? (why they call it a keyboard anyway? they dont look like the keys you put in doorlocks…should of called it a buttonboard)

keydown(x) is not an event, it is a conditional check. That means if you check for keydown(5) it is not going to tell Graal that you actually pressed “S”, because Graal can only tell if it’s 0 or 1(which is false or true). You need an event to tell Graal to actually check that true/false status, which you did with keypressed(which IS an event). Can also be done with timeouts, for example.

http://forums.graalonline.com/forums/showthread.php?t=46557

ummm , wtf ? someone lock this thread before more non-sense show’s up .

Emim’s post must of gotten removed, its not there…O.o I never did get that list of keyID’s

i don’t think there is one . the only ones i know are the basic’s , a,s,d,q,m . there might be a list on the official graal online forum’s . however someone gave me a script awhile back to figure out the key’s . if you put that in an npc in a level and hit play , when you hit a key it will tell you what the key number is via player chat .

if(keypressed){
    setplayerprop #c, #p(0);
}

Edit : credit goes to Beholder for that script . :slight_smile:

You’re welcome. Hahaha

;D still not locked!

Your moderator. E_e
How about: lock it yourself If you feel like it?

Nah.

after working on this for the better part of a month I’ve made some progress . but now im having new problem’s . for example every time a client string is changed it does it twice instead of once . now im not interested in every single problem with the script , just what ever is causing the client strings to be set more then once at a time . it is currently obtainable by just logging onto Zombiewars .

KEY : client.colt1911ammo = max amount of ammo for said gun carried
at any given time .

KEY : client.ammo = amount of ammo in the gun mag .

Key : this.colt1911 = gun is in use or not . 0 = not in use . 1 = is in use .

//NPC Scripted By MysticalNinja
//#CLIENTSIDE
if(created){
toweapons Colt1911;
setimg zw-icon_colt1911.png;
this.colt1911 = 0;
}

if(strequals(#w,Colt1911)){
  if(keypressed && keydown(4)){
    if(this.colt1911 = 0){
      this.newammo = strtofloat(#s(client.colt1911ammo))-7;              ///
      setstring client.colt1911ammo,#v(this.newammo);
      setstring client.ammo,7;
      setani zw_colt1911-idle,;
      replaceani idle,zw_colt1911-idle;
      replaceani walk,zw_colt1911-walk;
      replaceani sword,zw_colt1911-idle;
      this.colt1911 = 1;
    } else {
      this.colt1911 = 0;
      setstring client.colt1911ammo,#s(client.ammo);
      setani idle,;
      replaceani idle,idle;
      replaceani walk,walk;
      replaceani sword,sword;
      sleep .2;
      setstring client.ammo,0;
    }
  }
}

if(strequals(#w,Colt1911)){
  if(keypressed && keydown(5)){
    if(this.colt1911 = 1){
      if(strtofloat(#s(client.ammo)) >=  1){
       play 44magnum.wav;
       this.newammo = strtofloat(#s(client.ammo))-.5;
       setstring client.ammo,#v(this.newammo);
       timereverywhere;
        if(strequals(#v(playerdir),0)){
          shoot playerx-0.8,playery,2,pi/2,0,0,zw_bullet-heated,;
        }
        if(strequals(#v(playerdir),1)){
          shoot playerx-1,playery+1.61,2,pi,1,0,zw_bullet-heated,;
        }
        if(strequals(#v(playerdir),2)){
          shoot playerx+0.84,playery+3.5,2,1.5*pi,.5,0,zw_bullet-heated,;
        }
        if(strequals(#v(playerdir),3)){
          shoot playerx+1.3,playery+1.44,2,pi*2,1,0,zw_bullet-heated,;
        }
      } else {
        this.reloadstat=0;
        setstring client.ammo,0;
        flashreload();
      }
    }
  }
  if(keypressed && keydown(6)){
    setani zw_colt1911-reload,;
    this.newammo = strtofloat(#s(client.colt1911ammo))-7;
    setstring client.colt1911ammo,#v(this.newammo);
    setstring client.ammo,7;
    this.reloadstat = 1;
    sleep .5;
    setani zw_colt1911-idle,;
    hideimg 100;
  }
}

function flashreload(){
  if(this.reloadstat == 0){
    showimg 100,@Kristen [email protected]@**** RELOAD ****,playerx,playery-5;
    changeimgzoom 100,1.5;
    changeimgcolors 100,1,0,0,0;
    sleep .5;
    hideimg 100;
    sleep .5;
    flashreload();
  } else {
    this.reloadstat = 1;
    break;
  }
}

My biggest nag is your rapidfire mode.

if(keydown(4)) { if(this.key4 == 0) { this.key4 = 1; DoShit(); } } else this.key4 = 0;

ok ,well i messed with it abit more and discovered my problem was a timeout loop in the gui was making the gun reload stutter . that’s why i saw my ammo go from thirty to zero in about two seconds . ill work on the rapid fire , wont need that till i do the PPSH .

keydown( key ) -the specified key is pressed (0…10: up,left,down,right,S,A,D,M,tab,Q,P)

thats in the commands.rtf in the graal folder :wink:

Stowen, your a bit late MysticalNinja already gave me a script (that beholder made) to give me keyID’s for use with keypressed scripts. (look up a few posts to see)