Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-21-2004, 09:20 AM
Termina_Owner Termina_Owner is offline
Registered User
Join Date: Oct 2003
Posts: 175
Termina_Owner is on a distinguished road
String-Based Weapon Tutorial [Intermediate]

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.
__________________
- Rance Vicious

Last edited by Termina_Owner; 02-22-2004 at 03:06 AM..
Reply With Quote
  #2  
Old 02-21-2004, 11:16 AM
WanDaMan WanDaMan is offline
Master Tux
WanDaMan's Avatar
Join Date: Aug 2002
Location: England, United Kingdom
Posts: 5,571
WanDaMan is a jewel in the roughWanDaMan is a jewel in the rough
Send a message via MSN to WanDaMan
It's a good tutorial, but it's hard. You didn't describe any of the commands in detail and I couldn't really understand it ...
But it looks good I guess <3
5 rating
__________________
V$:CONFL16T
Reply With Quote
  #3  
Old 02-21-2004, 03:46 PM
osrs osrs is offline
Graalian since 1998
osrs's Avatar
Join Date: Mar 2002
Location: Brazil
Posts: 2,724
osrs is on a distinguished road
Send a message via ICQ to osrs Send a message via AIM to osrs Send a message via MSN to osrs Send a message via Yahoo to osrs
Most of the people wont understand it.
__________________
"Ability is what you are capable of doing. Motivation determines what you do. Attitude determines how well you do it."
Facebook: facebook.com/raysilvadotnet /
Reply With Quote
  #4  
Old 02-21-2004, 06:40 PM
Termina_Owner Termina_Owner is offline
Registered User
Join Date: Oct 2003
Posts: 175
Termina_Owner is on a distinguished road
Erm... Not for starters, I must admit. I tried not using too simple commands none-the-less.

I can't see where someone COULD have trouble... Just submit the part of the code which you don't understand, and I'll explain it more in detail.
__________________
- Rance Vicious
Reply With Quote
  #5  
Old 02-21-2004, 06:43 PM
Kadar Kadar is offline
Registered User
Join Date: Jan 2002
Posts: 636
Kadar is on a distinguished road
use clientr.flags

client.flags can be hacked easily
__________________
Reply With Quote
  #6  
Old 02-21-2004, 07:26 PM
Termina_Owner Termina_Owner is offline
Registered User
Join Date: Oct 2003
Posts: 175
Termina_Owner is on a distinguished road
I made it conceptual...
__________________
- Rance Vicious
Reply With Quote
  #7  
Old 02-21-2004, 08:35 PM
Duwul Duwul is offline
Registered User
Join Date: Nov 2003
Posts: 105
Duwul is on a distinguished road
I understand it. <3 Rance

=P

However, for the angle in the shoot part, all you need to do is
NPC Code:

getangle(vecx(playerdir),vecy(playerdir))

__________________
-Ajira
Liek, omigosh.
<3 DoomsDay.
Reply With Quote
  #8  
Old 02-21-2004, 10:15 PM
WanDaMan WanDaMan is offline
Master Tux
WanDaMan's Avatar
Join Date: Aug 2002
Location: England, United Kingdom
Posts: 5,571
WanDaMan is a jewel in the roughWanDaMan is a jewel in the rough
Send a message via MSN to WanDaMan
Rance, a **** who dosn't know how to indent a script I doubt he knows strings or anything..
It's good though like I said before
__________________
V$:CONFL16T
Reply With Quote
  #9  
Old 02-21-2004, 10:58 PM
Termina_Owner Termina_Owner is offline
Registered User
Join Date: Oct 2003
Posts: 175
Termina_Owner is on a distinguished road
Quote:
Originally posted by WanDaMan
Rance, a **** who dosn't know how to indent a script I doubt he knows strings or anything..
It's good though like I said before
Ehh?
__________________
- Rance Vicious
Reply With Quote
  #10  
Old 02-21-2004, 11:18 PM
Duwul Duwul is offline
Registered User
Join Date: Nov 2003
Posts: 105
Duwul is on a distinguished road
Wan, it's obvious you don't know Rance as well as I do.
__________________
-Ajira
Liek, omigosh.
<3 DoomsDay.
Reply With Quote
  #11  
Old 02-21-2004, 11:53 PM
Deek2 Deek2 is offline
Registered User
Join Date: May 2002
Location: Springfield, Missouri
Posts: 1,578
Deek2 is on a distinguished road
NPC Code:
if (strequals(#t(1),strtoflaot(#t(1)))){


Remember, being paranoid about spelling errors is crucial for programming.
Reply With Quote
  #12  
Old 02-22-2004, 12:31 AM
Termina_Owner Termina_Owner is offline
Registered User
Join Date: Oct 2003
Posts: 175
Termina_Owner is on a distinguished road
Erm.. You posted two errors: "float" , and the whole float thing needs to be in a #v()... :P
__________________
- Rance Vicious
Reply With Quote
  #13  
Old 02-22-2004, 02:15 AM
R0bin R0bin is offline
Banned
R0bin's Avatar
Join Date: Oct 2002
Location: Wales, UK
Posts: 828
R0bin is on a distinguished road
Send a message via AIM to R0bin
Its cool, someone should sticky.
Reply With Quote
  #14  
Old 02-22-2004, 06:07 AM
Thought Thought is offline
PipBoy Extraordinaire!
Thought's Avatar
Join Date: Nov 2001
Location: Long Beach, California.
Posts: 692
Thought is on a distinguished road
Indices are not 'code names'.
They are the position in a list, which can be iterated through by using an index.
__________________
Rick ([email protected])
#gscript on FreeNode (#gscript Guild, #gscript Information)
Graal User Statistics

I am now using my new account, Rick.
Reply With Quote
  #15  
Old 02-22-2004, 11:40 AM
WanDaMan WanDaMan is offline
Master Tux
WanDaMan's Avatar
Join Date: Aug 2002
Location: England, United Kingdom
Posts: 5,571
WanDaMan is a jewel in the roughWanDaMan is a jewel in the rough
Send a message via MSN to WanDaMan
Quote:
Originally posted by Termina_Owner


Ehh?
A **** couldn't read it, so it's useless to them. But usefull to people like R0bin who know these things.
__________________
V$:CONFL16T
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 04:38 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.