Author Topic: OnPlayerWithItemTouch?  (Read 1636 times)

Okay guys, so I am wondering if I could get some help on an event.
What I want it to basically do is find out what item the player is holding. If the item is related to

Code: [Select]
"datablock ItemData", 1);
then it would do whatever the player schedules it to do with the other event, onPlayerWithItemTouched.

What I have so far, which isn't much...

Code: [Select]
registerInputEvent("OnItemTouch", "Self", "datablock ItemData", 1);

Haha :) any help would be much appreciated. I suck at scripting events.
« Last Edit: February 02, 2011, 08:47:54 PM by ::Matt:: »

Let me see if I actually understand what you're wanting to check for before I try to explain it...

You're trying to set an input that's triggered when a player collides with a brick, but only when s/he has a specific item in their inventory?

If you want to test for which a player hits a brick with a specific item, that should come default with every item.

Code: [Select]
function ItemImage::onHitObject(%this, %player, %slot, %col, %pos, %normal)

Let me see if I actually understand what you're wanting to check for before I try to explain it...

You're trying to set an input that's triggered when a player collides with a brick, but only when s/he has a specific item in their inventory?

Precisely! :)

If you want to test for which a player hits a brick with a specific item, that should come default with every item.

Code: [Select]
function ItemImage::onHitObject(%this, %player, %slot, %col, %pos, %normal)

Ok, I'll try it.

To be able to pick an item type you'd need something like this which doesn't exist in the game yet.

Erm, if that were the way things worked, we'd have to revise all of our addons to meet that. BEsides, that's possible with VCE.

Well the idea was that kind of selector would be optional - existing events wouldn't use it unless specifically changed to.

Well the idea was that kind of selector would be optional - existing events wouldn't use it unless specifically changed to.

So basically what you're saying is that there is no way for me to do this?

I dont think thats what he meant; by what you said to me you want to make it go by the item's UIname.

Sorry meant to quote this...

To be able to pick an item type you'd need something like this which doesn't exist in the game yet.

Sorry meant to quote this...

If you're looking for "on player with a specific item you're making - touch", that is possible.

If you're looking for an event which lets you pick an item out of any that exist on the server, it's not possible yet. Truce was making something like that idea I posted but stopped working on it about a year ago...

Truce was making something like that idea I posted but stopped working on it about a year ago...

http://forum.blockland.us/index.php?topic=94935.0

I know I had a reason I stopped working on it, but I can't remember what it was, since this was from the end of 2009. I'm pretty sure I got it working though - it was probably just some optimization I was too lazy to put in (I made the mod during a long car ride). Anyway, I still have the files, so if someone wants to play around with it, touch it up, and release it, then be my guest:

Code: (server.cs) [Select]
function registerInputParameter(%inputEvent,%parameters,%callback)
{
if(!isObject(InputParameters_ServerList))
new SimGroup(InputParameters_ServerList);

if(strPos("\tdatablock\tlist\tstring\tint\t","\t" @ getWord(%parameters,0) @ "\t") == -1)
return;

%entry = hasInputParameter_Server(%inputEvent);

if(%entry != -1)
InputParameters_ServerList.remove(%entry);

%entry = new ScriptObject()
{
inputEvent = %inputEvent;
parameters = %parameters;
callback = %callback;
};

InputParameters_ServerList.add(%entry);
}

function hasInputParameter_Server(%inputEvent)
{
if(!isObject(InputParameters_ServerList))
return -1;

for(%i = 0; %i < InputParameters_ServerList.getCount(); %i++)
{
%entry = InputParameters_ServerList.getObject(%i);

if(%entry.inputEvent $= %inputEvent)
return %entry;
}

return -1;
}

function serverCmdRequestInputParameters(%client)
{
commandToClient(%client,'clearInputParameters');

if(!isObject(InputParameters_ServerList))
return;

for(%i = 0; %i < InputParameters_ServerList.getCount(); %i++)
{
%entry = InputParameters_ServerList.getObject(%i);
commandToClient(%client,'registerInputParameter',%entry.inputEvent,%entry.parameters);
}
}

function serverCmdAddInputParameter(%client,%index,%parameter)
{
%brick = %client.wrenchBrick;

if(isObject(%brick))
%brick.eventInputParameter[%index] = %parameter;
}

