Hello... Bored one friday night, so I'm writing this! I'm doing this directly in the Forum, so there might be little mistakes.
First off... You want to know what you want your item system to look like. There are many things you can do on this to make what you want. Persay, if you want some gun item system made, something like:
NPC Code:
GUN:
itemINDEX="Gun Name",graphics.png,TYPE,ShootRate,MaxShells,Bullet Type
BULLET:
itemINDEX="Bullet Name",graphics.png,TYPE,DAMAGE,SPEED
INDEX: what the item index is... A code-name to better remember things.
Gun Name: The name of your Gun
TYPE: Type of item (Gun - 0; Bullet - 1)
Shoot Rate: How fast your bullets shoot
Max Shells: How much bullets you can shoot before needing to reload.
Bullet Type: The index of the bullet.
Damage: How much the bullets hurt
Speed: The speed it shoots out
Once you have what you want, you can easily make an item... I'll make one before making the system to refer to it.
NPC Code:
item0="Pistol",pistol.png,0,2,8,2
item1="Uzi",pistol.png,0,0.5,100,3
item2="Pistol Bullets",bullet.png,1,1.5,20
item3="Uzi Bullets",bullet.png,1,0.5,30
Now that you got that determined, you can move on to the actual programming.
First off... You'd want to know what items you have... You can have a multitude of items, and want them easily accessed.
To do so, the most effective way I found was to record them in an array:
NPC Code:
if (playerenters){
maxitems = 4;
setarray this.item,maxitems;
setarray this.itemtype,maxitems;
setarray this.itemstate,maxitems;
func_array();
}
In here, you can see that I have this.item, this.itemtype, and this.itemstate. This is mainly so that I can easily identify whether I selected a gun, or ammo, and whether I have it equiped.
NPC Code:
function func_array(){
itemcount = 0;
for(i=0;i<maxitems;i++){
if (!strequals(#s(client.item#v(i)),)){
this.item[itemcount] = i;
this.itemtype[itemcount] = strtofloat(#I(client.item#v(this.item[itemcount]),2));
this.itemstate[itemcount] = i == strtofloat(#I(client.weap,0));
itemcount ++;
}
}
}
Now, well... In here, you see some traces of something I'll be using next. The client.weap reprosents what weapon your using.
Understand so far? Now... I won't be making the Q-Menu for you, however I'll make the main functions.
NPC Code:
if (playerchats){
tokenize #c;
if (strequals(#t(0),use_item)){
if (strequals(#t(1),#v(strtofloat(#t(1))))){ // If you say the INDEX
this.TI = strtofloat(#t(1));
findindex();
if (this.index>-1){ // Item Excists
this.weap = this.item[this.index];
setstring client.weap,#v(this.weap),#I(client.item#v(this.we ap),0);
func_array();
}
} else { // If you say Item Name
setstring this.name,#t(1);
findname();
if (this.index>-1){ // Item Excists
this.weap = this.item[this.index];
setstring client.weap,#v(this.weap),#I(client.item#v(this.we ap),0);
func_array();
}
}
}
}
function findindex(){
this.index = -1;
for (i=0;i<itemcount;i++){
if (this.item[i] == this.TI){
this.index = i;
break;
}
}
}
function findname(){
this.index = -1;
for (i=0;i<itemcount;i++){
if (strequals(#I(client.item#v(this.item[i]),0),#s(this.name))){
this.index = i;
break;
}
}
}
Erm... Complicated? Basically, if you say an index, it sees if it excists, and if it does, it records as the weapon your wearing. It recalls the item array, which reinitializes, and makes the item "on".
Now, for the actual use... This is mainly the most complex part, once you have the top done.
NPC Code:
if (created){
disableweapons;
timeout = 0.05;
}
if (timeout){
if (timer<0){
if (keydown(5)){
this.TI = strtofloat(#I(client.weap,0));
this.BI = strtofloat(#I(client.item#v(this.TI),5));
timer = strtofloat(#I(client.item#v(this.TI),3));
setshootparams (#I(client.item#v(this.BI),3));
angles = {4.71,3.14,1.57,0};
shoot playerx,playery,playerz,angles[playerdir],0,(#I(client.item#v(this.BI),4),shoot,;
}
} else timer -=0.05;
timeout = 0.05;
}
That's a basic concept of it. It doesn't subtract bullets, nor does it shoot from the center of the player, however, that is the general look of what it would look like.
Hope this tutorial explained what you wanted it to. If you want me to go into more details of things, just ask.
EDIT: Fixed some things.