Hey there,
I'm currently creating some basic script to create live in my station.
I'm currently studing in computer science but i didn't have any experience in LUA.
Then i beginned by checking how the forgotten tutorial station with all the NPC worked.
I checked the lines,functions and variables to see how it work... but no one have passive action,
you need to talk to it so they start his script...
I made some functions to make moved the NPC but you need to talk to him so it's restart to move to a another position.
Using a infinite loop just freeze the game and i don't found how to detect when moving function is done.
Any ideas?
I'm currently creating some basic script to create live in my station.
I'm currently studing in computer science but i didn't have any experience in LUA.
Then i beginned by checking how the forgotten tutorial station with all the NPC worked.
I checked the lines,functions and variables to see how it work... but no one have passive action,
you need to talk to it so they start his script...
I made some functions to make moved the NPC but you need to talk to him so it's restart to move to a another position.
Using a infinite loop just freeze the game and i don't found how to detect when moving function is done.
Any ideas?
Code:
function dist2(x,z) --to get distance between input and center of the station
return ((x-16)*(x-16))+((z-16)*(z-16));
end
function distanceBonne(x,z) -- see if it's in the circle of walking area
return dist2(x,z)>42*42 and dist2(x,z)<90*90;
end
function moveToHookFunc(dialogObject, x, y, z)
--dialogObject:giveGravity(true);
return dialogObject:moveTo(x,y,z);
end
function create(dialogObject, bindings) -- main
math.randomseed(os.time()) -- random for later
print(bindings) -- start NPC general code
print(dialogObject)
dSysClass = luajava.bindClass( "org.schema.game.common.data.player.dialog.DialogSystem" );
dSysFactoryClass = luajava.bindClass( "org.schema.game.common.data.player.dialog.DialogStateMachineFactory" );
dSysEntryClass = luajava.bindClass( "org.schema.game.common.data.player.dialog.DialogStateMachineFactoryEntry" );
hookClass = luajava.bindClass( "org.schema.game.common.data.player.dialog.DialogTextEntryHookLua" );
dSys = luajava.newInstance( "org.schema.game.common.data.player.dialog.DialogSystem", dialogObject );
print(dSys);
factory = dSys:getFactory(bindings);
hook = luajava.newInstance( "org.schema.game.common.data.player.dialog.DialogTextEntryHookLua", "hookFunc", {} );
entry = luajava.newInstance( "org.schema.game.common.data.player.dialog.TextEntry",
dialogObject:format("follow me!"), 2000 );
factory:setRootEntry(entry);-- end NPC general code
--mouvement algorythm
x=math.random(-150,100); --should be a do while
z=math.random(-150,100); -- give a random position in the station
while ( not distanceBonne(x,z)) do --detect if it's possible to go
x=math.random(-150,100);
z=math.random(-150,100);
end
--dialogObject:moveTo(x,17,z); -- we affect to position to focus
moveToHook = luajava.newInstance( "org.schema.game.common.data.player.dialog.DialogTextEntryHookLua", "moveToHookFunc", {x,17,z} ); --centre station 16,18,16 court 42 long 90
entry:setHook(moveToHook); -- stolen lines from npc-tutorial-00.lua
moveToHook:setStartState("entry");
moveToHook:setEndState("entry");
entry:addReaction(moveToHook, -1, entry);
entry:addReaction(moveToHook, 0, entry);
entry:addReaction(moveToHook, 1, entry);
dSys:add(factory)
return dSys
end
Attachments
-
2.3 KB Views: 2