package InputParameters_Server
{
function serverCmdRequestWrenchEvents(%client)
{
Parent::serverCmdRequestWrenchEvents(%client);
%brick = %client.wrenchBrick;

for(%i = 0; %i < %brick.numEvents; %i++)
{
%inputParameter = %brick.eventInputParameter[%i];

if(%inputParameter !$= "")
commandToClient(%client,'addInputParameter',%i,%inputParameter);
}
}

function fxDTSBrick::processInputEvent(%this,%inputEvent,%client)
{
for(%i = 0; %i < %this.numEvents; %i++)
{
%event = %this.serializeEvent(%i);
%input = getField(%event,1);

if(!getField(%event,0) || $InputEvent_Name["fxDTSBrick",%input] !$= %inputEvent)
continue;

%callback = hasInputParameter_Server(%inputEvent).callback;

if(isFunction(%callback))
{
if(!call(%callback,%this,%this.eventInputParameter[%i],%client))
continue;
}

%string = ".schedule(" @ getField(%event,2) @ ",";
%target = getField(%event,3);

if(%target == -1)
{
%class = "fxDTSBrick";

%group = %this.getGroup();
%index = getField(%event,4);
%name = %group.NTName[%index];

%targetList = "";

for(%j = 0; %j < %group.NTObjectCount[%name]; %j++)
%targetList = %targetList @ %group.NTObject[%name,%j] @ "\t";

%targetList = getSubStr(%targetList,0,strLen(%targetList) - 1);
}
else
{
%class = inputEvent_GetTargetClass("fxDTSBrick",%input,%target);

for(%j = 0; %j < getFieldCount($InputEvent_TargetList["fxDTSBrick",%input]); %j++)
{
%field = getField($InputEvent_TargetList["fxDTSBrick",%input],%j);

if(getWord(%field,1) $= %class)
{
%targetList = $InputTarget_[getWord(%field,0)];
break;
}
}
}

%output = getField(%event,5);
%string = %string @ "\"" @ $OutputEvent_Name[%class,%output] @ "\",";

for(%j = 0; %j < outputEvent_GetNumParametersFromIdx(%class,%output); %j++)
%string = %string @ "\"" @ getField(%event,6 + %j) @ "\",";

if($OutputEvent_AppendClient[%class,%output])
%string = %string @ "1,";

%string = getSubStr(%string,0,strLen(%string) -1) @ ");";

for(%j = 0; %j < getFieldCount(%targetList); %j++)
{
%eval = getField(%targetList,%j) @ %string;

echo(%eval);
eval(%eval);
}
}
}
};
activatePackage(InputParameters_Server);

Code: (client.cs) [Select]
package InputParameters_Client
{
function WrenchEventsDlg::reshuffleScrollbox(%this,%swatch)
{
%object = %swatch.inputParameter;

if(isObject(%object))
%object.delete();

Parent::reshuffleScrollbox(%this,%swatch);
}

function WrenchEventsDlg::createTargetList(%this,%swatch,%box)
{
Parent::createTargetList(%this,%swatch,%box);

%object = %swatch.inputParameter;

if(isObject(%object))
%object.delete();

if(!isObject(InputParameters_ClientList))
return;

%input = %box.getValue();
%parameters = hasInputParameter_Client(%input).parameters;

if(%parameters $= "")
return;

switch$(getWord(%parameters,0))
{
case "datablock":
%object = InputParameters_NewPopup(getWord(%swatch.getPosition(),1) + 19);
%dataClass = getWord(%parameters,1);

for(%i = 0; %i < DatablockGroup.getCount(); %i++)
{
%datablock = DatablockGroup.getObject(%i);
%uiName = %datablock.uiName;

if(%datablock.getClassName() $= %dataClass && %uiName !$= "")
%object.add(%uiName,%datablock);
}

%object.sort();
%object.addFront("NONE",-1);

%object.setSelected(-1);

case "list":
%object = InputParameters_NewPopup(getWord(%swatch.getPosition(),1) + 19);

for(%i = 1; %i < getWordCount(%parameters); %i += 2)
%object.add(getWord(%parameters,%i),getWord(%parameters,%i + 1));

%object.setSelected(0);

case "string":
%object = InputParameters_NewTextbox(getWord(%swatch.getPosition(),1) + 19);
%object.maxLength = getWord(%parameters,1);

%object.setValue(getWords(%parameters,2));

case "int":
%min = getWord(%parameters,1);
%object = InputParameters_NewTextbox(getWord(%swatch.getPosition(),1) + 19);
%object.command = "$ThisControl.setText(mClamp($ThisControl.getValue()," @ %min @ "," @ getWord(%parameters,2) @ "));";

%default = getWords(%parameters,3);

if(%default $= "")
%object.setValue(%min);
else
%object.setValue(%default);
}

%swatch.inputParameter = %object;
WrenchEvents_Scroll.add(%object);
}

function WrenchEventsDlg::send(%this)
{
Parent::send(%this);

for(%i = 0; %i < WrenchEvents_Box.getCount() - 1; %i++)
{
%parameter = WrenchEvents_Box.getObject(%i).inputParameter;

if(isObject(%parameter))
{
switch$(%parameter.getClassName())
{
case "GuiPopUpMenuCtrl":
commandToServer('addInputParameter',%i,%parameter.getSelected());

case "GuiTextEditCtrl":
commandToServer('addInputParameter',%i,%parameter.getValue());
}
}
else
commandToServer('addInputParameter',%i,"");
}
}
};
activatePackage(InputParameters_Client);

