|
Registered User
|
Join Date: Oct 2003
Posts: 175
|
|
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! |
__________________
- Rance Vicious
|
|