Gothic Online Forums
GiveItem with removeItem - Printable Version

+- Gothic Online Forums (https://archive.gothic-online.com)
+-- Forum: Scripting (English) (https://archive.gothic-online.com/forum-11.html)
+--- Forum: Scripting Help (https://archive.gothic-online.com/forum-12.html)
+--- Thread: GiveItem with removeItem (/thread-2706.html)



GiveItem with removeItem - Flowa - 10.02.2020

Hello. I have a small problem. How i can give item in command and check gold? If player not have a specific amount gold - command will not work and return msg ("You need a <amount> gold"). If gold will be correct with amount - script will give me (for example) armor. 

Maybe whos have a simple script for this or tips how can i do it. (:


RE: GiveItem with removeItem - Quarchodron - 11.02.2020

Well. If u want to do this on server side and i highly recommend that. Save given item to table. U will have to create table wilth all save items. And aftee that u will be able to get amount of Players given item


RE: GiveItem with removeItem - Flowa - 11.02.2020

Can you give me beginning of this script? Current i learn how squirrel work and without - tips - its will be too hard to create.


RE: GiveItem with removeItem - Quarchodron - 11.02.2020

Code:
Well. For start u need to hook old functions too rewrite them.

_giveItem <- giveItem;
_removeItem <- removeItem;

local PItems = {};

for (local i = 0; i < getMaxSlots(); ++i)
{
    PItems[i] <- {};
}


function giveItem(pid, instance, amount)
{
/// ** = = = = = = = = = = = ** \\\
instance = instance.tostring();
local item = instance.toupper();
local id = Items.id(item);
/// ** = = = = = = = = = = = ** \\\
if(id != -1)
{
if(PItems[pid].rawin(id))
    {
PItems[pid][id] = PItems[pid][id] + amount;
}else{
PItems[pid][id] <- amount;
}
_giveItem(pid, id, amount);
}
}

function removeItem(pid, instance, amount)
{
/// ** = = = = = = = = = = = ** \\\
local item = instance.toupper();
local id = Items.id(item);
/// ** = = = = = = = = = = = ** \\\
    if(id != -1)
    {
if(PItems[pid].rawin(id))
{
if(PItems[pid][id] > amount)
{
PItems[pid][id] = PItems[pid][id] - amount;
}
else
{
PItems[pid].rawdelete(id);
}
}
_removeItem(pid, id, amount);
}
}

function getPlayerItems(pid)
{
return PItems[pid];
}