Thread: Free Code
View Single Post
  #2  
Old 02-02-2004, 12:33 AM
Termina_Owner Termina_Owner is offline
Registered User
Join Date: Oct 2003
Posts: 175
Termina_Owner is on a distinguished road
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!
__________________
- Rance Vicious
Reply With Quote