Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GiveItem with removeItem
#1
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. (:
Reply
#2
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
Reply
#3
Can you give me beginning of this script? Current i learn how squirrel work and without - tips - its will be too hard to create.
Reply
#4
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];
}
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  callClientFunc and giveItem Osmith 4 4,394 18.02.2016, 13:04
Last Post: Bimbol

Forum Jump:


Users browsing this thread: