> 神唱K歌 > 点击座椅自动坐下的脚本内容

点击座椅自动坐下的脚本内容

以下内容为点击物品(座椅)自动坐下的脚本,制作时请注意模型最好使用方形平整的物体(适用于坐下),另外物体摆放时高低也要注意。

MyTable =
{
EntryInfo = {ONLOADED,"state1"};
StateList = {"state1","state2"};
state1 =
{
Timer = -1,
TimeOut = -1,
NextState = "nil",
EventList = {ONTOUCH,ONCLICK};
};

state2 =
{
Timer = 100,
TimeOut = -1,
NextState = "nil",
EventList = {ONTOUCH,ONCLICK};
};
}

function MyTable.state1.OnEnter(args)
sit=0
uPrintf(sit);
end

function MyTable.state1.OnTouch(args)
uisavailable()
end

function MyTable.state1.OnClick(args)
uisavailable()
end

function uisavailable()
if sit==0 then uposcompare();
else
uSayChannel(uGetPlayerName(uGetToucherId()).."此座位已有人。");
end
end

function uposcompare()
playerid=uGetToucherId();
itemid=uGetItemId();
itempos = uGetItemPos(itemid);
playerpos=uGetPlayerPos (playerid);
orient = uGetItemOrient(itemid);
if uAbs(playerpos.x-itempos.x)<4 and uAbs( playerpos.y-itempos.y)<4 then
uTransState("state2");
else
uSayChannel(uGetPlayerName(uGetToucherId()).."距离过远");
uTransState("state1");
end
end

function MyTable.state1.OnExit(args)
end

function MyTable.state2.OnEnter(args)
if uWorldServer. ulGetPlayerAge (playerid)==2 and uWorldServer. ulGetPlayerSex (playerid)==0 then--成年男坐标
goalpos = G3D.Vector3:new(itempos.x,itempos.y+0.6,itempos.z+0.2);
elseif uWorldServer. ulGetPlayerAge (playerid)==2 and uWorldServer. ulGetPlayerSex (playerid)==1 then--成年女坐标
goalpos = G3D.Vector3:new(itempos.x,itempos.y-1.15,itempos.z+0.2);
elseif uWorldServer. ulGetPlayerAge (playerid)==1 and uWorldServer. ulGetPlayerSex (playerid)==0 then--未成年男坐标
goalpos = G3D.Vector3:new(itempos.x,itempos.y+0.5,itempos.z+0.2);
elseif uWorldServer. ulGetPlayerAge (playerid)==1 and uWorldServer. ulGetPlayerSex (playerid)==1 then--未成年女坐标
goalpos = G3D.Vector3:new(itempos.x,itempos.y-0.6,itempos.z+0.2);
end
sit=1
uSetPlayerOrient(playerid,orient.z);--调整朝向,转90度就改成z+90,190亦然
uSetPlayerPos(playerid,goalpos);
uPlayOperatorAct("idlechair",playerid);
uPrintf(sit);
end

function MyTable.state2.OnTimer(args)
playerpos=uGetPlayerPos (playerid);
if uAbs(playerpos.x-goalpos.x)<0.5 and uAbs( playerpos.y-goalpos.y)<0.5 then
sit=1
else
if uAbs(playerpos.x-goalpos.x)>0.5 and uAbs( playerpos.y-goalpos.y)>0.5 then
uTransState("state1");
end
end
end

function MyTable.state2.OnTouch(args)
uisavailable()
end

function MyTable.state2.OnClick(args)
uisavailable()
end

function MyTable.state2.OnExit(args)
end