serverside item handling

Hopefully this thread doesn’t turn into a spamfest liek the rest, but hookarz.

This is just a basic script made for people to learn how to make a system that allows dropping of items in levels that can be seen by all players after reconnecting or leaving and coming back into the level.(furniture and other things…)

Each item on the server is stored in level data like so:

so yeah going to want something like this>

It isn’t completely finished but it’s a good start if anyones trying to do this…
Going to need to make random item numbers for each item when dropped , store drop time and have the item check to see if it is actually still around or have it destroyed…

item “handler”:

if (created){
  toweapons test;
  //just holds X and y so far.. can hold more information obviously..
  setstring server.iteminfo_new1.nw_0,30,30;
  setstring server.iteminfo_new1.nw_1,30,33;
  setstring server.iteminfo_new1.nw_2,33,30;
  placeitems = false;
  chckitemtimer = 1;
  dropitemtimer = -99;

if ((playerenters||timeout)&&isweapon){
  setstring this.level,#L;
  this.items = getflagkeys(server.iteminfo_#s(this.level)_);
  this.maxitems = arraylen(this.items);
  setarray this.itemcheck,this.maxitems;

  if (chckitemtimer>0)chckitemtimer-=0.05;
  if (chckitemtimer<=0){
      for (i=0;i<this.maxitems;i++){
      this.itemcheck[i] = 0;
      setstring iteminfo,#s(server.iteminfo_#s(this.level)_#v(i));
      this.x = strtofloat(#I(iteminfo,0));
      this.y = strtofloat(#I(iteminfo,1));
      triggeraction this.x+.5,this.y+.5,check,#v(playerx),#v(playery),#v(i);
    chckitemtimer = 2;
    dropitemtimer = 1;
  if (dropitemtimer>0)dropitemtimer-=0.05;
  if (dropitemtimer<=0 && !dropitemtimer==-99){
    for (i=0;i<this.maxitems;i++){
      if (this.itemcheck[i]==0){
        setstring iteminfo,#s(server.iteminfo_#s(this.level)_#v(i));
        this.x = strtofloat(#I(iteminfo,0));
        this.y = strtofloat(#I(iteminfo,1));
        putnpc item.txt,item.txt,this.x,this.y;
    dropitemtimer = -99;

if (actionfounditem){
  itemnum = strtofloat(#p(0));
  this.itemcheck[itemnum] = 1;



//make timeout that checks a random number that was created when the item was dropped to check if its still around.. if not destroy;
//going to need to check server time when playertouches and wait 0.1 seconds to see if the time has changed or not in order to deter modem tapping/item duplication.

if (created){
setimg door.png;
if (actioncheck){
//get item info here from serverstrings.
this.x = strtofloat(#p(0));
this.y = strtofloat(#p(1));
this.itemnum = strtofloat(#p(2));
message Item checked for is already Here #v(this.itemnum) npc #v(npcscount);
triggeraction this.x+.5,this.y+.5,founditem,#v(this.itemnum);

your welcome

Read somewhere on here that actionprojectile is better then triggeraction, i used actionprojectile on the one that i scripted for colosso and it worked online … so yeah

wow this is nice, its similar to what i want to do for my furniture system, well done with this its a pretty elegant yet easy to understand piece of code :slight_smile: do you mind if I could take parts of this and use the base of it for my furniture system and ill give reference to you on completion of it?

Personally, when I did serverside item management, it was done via a GServer mod.

Server string setting and comparison is checked on clientside. So even when using server strings, as long as both clients see the server.string validation they can still dupe the item as they would as if there was no protection and a playertouchsme anyway.

Then there is the case that again involves setting and reading is clientside again;
People can over write someone else’s serverstring if they contain the same name.

Think of it like this-

if(playerenters || timeout) { timereverywhere; timeout = 0.1; setstring server.timer,#v(strtofloat(#s(server.timer))+0.1); setplayerprop #c,#s(server.timer); }

And watch people’s timers get mangled and jumbled up as two or more players fight over what the string should be.

Thats why I have an account that is in a level that only it can enter that handles the time string, the account is kept in the level whenever the server is online and is moved around randomly every once in a while to stay alive and not DC… the level name is npcserver.nw

___Merged doublepost__________________

Its public now, anyone can use it as their own…