Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cell AMX_NATIVE_CALL DeleteItem(AMX* amx, cell* params)
- {
- if((int)params[1]) {
- CItem * ptr = CItem::GetItemByUID((unsigned int)params[1]);
- if(ptr != NULL) {
- CItem::DeleteItem(ptr);
- return 1;
- }
- }
- return 0;
- }
- cell AMX_NATIVE_CALL CreateItem(AMX* amx, cell* params)
- {
- // Get the name length
- int iLength = 0;
- cell *pAddress = NULL;
- amx_GetAddr(amx, params[1], &pAddress);
- amx_StrLen(pAddress, &iLength);
- // Make sure the length is valid
- if(!iLength)
- return 0;
- // Make room for the string end
- iLength++;
- // Allocate the name string
- char *szName = new char [iLength];
- // Get the name
- amx_GetString(szName, pAddress, 0, iLength);
- CItem * item = new CItem(szName, (int)params[2], (int)params[3]);
- return item->getUniqueId();
- }
- //////////// kiti failai
- std::deque<CItem *> gItems;
- std::stack<long int> gUnusedUniqueIds;
- CItem * CItem::GetItemByUID(unsigned int uid)
- {
- for(auto i = gItems.begin(); i != gItems.end(); ++i) {
- if((*i)->getUniqueId() == uid) {
- return (*i);
- }
- }
- return NULL;
- }
- void CItem::DeleteItem(CItem * item)
- {
- deque<CItem *>::iterator result;
- result = std::find(gItems.begin(), gItems.end(), item);
- if(result != gItems.end()) {
- gUnusedUniqueIds.push(item->getUniqueId());
- gItems.erase(result);
- delete item;
- }
- }
- void CItem::CreateItem()
- {
- static unsigned int nextUniqueId = 1;
- if(gUnusedUniqueIds.empty()) {
- uniqueId = nextUniqueId++;
- }
- else {
- uniqueId = gUnusedUniqueIds.top();
- gUnusedUniqueIds.pop();
- }
- gItems.push_back(this);
- }
- CItem::CItem(string id) : itemId(id), itemCount(1), itemLevel(1)
- {
- CreateItem();
- }
- CItem::CItem(string id, int count) : itemId(id), itemCount(count), itemLevel(1)
- {
- CreateItem();
- }
- CItem::CItem(string id, int count, int level) : itemId(id), itemCount(count), itemLevel(level)
- {
- CreateItem();
- }
Advertisement
Add Comment
Please, Sign In to add comment