[REQUEST] Item

Place for sharing your game modifications for Life is Feudal: Your Own

Amad
 
Posts: 7
Joined: 27 Apr 2016, 12:27

[REQUEST] Item

Post by Amad » 25 Oct 2016, 10:51

Hello everyone

I want to give and take items realtime from user's backback. I already accomplished give and take part via database but user must be re-log in to game to see changes. Is there a way to doing this realtime ?

Any help will be appreciated :friends:


Alakar
Beta Tester
 
Posts: 202
Joined: 23 Jan 2015, 07:39

Re: [REQUEST] Item

Post by Alakar » 25 Oct 2016, 21:49

Amad wrote:Hello everyone

I want to give and take items realtime from user's backback. I already accomplished give and take part via database but user must be re-log in to game to see changes. Is there a way to doing this realtime ?

Any help will be appreciated :friends:


Already possible that is how I made a market...


Amad
 
Posts: 7
Joined: 27 Apr 2016, 12:27

Re: [REQUEST] Item

Post by Amad » 26 Oct 2016, 04:46

Alakarsiann wrote:
Amad wrote:Hello everyone

I want to give and take items realtime from user's backback. I already accomplished give and take part via database but user must be re-log in to game to see changes. Is there a way to doing this realtime ?

Any help will be appreciated :friends:


Already possible that is how I made a market...


Would you like to share `how` ? I do not know debugging thing and i can't find a video about it.


Fetsstef
Beta Tester
 
Posts: 2
Joined: 08 Dec 2014, 13:25

Re: [REQUEST] Item

Post by Fetsstef » 29 Oct 2016, 11:13

Hello,

i' have find a way for these, but actualy it's not realy the best way, mostly if you want take a amount of a stack in the inventory.

it's work very good for add or remove a complete stack, but for a amount of item you need to remove the full stack and give the difference.

I need to find a best way but for now, i can't interacte with the inventory item directly in the player class.

Now the code:

Code: Select all
//Searches through the player list and tries to find the player with the given id
function getPlayer(%pid)
{
   for(%id = 0; %id < ClientGroup.getCount(); %id++)
   {
      %client = ClientGroup.getObject(%id);
      
      if(%pid == %client.getCharacterId())
      {
         return %client;
      }
   }
   return 0;
}

// add a item to the player inventory
function addItemToPlayerInventory(%pid, %itemType, %quantity, %quality, %durability, %createdDurability)
{
   %client = getPlayer(%pid);
   if(%client != 0)
      %client.player.inventoryAddItem(%itemType, %quantity, %quality, %durability, %createdDurability );
}

//Remove the item to the player inventory (remove full stack)
function removeItemToPlayerInventory(%pid, %itemType)
{
   %client = getPlayer(%pid);
   if(%client != 0)
      %client.player.inventoryRemoveItem(%itemType);
}


put this code in a files on the server "/mods/itemInventory.cs" for exempale, and execute it by adding the code in the end of "main.cs" file
Code: Select all
exec("mods/itemInventory.cs");


After you can use this two command in cs files or in console server :

Add 10 gold coin quality 100 in the player id 1 inventory
Code: Select all
addItemToPlayerInventory(1, 1061, 10, 100, 0, 0);


//remove item with the id 10 in the "items" table to the player 10 inventory
Code: Select all
removeItemToPlayerInventory(1, 10);


To remove a amount of item of a stack you need ti remove the item and add the difference, the item will be move in the player inventory and the player get a message "You receive X item ..."


if someone has a better way to do that, i really need this.

Sorry for my english i'm not really good for this

User avatar
Arzin
Beta Tester
 
Posts: 33
Joined: 01 Oct 2015, 15:18

Re: [REQUEST] Item

Post by Arzin » 01 Dec 2016, 01:10

is it possible to give it to everyone at single time.
For example, instead of giving 10 coins to single person, you can give 10 coins to everyone ?


Fetsstef
Beta Tester
 
Posts: 2
Joined: 08 Dec 2014, 13:25

Re: [REQUEST] Item

Post by Fetsstef » 01 Dec 2016, 10:48

You can add a function for this

Code: Select all
// add a item to all player inventory
function addItemToAllPlayerInventory(%itemType, %quantity, %quality, %durability, %createdDurability)
{
   for(%id = 0; %id < ClientGroup.getCount(); %id++)
   {
      %client = ClientGroup.getObject(%id);
     
             if(%client != 0)
             {
                   %client.player.inventoryAddItem(%itemType, %quantity, %quality, %durability, %createdDurability );
             }
     }
}



To give 10 coins ti everyone use :
Code: Select all
addItemToAllPlayerInventory(1061, 10, 10, 0, 0);


Alakar
Beta Tester
 
Posts: 202
Joined: 23 Jan 2015, 07:39

Re: [REQUEST] Item

Post by Alakar » 02 Dec 2016, 05:50

May want to make sure the Player exists too...

for example
Code: Select all
function EveryoneGetsACopperCoin()
{
   %count = ClientGroup.getCount();
   for (%i=0;%i<%count;%i++) {
      %obj = ClientGroup.getObject(%i);
      if (!isObject(%obj)) {
         continue;
      }
      if (%obj.getClassName() $= "Player") {
         %obj.inventoryAddItem(1059, 1, 100, 20000, 20000);
      }
   }
}

User avatar
Arzin
Beta Tester
 
Posts: 33
Joined: 01 Oct 2015, 15:18

Re: [REQUEST] Item

Post by Arzin » 02 Dec 2016, 11:11

Thank you guys, it worked.
@Alakarsiann - You mentioned that you made market functional, is there any way you could share some intel ?


Tobias0412
 
Posts: 32
Joined: 06 Dec 2016, 21:15

Re: [REQUEST] Item

Post by Tobias0412 » 08 Jan 2017, 06:11

Works fine, but is there any way to make it trigger with ingame actions ?
I want to set up something like a market.

My idea was something about...
IF Player puts 1 bar in warehouse (container id) execute add command and give him 1 coin.
IF Player takes 1 bar from warehouse (container id) execute delete command and take 1 coin....

Is this possible in any way ?


Sebbbbyocum
 
Posts: 12
Joined: 03 Jun 2017, 06:32

Re: [REQUEST] Item

Post by Sebbbbyocum » 03 Jun 2017, 19:03

This is not working for me, whenever i try to execute
Code: Select all
addItemToAllPlayerInventory(1061, 10, 10, 0, 0);



in-game it says unable to find the function addItemToAllPlayerInventory

yes i have exec(“mods/itemInventory.cs”); in my main.cs

This is what my /mods/iteminventory.cs looks like btw:
Code: Select all
//Searches through the player list and tries to find the player with the given id
function getPlayer(%pid)
{
   for(%id = 0; %id < ClientGroup.getCount(); %id++)
   {
      %client = ClientGroup.getObject(%id);
     
      if(%pid == %client.getCharacterId())
      {
         return %client;
      }
   }
   return 0;
}

// add a item to the player inventory
function addItemToPlayerInventory(%pid, %itemType, %quantity, %quality, %durability, %createdDurability)
{
   %client = getPlayer(%pid);
   if(%client != 0)
      %client.player.inventoryAddItem(%itemType, %quantity, %quality, %durability, %createdDurability );
}

// add a item to all player inventory
function addItemToAllPlayerInventory(%itemType, %quantity, %quality, %durability, %createdDurability)
{
   for(%id = 0; %id < ClientGroup.getCount(); %id++)
   {
      %client = ClientGroup.getObject(%id);
     
             if(%client != 0)
             {
                   %client.player.inventoryAddItem(%itemType, %quantity, %quality, %durability, %createdDurability );
             }
     }
}

//Remove the item to the player inventory (remove full stack)
function removeItemToPlayerInventory(%pid, %itemType)
{
   %client = getPlayer(%pid);
   if(%client != 0)
      %client.player.inventoryRemoveItem(%itemType);
}


Nothing_Personal
Zealous Believer
 
Posts: 52
Joined: 16 Mar 2016, 18:25

Re: [REQUEST] Item

Post by Nothing_Personal » 05 Jun 2017, 18:40

Sebbbbyocum wrote:This is not working for me, whenever i try to execute
Code: Select all
addItemToAllPlayerInventory(1061, 10, 10, 0, 0);



in-game it says unable to find the function addItemToAllPlayerInventory

yes i have exec(“mods/itemInventory.cs”); in my main.cs

This is what my /mods/iteminventory.cs looks like btw:
Code: Select all
//Searches through the player list and tries to find the player with the given id
function getPlayer(%pid)
{
   for(%id = 0; %id < ClientGroup.getCount(); %id++)
   {
      %client = ClientGroup.getObject(%id);
     
      if(%pid == %client.getCharacterId())
      {
         return %client;
      }
   }
   return 0;
}

