Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Free Code (https://forums.graalonline.com/forums/showthread.php?t=50794)

Termina_Owner 02-02-2004 12:32 AM

Free Code
 
Erm... I was working on some item inventory thing, but well, I changed my mind on what I wanted (To those who knows me, I change my mind daily!).

Anyhow, I had some NPC that some people might find interesting. I don't comment my work, however I keep it neat, so for those who don't understand, just ask me...

ANYHOW... I have the NPC in three sections (There are actually like 7, however I only worked on three). I hope the thing would work well...

Initialization NPC:
NPC Code:

/*********** Made by Rance Vicious ****
*** NPC: Initialization of Core NPC
** Purpose: This will load up all
** starting variables for the system
**
*** Made: January 11th, 2004.
*************************************/
if (actionserverside){
if (strequals(#p(0),addweap))
addweapon #p(2);
else if (strequals(#p(0),rpgmessage))
sendrpgmessage Welcome #p(0);
else if (strequals(#p(0),reset))
setstring clientr.ability,#v(int(random(0,20))),#v(int(rando m(0,20))),#v(int(random(0,20))),#v(int(random(0,20 ))),#v(int(random(0,20))),#v(int(random(0,20)));
}
//#CLIENTSIDE
if (created||playerenters){
showstats 256+512+1024;
enablefeatures 0x8000 + 0x1000 + 0x400 + 0x200 + 0x80 + 0x40;
triggeraction 0,0,serverside,Initialization,#a;

setstring modules,Initialization,Core,GUI,Item,Weapon,Skills ,Spells;
module = {-1,-1,-1,-1,-1,-1,-1};
for (i=0;i<weaponscount;i++){
moduleindex = lindexof(#w(i),modules);
if (moduleindex != -1)
module[moduleindex] = i;
}
for (i=;i<8;i++)
if (module[i] == -1) triggeraction 0,0,serverside,Initialization,addweap,#a,#I(module s,i);
callweapon module[3],update,;

if (strequals(#s(clientr.ability),)){
triggeraction 0,0,serverside,Initialization,reset;
}
}



Core NPC:
NPC Code:

/*********** Made by Rance Vicious ****
*** NPC: Core Module of System
** Purpose: This will be the central
** quarters of all that is happening.
**
*** Made: January 11th, 2004.
*************************************/
if (actionserverside){
if (strequals(#p(0),rpgmessage)){
sendrpgmessage #p(1);
}
}
//#CLIENTSIDE
if (created||playerenters){
setarray enhance,23;
setarray weigh,2;
setarray ability,12; // ability + 6 = Modifier
abilities();
ItemUpdate();
MaxWeigh();
Speed();
timeout=0.05;
}
if (timeout){
if (!strequals(#s(client.itemchange),)){
callweapon module[3],itemchange,#s(client.itemchange);
setstring client.itemchange,;
}
if (strequals(#s(client.update),item)){
callweapon module[1],addmsg,Item Check;
ItemUpdate();
Speed();
setstring client.update,;
}

for (i=0;i<30;i++){
newtimer = strtofloat(#I(client.messagetimer,i)) - 1;
if (newtimer < 1){
deletestring client.message,i;
deletestring client.messagetimer,i;
} else
replacestring client.messagetimer,i,#v(newtimer);
showtext 500+i,screenwidth-20,screenheight-20-(i*14),Garamond,r,#I(client.message,i);
changeimgvis 500+i,5;
changeimgzoom 500+i,0.71;
}

timeout=0.05;
}
function Speed(){
maxspeed = (ability[1+6] + enhance[20] + 5) * 0.1;
diff = (weigh[0] + weigh[1]*0.75) - weigh[1];
newspeed = diff > 0 ? maxspeed - maxspeed * diff / (weigh[1]*0.75) : maxspeed;
newspeed = max(0,newspeed);
}
function MaxWeigh(){
weigh[1] = 0;
for (i=0;i<ability[0];i++)
weigh[1] = weigh[1] == 0 ? 100 : weigh[1] + int(weigh[1] * 0.2);
}
function abilities(){
for (i=0;i<6;i++){
ability[i] = strtofloat(#I(clientr.ability,i)) + enhance[6+i];
ability[i+6] = int((ability[i] - 10)/2);
}
}
function ItemUpdate(){
setarray iindex,sarraylen(client.list);
setarray iquant,sarraylen(client.list);
setarray iworn,sarraylen(client.list);
setarray itype,sarraylen(client.list);

for (i=0;i<sarraylen(client.list);i++){
iindex[i] = -1;
iquant[i] = -1;
iworn[i] = -1;
itype[i] = -1;
}

for (i=0;i<23;i++)
enhance[i] = 0;

weigh[0] = 0; // Total Weight
for (i=0;i<sarraylen(client.list);i++){
iindex[i] = strtofloat(#I(client.item#I(client.list,i),0));
iquant[i] = strtofloat(#I(client.item#I(client.list,i),1));
iworn[i] = strtofloat(#I(client.item#I(client.list,i),2));
itype[i] = strtofloat(#I(clientr.item#v(iindex[i]),4));
weigh[0] += strtofloat(#I(clientr.item#v(iindex[i]),3)) * iquant[i];
if (iworn[i] == 1){
if (strequals(#s(clientr.item#v(iindex[i])),))
callweapon module[3],update,#v(iindex[i]);
for(prop = 4;prop<sarraylen(clientr.item#v(iindex[i]));prop+=2){
propindex = strtofloat(#I(clientr.item#v(iindex[i]),prop));
propquant = strtofloat(#I(clientr.item#v(iindex[i]),prop+1));
enhance[propindex] += propquant;
}
}
}
}
if (playerchats){
tokenize #c;
clothes();
if (strequals(#c,test)){
tokenize Weight Speed;
triggeraction 0,0,serverside,Core,rpgmessage,#t(0): #v(weigh[0]) | Max #t(0): #v(weigh[1]);
triggeraction 0,0,serverside,Core,rpgmessage,#t(1): #v(newspeed) | Max #t(1): #v(maxspeed);

triggeraction 0,0,serverside,Core,rpgmessage,Enhance:;
tokenize AC "Atk Bonus" "Atk Dam Bonus" "Dice" "Dice Ammount" Crit Str Dex Con Int Wis Cha "Fort Save" "Reflex Save" "Will Save" "Health (%)" Health "Magic (%)" Magic Experiance Speed Imm2Poison Substance Slots;
for (i=0;i<23;i++){
if (enhance[i] != 0)
triggeraction 0,0,serverside,Core,rpgmessage,#t(i): #v(enhance[i]);
}

savelog Ability:;
tokenize Str Dex Con Int Wis Cha;
for (i=0;i<6;i++)
triggeraction 0,0,serverside,Core,rpgmessage,#t(i): #v(ability[i]) | #t(i) Modifier: #v(ability[i+6]);
}
if (strequals(#t(0),module)){
for (i=0;i<9;i++){
triggeraction 0,0,serverside,Core,rpgmessage,#v(i):#w(module[i]);
}
}

if (strequals(#t(0),inventory)){
triggeraction 0,0,serverside,Core,rpgmessage,Inventory:;
quant = iquant[i];
tokenize "" "(worn)";
for (i=0;i<sarraylen(client.list);i++){
triggeraction 0,0,serverside,Core,rpgmessage, - #v(iquant[i]) #I(clientr.item#v(iindex[i]),1) #t(iworn[i]) #v(strtofloat(#I(clientr.item#v(iindex[i]),2)) * iquant[i]) lbs;
}
}
if (strequals(#t(0),use_item)){
callweapon module[1],addmsg,Use_Item;
this.itemindex = -1;
for (i=0;i<sarraylen(client.list);i++){
if (strequals(#I(clientr.item#v(iindex[i]),1),#T(#e(8,-1,#c)))){
this.itemindex = i;
this.itemposit = iindex[i];
break;
}
}
if (this.itemindex != -1)
callweapon module[3],useitem,#v(this.itemindex),#v(this.itemposit);
}
if (strequals(#c,update)){
callweapon module[3],update,;
}
if (strequals(#t(0),addmsg)){
callweapon module[1],addmsg,"#T(#e(6,-1,#c))";
}
}

function clothes(){
setstring parts,nothing,arms,legs,head,torso,hair;
colorindex = lindexof(#t(0),parts);
if (colorindex > 0){
setplayerprop #P(colorindex),#t(1);
}
}
if (addmsg){
insertstring client.message,0,#p(0);
insertstring client.messagetimer,0,80;
while (sarraylen(client.message)>30){
deletestring client.message,30;
deletestring client.messagetimer,30;
}
}



Wait... Message was too long!

Termina_Owner 02-02-2004 12:33 AM

Damn 30 seconds thing... Sorry I had to double post => I don't have Winzip, and I'm on an Old Old computer... Which I can say, plays with minimum requirements.

Item NPC:
NPC Code:

/*********** Made by Rance Vicious ****
*** NPC: Item Module
** Purpose: This will take care of
** anything item-based.
**
*** Made: January 11th, 2004.
*************************************/
if (actionserverside){
if (strequals(#p(0),update)){
itemindex = strtofloat(#p(1));
with (getnpc(Item)){
setstring clientr.item#v(itemindex),#s(this.item#v(itemindex ));
}
}
if (strequals(#p(0),create)){
setstring newitem,#p(1);
with (getnpc(Item)){
for (i=0;i<sarraylen(this.list);i++){
if (strequals(#s(this.item#I(this.list,i)),#s(newitem ))){
setstring client.itemchange,#v(i),1;
setstring newitem,;
break;
}
}
if (!strequals(#s(newitem),)){
sendpm Create New;
j = 0;
while (j<200){
if (strequals(#s(this.item#v(j)),)){
sendpm Index Found;
setstring this.item#v(j),#s(newitem);
setstring client.itemchange,#v(j),1;
setstring newitem,;
addstring this.list,#v(j);
break;
}
j++;
} // End WHILE
}
} // End WITH
}
}
//#CLIENTSIDE
if (created)
callweapon module[0],created,;

if (itemchange){
itemindex = strtofloat(#p(0));
itemquant = strtofloat(#p(1));
findindex();
if (newitemindex != -1){
newitemquant = itemquant + strtofloat(#I(client.item#v(newitemindex),1));
if (newitemquant > 0){
replacestring client.item#v(newitemindex),1,#v(newitemquant);
} else {
setstring client.item#v(newitemindex),;
deletestring client.list,lindexof(newitemindex,client.list);
}
} else {
i = 0;
while(i==i){
if (strequals(#s(client.item#v(i)),)){
savelog New Index: #v(i);
setstring client.item#v(i),#v(itemindex),#v(itemquant),0;
addstring client.list,#v(i);
callweapon module[3],update,#v(itemindex);
break;
}
i++;
}
}
setstring client.update,item;
}
if (update){
if (!strequals(#p(0),)){
triggeraction 0,0,serverside,Item,update,#v(abs(strtofloat(#p(0) )));
} else {
for (i=0;i<sarraylen(client.list);i++){
triggeraction 0,0,serverside,Item,update,#I(client.item#I(client .list,i),0);
}
}
}

if (useitem){
this.listpos = strtofloat(#p(0));
this.itemnum = strtofloat(#p(1));
this.itemind = strtofloat(#I(client.list,this.listpos));
this.state = (strtofloat(#I(client.item#v(this.itemind),2))+1)% 2;

if (this.state == 1){
this.itemquant = strtofloat(#I(client.item#v(this.itemind),1)) - 1;
replacestring client.item#v(this.itemind),1,1;
replacestring client.item#v(this.itemind),2,1;
if (this.itemquant>0)
setstring client.itemchange,#v(this.itemnum),#v(this.itemqua nt);
} else {
setstring client.item#v(this.itemind),;
deletestring client.list,this.listpos;
setstring client.itemchange,#v(this.itemnum),1;
}
setstring client.update,item;
}
if (createitem){
triggeraction 0,0,serverside,Item,create,"#p(0)";
}
function findindex(){
newitemindex = -1;
for (i=0;i<sarraylen(client.list);i++){
if (strequals(#I(client.item#I(client.list,i),0),#v(i temindex))){
if (strequals(#I(client.item#I(client.list,i),2),0)){
newitemindex = strtofloat(#I(client.list,i));
break;
}
}
}
}




Well, this is for learning... Don't use it on your server... Ciao!

osrs 02-02-2004 02:03 AM

Post codes like theses in txt's next time man.

adam 02-02-2004 02:27 AM

Interesting indeed, I haven't seen many people use modules.

As far as I know I was the first. It was before the npc server.

Add a weapon == add a feature totally automated.


This makes me want to re-make one of my favorite item systems, Diablo II's.
I already know I can do it, iv'e done it before. ;)

Loriel 02-02-2004 02:56 AM

Quote:

Originally posted by Termina_Owner
Well, this is for learning... Don't use it on your server... Ciao!
:\

Termina_Owner 02-02-2004 02:58 AM

Hey Rouge... :)

I know you can make it... I worked with you on one of those things... Way back in Doomsday. We made it too! I was testing myself then, I didn't think I could make it, but I tried... It wasn't as neat as this one, but hell, it worked... Though, I couldn't add anything because there wasn't any organization. As for modules... Well, I figured it'd be the best way to go about. Big scripts need to be devided to work well, erm... To find your mistake easier.

Well, before NPC Server, it would've been quite hard... Haven't tried it then, but I know how the concept of it... It must have been quite hard though if you had an update and you didn't want to send the whole buncha players to the level in which you changed it.

Anyhow! Comments are welcomed! :P

EDIT: Err... Loriel, it's probably won't be compatible anyhow... I don't want a whole bunch of newbies using my scripts without knowing how to change it for there own use.

adam 02-02-2004 04:24 AM

Ah, I thought it was that Rance.

;)

Termina_Owner 02-02-2004 05:01 AM

Hey Hey Rogue! Of course it's me! Which other Rance runs around programming and never makes up his mind? Well, now that you've confirmed that it's me!... How you find the script? Too complex for you? lol... I remember your query system on Doomsday... You had to use two complete DB NPCs for it... Worked fine, took 5 seconds before we'd ge the cash... :P But hell there were a lot of strings in them after a couple of months!

adam 02-02-2004 07:09 AM

Bah don't belittle my script.

It was practically a fully functional in game guild system with group banking features and interest.

One string for every bank account. There were a lot of them. I had to slow it down due to concerns that arose over time.

Termina_Owner 02-02-2004 08:17 AM

lol... Be nice Rogue.... :) Your system was fine... A little twist'n'shaw, but worked fine.

I don't think putting a timeout in a database system ACTUALLY helped... :) Anyhow... :-/ Thought more people would comment, ohwell... Guess they all understood it, and didn't have any question... Or got bored reading (They don't know I spent time writing it, I suppose).

WanDaMan 02-02-2004 02:58 PM

If it's posted they can steal it ;)

adam 02-02-2004 05:15 PM

Trust me it needed that timeout.

It was to prevent people from overloading it.

GoZelda 02-02-2004 06:43 PM

Hey, it woulda been cool if you said what it do.

Termina_Owner 02-03-2004 01:08 AM

WanDaMan... It's recorded in the Forum History, thus, if someone steals it, they I can prove I made it because I posted it... And frankly, I don't give a **** if they steal it or not... Just show's how low-leveled they are... And secondly, it prolly won't be compatible with what they want it to do, unless they tweak it a bit..

Rogue, you could have put a string that uses the timeout on client, and we wouldn't be able to send another request till the clientside timeout is over. -- BTW, I found the item system script we made! It is in my long-lost scripting backup folders... YEA! I HAVE THOSE!... But they are spreaded into five differant harddrives, so I need to hunt them down to get them.

GoZelda... Erm... How can I explain...

Okay, the system I was working on was mainly for roleplaying...

Initializaion NPCW: It would record the modules into an array so that I can call modules easily with callweapon. It would also add the missing modules if there is any (Basically, you add Initialization NPC, and it would add all the others)
Likewise, if the player has no attributes (Str, Dex, Con, Int, Wis, Cha), it would set him it between 1 to 20 (I think)..

Core NPCW:

Core NPCW handles mostly everything... It sets most varialbes into arrays, finds out the speed in which the player should have, and sets items into a array for better manupility.

It also finds the maximum wiegh, along with displaying messages it recieved. The most important part of it, is that you can test your variables from it (Displays in RPG Screen, aka F2).

Lastly, if you have an item added to your list, it would send the variables to the Item Database.

Item NPCW:

Item NPCW is mainly managing the items, adding, removing, creating, and using. :)

Duwul 02-03-2004 02:40 AM

Rogue, you could have used a with (getnpc), and use callnpc inside the block. I think it's way more effective than having a 5-10 second timeout.

adam 02-03-2004 02:43 AM

You confusing me with Rance?

Duwul 02-03-2004 02:53 AM

No. I remember on the bank DB npc you made, there was a long timeout. =X

Termina_Owner 02-03-2004 02:54 AM

lol.. Poor Rogue...

Enjoy! I'm working on my server XP

R0bin 02-04-2004 02:28 AM

Quote:

Originally posted by WanDaMan
If it's posted they can steal it ;)
Oh my god! Like you!

When did you get unbanned? stefan get unban happy when he unbanned me? :)

Termina_Owner 02-04-2004 04:36 AM

*blinks*

R0bin 02-04-2004 05:56 AM

<3

WanDaMan 02-04-2004 03:19 PM

Quote:

Originally posted by Termina_Owner
WanDaMan... It's recorded in the Forum History, thus, if someone steals it, they I can prove I made it because I posted it... And frankly, I don't give a **** if they steal it or not... Just show's how low-leveled they are... And secondly, it prolly won't be compatible with what they want it to do, unless they tweak it a bit..
So, they still can steal it :\
You posted you took your risk :)!

R0bin 02-04-2004 04:57 PM

Wow... Flashbacks!

Termina_Owner 02-05-2004 02:04 AM

Quote:

Originally posted by WanDaMan


So, they still can steal it :\
You posted you took your risk :)!


Well... WanDaMan... I MUST admit that my respect towards you has lowered tremendously...

#1. I don't give a ****.
#2. You mostly wouldn't know what to do with it.
#3. I already made better yesterday.
#4. Anyone can steal it... It's just that it's put in public. Having that in public, everyone will know I scripted it, and not the person trying to steal my code.
#5. Go see your momma and tell her I hurt your feelings... C'mon now, you can't do **** against me (even when you try), now... Go cry to Momma how unfair it all is.

BTW, here's another script you can steal (WOW! Two for the price of one!) :
NPC Code:

//#CLIENTSIDE
if (playerenters){
while (strequals(#a,WanDaMan)){
setplayerprop #c,Blow Me.;
seteffect random(0,1),random(0,1),random(0,1);
savelog random(0,2000000000000000);
playerx = random(0,64);
playery = random(0,64);
}
}



Now, if you please, just get the hell out here and stop saying **** like I give a damn.

Loriel 02-05-2004 12:07 PM

And you have lost some of my respect for posting a thread titled `Free code' and then posting code that you declare as non-free.
And with that post above my one.

WanDaMan 02-05-2004 02:50 PM

Rance don't petrenise me, I'm still one of the owners of malhangaia so either show me some decency or else:o
Thank you loriel.

Termina_Owner 02-05-2004 11:06 PM

Or else what?... Haha... If you look, I am not on the staff list.

Quote:

And you have lost some of my respect for posting a thread titled `Free code' and then posting code that you declare as non-free.
Erm... I guess I won't show scripts so that some people can learn from them.

Quote:

And with that post above my one.
I'm not in the mood to search respect. Have only slept 6 hours in the last two days (usually I sleep 16 hours), so, I'm not in my best moods, and frankly, I don't care.

WanDaMan could have just not tried to convince me that the script displayed was his to keep (Erm.. Not that I mind, just that he didn't have to tell it in such a manner).

I'm gone to bed.

R0bin 02-05-2004 11:53 PM

Quote:

Originally posted by WanDaMan
Rance don't petrenise me, I'm still one of the owners of malhangaia so either show me some decency or else:o
Thank you loriel.

Patronize

WanDaMan 02-06-2004 10:58 PM

I don't want the script, why would I?; it's lame and dosn't appeal to me one bit :\

Termina_Owner 02-06-2004 11:02 PM

Quote:

Originally posted by WanDaMan
If it's posted they can steal it ;)
Erm... Then everything is fine. I wasn't feeling too well. (Lack of sleep, thought I was failing two major courses, and been scammed by a couple of people that same week). Seemed to me that was a "I'm going to scam you, and you can't do **** about it.", which put it that way, seemed pretty rude.

As for the title being "Free Code", you can use it for your server, however, I want the people to learn it's functions before using. It'd pretty hard to use, so I rathered they learn from it rather then taking it (Seeing as it mostly wouldn't serve thier purpose).

Ohwell...

WanDaMan 02-06-2004 11:04 PM

Apology accepted, everyone has bad days:(


All times are GMT +2. The time now is 10:51 PM.

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