Blockland Forums > Modification Help
Getting the object created from a default/different function
Trogtor:
For instance, if my script calls servercmdDropTool, that function creates an item in front of the player. How can i get that items object ID when the function gets called?
Potatoh:
call .getid(); when so said item spawns
Trogtor:
theres nothing to use the getID function on. im not asking how to get an object ID. im asking how to find the object that was just spawned.
Crøwn:
Unless the function returns the object it creates, you can't magically get it.
For example:
function makeObject()
{
%obj = new Item();
return %obj;
}
talk(makeObject());
Would print the new object's ID. If you don't return the new object nothing will be echoed.
If you're looking to get an item's ID from serverCmdDropTool you might have to loop through missionCleanup to look for items and find the one that was most recently spawned/belonged to your client.
--- Quote from: Potatoh on October 25, 2017, 03:09:36 PM ---call .getid(); when so said item spawns
--- End quote ---
If you're referring to /getID, that doesn't work on item objects.
Shift Kitty:
Unfortunately, most if not all serverCmds aren't designed to return any value, nor should they be. The problem is that serverCmdDropTool instead contains all the code for dropping a tool, rather than calling a function that would drop the tool and return the object id. If it were like that, then we'd be able to easily just call that function instead and get an object from it to call additional functions on it.
You need to rewrite the entire function if you want to do anything else with it.
--- Quote from: Crøwn on October 25, 2017, 04:31:28 PM ---If you're looking to get an item's ID from serverCmdDropTool you might have to loop through missionCleanup to look for items and find the one that was most recently spawned/belonged to your client.
--- End quote ---
Never do that. Like, ever.
::onAdd exists.