function hasInputParameter_Client(%inputEvent)
{
if(!isObject(InputParameters_ClientList))
return -1;

for(%i = 0; %i < InputParameters_ClientList.getCount(); %i++)
{
%entry = InputParameters_ClientList.getObject(%i);

if(%entry.inputEvent $= %inputEvent)
return %entry;
}

return -1;
}

function clientCmdClearInputParameters()
{
if(isObject(InputParameters_ClientList))
InputParameters_ClientList.clear();
}

function clientCmdRegisterInputParameter(%inputEvent,%parameters)
{
if(!isObject(InputParameters_ClientList))
new SimGroup(InputParameters_ClientList);

%entry = hasInputParameter_Client(%inputEvent);

if(%entry != -1)
InputParameters_ClientList.remove(%entry);

%entry = new ScriptObject()
{
inputEvent = %inputEvent;
parameters = %parameters;
};

InputParameters_ClientList.add(%entry);
}

function clientCmdAddInputParameter(%index,%parameter)
{
%object = WrenchEvents_Box.getObject(%index).inputParameter;

switch$(%object.getClassName())
{
case "GuiPopUpMenuCtrl":
%object.setSelected(%parameter);

case "GuiTextEditCtrl":
%object.setValue(%parameter);
}
}

function InputParameters_NewPopup(%y)
{
%object = new GuiPopUpMenuCtrl()
{
profile        = "GuiPopUpMenuProfile";
horizSizing    = "right";
vertSizing     = "bottom";
position       = "76 " @ %y;
extent         = "100 18";
minExtent      = "8 2";
visible        = 1;
maxLength      = 255;
maxPopupHeight = 200;
};

return %object;
}

function InputParameters_NewTextbox(%y,%command)
{
%object = new GuiTextEditCtrl()
{
profile        = "GuiTextEditProfile";
horizSizing    = "right";
vertSizing     = "bottom";
position       = "76 " @ %y;
extent         = "100 18";
minExtent      = "8 2";
visible        = 1;
maxLength      = 255;
};

return %object;
}

Code: (example.cs) [Select]
function Check_onProjectileHit(%brick,%parameter,%client)
{
return (%parameter $= "" || %parameter == -1 || $InputTarget_["Projectile"].getDatablock() == %parameter);
}

registerInputParameter("onProjectileHit","datablock ProjectileData","Check_onProjectileHit");

http://forum.blockland.us/index.php?topic=94935.0

I know I had a reason I stopped working on it, but I can't remember what it was, since this was from the end of 2009. I'm pretty sure I got it working though - it was probably just some optimization I was too lazy to put in (I made the mod during a long car ride). Anyway, I still have the files, so if someone wants to play around with it, touch it up, and release it, then be my guest:

-megasnipofdoom-

Don't you get like, really nauseous when you do this?
I wouldn't be able to do it. D:

http://forum.blockland.us/index.php?topic=94935.0

I know I had a reason I stopped working on it, but I can't remember what it was, since this was from the end of 2009. I'm pretty sure I got it working though - it was probably just some optimization I was too lazy to put in (I made the mod during a long car ride). Anyway, I still have the files, so if someone wants to play around with it, touch it up, and release it, then be my guest:

Code: (server.cs) [Select]
-snip-

Wow this is pretty hardcore. I'll see if I can mess around with it a little.
I just looked through the server, is there anywhere in it I need a
Code: [Select]
exec("./client.cs");
« Last Edit: February 03, 2011, 10:58:26 PM by ::Matt:: »