• 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!

doPlayerAddItem for the precise player

ligus

New Member
Joined
Apr 26, 2010
Messages
253
Reaction score
0
Hey, I have this line in script:
Code:
local teamleader = getPlayerNameByGUID(getGlobalStorageValue(15026))

When I want to give him item:
Code:
doPlayerAddItem(teamleader, 2472, 1)

Code:
 [Error - MoveEvents Interface]
(LuaInterface::luaDoPlayerAddItem) Player not found

How can it be solved?
 
Hey!
Code:
//doPlayerAddItem(cid, itemid[, count/subtype = 1[, canDropOnMap = true[, slot = 0]]])
    //doPlayerAddItem(cid, itemid[, count = 1[, canDropOnMap = true[, subtype = 1[, slot = 0]]]])
    //Returns uid of the created item
    lua_register(m_luaState, "doPlayerAddItem", LuaInterface::luaDoPlayerAddItem);

This is good way how to use doPlayerAddItem - player cid. What you are doing is passing there players name. Maybe show whole code, im not sure if there is a way to add item by players guid.

You can only get player cid knowing his GUID with this function:
Code:
//getPlayerByGUID(guid)
    lua_register(m_luaState, "getPlayerByGUID", LuaInterface::luaGetPlayerByGUID);
But this player have to be online if you want to obtain his cid
 
There is code :)
Code:
function onAddItem(moveitem, tileitem, position)
-- middle pos of soccers  field, change it to position where ust be your ball spawned!
local ballpos = {x=524, y=1089, z=7, stackpos=1}
local ball = getThingfromPos(ballpos)
local komanda1 = getPlayerNameByGUID(getGlobalStorageValue(15026))
local komanda2 = getPlayerNameByGUID(getGlobalStorageValue(15027))
if tileitem.actionid == 15027 and moveitem.itemid == 2109 then
local wet = getGlobalStorageValue(15025) + 1
local wet2 = getGlobalStorageValue(15024)
doRemoveItem(moveitem.uid, 1)
doSendMagicEffect(ballpos, 5)
setGlobalStorageValue(15025, wet)
if getGlobalStorageValue(15025) ~= 3 then
doCreateItem(2109, 1, ballpos)
end
doBroadcastMessage("GOOOL, "..komanda1.."'s team score! "..wet2.." : " ..wet.. "!", MESSAGE_EVENT_ADVANCE) 
    if getGlobalStorageValue(15025) == 3 then
    doBroadcastMessage("Game over, "..komanda1.."'s team won! "..wet2.." : " ..wet.. "!", MESSAGE_EVENT_ADVANCE)
    doPlayerAddItem(komanda1, 9020, 6)
    doCreatureSay(komanda1, "Your team won 6 game tokens", TALKTYPE_ORANGE_1)
    doSetItemActionId(doCreateItem(8058, 1, ballpos), 15029)
    end

elseif tileitem.actionid == 15028 and moveitem.itemid == 2109 then
local wet3 = getGlobalStorageValue(15024) + 1
local wet4 = getGlobalStorageValue(15025)
doRemoveItem(moveitem.uid, 1)
doSendMagicEffect(ballpos, 5)
setGlobalStorageValue(15024, wet3)
if getGlobalStorageValue(15024) ~= 3 then
doCreateItem(2109, 1, ballpos)
end
doBroadcastMessage("GOOOL, "..komanda2.."'s team score! "..wet3.." : " ..wet4.. "!", MESSAGE_EVENT_ADVANCE) 
    if getGlobalStorageValue(15024) == 3 then
    doBroadcastMessage("Game over, "..komanda2.."'s team won! "..wet3.." : " ..wet4.. "!", MESSAGE_EVENT_ADVANCE)
    doPlayerAddItem(komanda2, 9020, 6)
    doCreatureSay(komanda2, "Your team won 6 game tokens", TALKTYPE_ORANGE_1)
    doSetItemActionId(doCreateItem(8058, 1, ballpos), 15029)
    end
end
return TRUE
end
 
Try this one wherever you want. I assume that leader is online while soccer match is on.
Code:
local leaderCid = getPlayerByGUID(getGlobalStorageValue(15026))
if leaderCid ~= nil and isPlayer(leaderCid) then
doPlayerAddItem(leaderCid, 2472, 1)
end
 
Back
Top