• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[8.1][Talkactions] Make item on position command!

Azi

Banned User
Joined
Aug 12, 2007
Messages
1,167
Reaction score
53
Location
Włocławek
[Talkactions] Make item on position command!

Hello!
I made simple script to make item on a select title

Example:
I'm in pos 100,100,7
and i need to make Magic Plate Armor on position 164,247,8
I'm using
!makeitem "2472, 1, 164 247 8

-- !makeitem "ITEMID, COUNT OF ITEM, POS_X, POS_Y, POS_Z

script made by me.

make new file newitem.lua in data/talkactions/scripts folder and put into file this code:
Code:
-- Make Item on Pos Talkaction by ersiu!
-- !makeitem "itemid, count, posx posy posz
-- EXAMPLE:
-- !makeitem "2472, 1, 42 65 7
function onSay(cid, words, param)
 local access = 3 -- access do uzywania komendy! 
 if(getPlayerAccess(cid) >= access)then
  local item={}
  local info = {'f1' = string.find(param, ','), 'itemid' = string.sub(param, 0, info.f1-1), 'countn' = string.sub(param, info.f1+1, string.len(param)), 'c1' = string.find(info.countn, ','), 'count' = string.sub(info.c1, 0, info.c1-1), 'topos' = string.sub(info.c1, info.c1+1, string.len(info.countn)), 'pos' = string.sub(info.topos, info.f1+1, string.len(info.topos)), 'f2' = string.find(info.pos, ' '), 'p1' = string.sub(info.pos, 0, info.f2-1), 'pos2' = string.sub(info.pos, info.f2+1, string.len(info.pos)), 'f2' = string.find(info.pos2, ' '),  'p2' = string.sub(info.pos2, 0, info.f2-1), 'p3' = string.sub(info.pos2, info.f3+1, string.len(info.pos2))}
   item.itemid = info.itemid
   item.count = info.count
   item.x = info.p1
   item.y = info.p2
   item.z = info.p3
    ground = getThingfromPos({x=item.x, y=item.y, z=item.z, stackpos=0})
    if(ground.itemid ~= nil)then
	 if(item.itemid ~= nil and item.count ~= nil && item.x > 0 and item.y > 0 and item.z > 0)then
     doCreateItem(item.itemid, item.count, {x=item.x, y=item.y, z=item.z})
     else
	 doPlayerSendCancel(cid, 'Sorry cannot make a new item!')
	else
    doPlayerSendCancel(cid, 'Sorry, title don\'t found')
    end
 else
 doPlayerSendCancel(cid, 'Sorry, you cannot execute this command.')
 end
end
talkactions.XML
edit talkactions.xml in data/talkactions folder and put under "<talkactions>"
Code:
<talkaction words="!makeitem" script="newitem.lua" />
Thanks you!

Your's,
ersiu!
 
Last edited:
Hahh, awesome! Is it possible to also remove item id on pos x y z?

etc im standing on 100x 100y 7z
and i want to remove a red backpack on id 120x 120y 6z

Would it be possible to make !r 2000, 1, 120 120 6 ?

Since if this is possible, then we need a npc that can execute theese talkactions, and you got a whole new world of stuff you can make, like quests and such things where you temporarly open/close a place, and then later open it again etc...
 
Script is bugged, have you even tested it? -.-

PHP:
--# Make Item on Pos Talkaction by ersiu and Colandus
--# !makeitem "itemid, count, posx posy posz
--# EXAMPLE:
--# !makeitem "2472, 1, 42 65 7

local access = 3

function onSay(cid, words, param)
	if getPlayerAccess(cid) < access then
		doPlayerSendCancel(cid, 'Sorry, you cannot execute this command.')
	end

	local info = string.explode(param, ",")
	local item = {
		itemid = info[1],
		count = info[2]
	}

	if type(item.itemid) ~= "number" then
		return warnPlayer(cid, "Please enter a valid itemid.")
	elseif type(item.count) ~= "number" then
		return warnPlayer(cid, "Please enter a valid count.")
	elseif info[3] == nil then
		return warnPlayer(cid, "Please enter a position.")
	end

	local t = string.explode(info[3], " ")
	local pos = tableToPos(t, 0)
	if pos == false then
		return warnPlayer(cid, "Please enter a valid position.")
	elseif positionExists(pos) == false then
		return warnPlayer(cid, "Position does not exist!")
	end

	doCreateItem(item.itemid, item.count, {x=item.x, y=item.y, z=item.z})
	return TRUE
end

Needed functions:
PHP:
function string.trim(str) 
    -- Function by Colandus 
    return (string.gsub(str, "^%s*(.-)%s*$", "%1")) 
end 

function string.explode(str, sep)  
    -- Function by Colandus 
    local pos, t = 1, {} 
    if #sep == 0 or #str == 0 then return end 
    for s, e in function() return string.find(str, sep, pos) end do 
        table.insert(t, string.trim(string.sub(str, pos, s-1))) 
        pos = e+1 
    end 
    table.insert(t, string.trim(string.sub(str, pos))) 
    return t 
end

function tableToPos(t, stack) 
    -- Function by Colandus 
    if type(t) == "table" and #t == 3 and tonumber(table.concat(t)) then 
	    local pos = {x=tonumber(t[1]), y=tonumber(t[2]), z=tonumber(t[3])} 
		if stack then pos.stackpos = stack end
		return pos
    end 
    return FALSE 
end 

function positionExists(pos) 
    -- Function by Pedro B. and Colandus 
    return getTileThingByPos(pos) > -1 
end 

function warnPlayer(cid, msg) 
    -- Function by Colandus 
    doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF) 
    return doPlayerSendCancel(cid, msg) 
end


Regards,
Colandus
 
I always knew Colandus is the best :)
Colandus pwn u all!!
 
Back
Top