// add a item to the player inventory
function addItemToPlayerInventory(%pid, %itemType, %quantity, %quality, %durability, %createdDurability)
{
   %client = getPlayer(%pid);
   if(%client != 0)
      %client.player.inventoryAddItem(%itemType, %quantity, %quality, %durability, %createdDurability );
}

// add a item to all player inventory
function addItemToAllPlayerInventory(%itemType, %quantity, %quality, %durability, %createdDurability)
{
   for(%id = 0; %id < ClientGroup.getCount(); %id++)
   {
      %client = ClientGroup.getObject(%id);
     
             if(%client != 0)
             {
                   %client.player.inventoryAddItem(%itemType, %quantity, %quality, %durability, %createdDurability );
             }
     }
}

//Remove the item to the player inventory (remove full stack)
function removeItemToPlayerInventory(%pid, %itemType)
{
   %client = getPlayer(%pid);
   if(%client != 0)
      %client.player.inventoryRemoveItem(%itemType);
}


That's because you don't run this cs or these commands from a game client, you run them from server scripting or the server console window.


Sebbbbyocum
 
Posts: 12
Joined: 03 Jun 2017, 06:32

Re: [REQUEST] Item

Post by Sebbbbyocum » 05 Jun 2017, 23:25

Nothing_Personal wrote:
Sebbbbyocum wrote:This is not working for me, whenever i try to execute
Code: Select all
addItemToAllPlayerInventory(1061, 10, 10, 0, 0);



in-game it says unable to find the function addItemToAllPlayerInventory

yes i have exec(“mods/itemInventory.cs”); in my main.cs

This is what my /mods/iteminventory.cs looks like btw:
Code: Select all
//Searches through the player list and tries to find the player with the given id
function getPlayer(%pid)
{
   for(%id = 0; %id < ClientGroup.getCount(); %id++)
   {
      %client = ClientGroup.getObject(%id);
     
      if(%pid == %client.getCharacterId())
      {
         return %client;
      }
   }
   return 0;
}

// add a item to the player inventory
function addItemToPlayerInventory(%pid, %itemType, %quantity, %quality, %durability, %createdDurability)
{
   %client = getPlayer(%pid);
   if(%client != 0)
      %client.player.inventoryAddItem(%itemType, %quantity, %quality, %durability, %createdDurability );
}

// add a item to all player inventory
function addItemToAllPlayerInventory(%itemType, %quantity, %quality, %durability, %createdDurability)
{
   for(%id = 0; %id < ClientGroup.getCount(); %id++)
   {
      %client = ClientGroup.getObject(%id);
     
             if(%client != 0)
             {
                   %client.player.inventoryAddItem(%itemType, %quantity, %quality, %durability, %createdDurability );
             }
     }
}

//Remove the item to the player inventory (remove full stack)
function removeItemToPlayerInventory(%pid, %itemType)
{
   %client = getPlayer(%pid);
   if(%client != 0)
      %client.player.inventoryRemoveItem(%itemType);
}


That's because you don't run this cs or these commands from a game client, you run them from server scripting or the server console window.


Unfortunately i am using bluefang and their console is read-only. Can you explain to me what server scripting is? Maybe that is a way i can accomplish it. Thank you


Nothing_Personal
Zealous Believer
 
Posts: 52
Joined: 16 Mar 2016, 18:25

Re: [REQUEST] Item

Post by Nothing_Personal » 06 Jun 2017, 00:06

Do you have access to the server to at least add files to it? If you can't place files in the server and the console is read only I don't know what you can do.


Sebbbbyocum
 
Posts: 12
Joined: 03 Jun 2017, 06:32

Re: [REQUEST] Item

Post by Sebbbbyocum » 06 Jun 2017, 00:18

Nothing_Personal wrote:Do you have access to the server to at least add files to it? If you can't place files in the server and the console is read only I don't know what you can do.


Yes i have access to the mySQL DB and the server files. I can add files too it if necessary/needed. That's how i was able to place the mods/itemInventory.cs folder and file.


Sebbbbyocum
 
Posts: 12
Joined: 03 Jun 2017, 06:32

Re: [REQUEST] Item

Post by Sebbbbyocum » 09 Jun 2017, 02:16

bump, would really appreciate if anyone can help me resolve this issue im having or help me to find another way to execute the script without console access.

Return to Game mods