Category | Farming Simulator 2011 |
Created | 03.01.2011 18:10 |
Heady Planet-ls (Headshot XXL) | 03.01.2011 18:36 |
---|---|
Hello I need an example script or a solution for map buildings works in multiplayer. I have tried my own script but it does not work. When the button is pressed by the server: server: new object: table: 0C2F57A0 write object: table: 0C2F57A0 write networkGetObjectId: nil client: Lua: Error running function: packetReceived <path>/ExtraFile.lua(98) : attempt to index field 'object' (a nil value) When the button is pressed by the client: client: new object: table: 02BA8080 write object: table: 02BA8080 write networkGetObjectId: nil server: Lua: Error running function: packetReceived <path>/ExtraFile.lua(98) : attempt to index field 'object' (a nil value) <-- lua file start --> SampleMapBuilding = {}; function onCreate(self, id) --trigger callback: ModfilenameWithoutExtension.onCreate print("created sample Mapbuilding, id: ", id); SampleMapBuilding:load(id) end; function SampleMapBuilding:load(id) self.transform = id; self.showText = ""; self.isActive = true; end; function SampleMapBuilding:loadMap(name) end; function SampleMapBuilding:deleteMap() end; function SampleMapBuilding:mouseEvent(posX, posY, isDown, isUp, button) end; function SampleMapBuilding:keyEvent(unicode, sym, modifier, isDown) end; function SampleMapBuilding:update(dt) if self.isActive ~= nil then if g_currentMission.player ~= nil then local x, y, z = getWorldTranslation(self.transform); local playerX, playerY, playerZ = getWorldTranslation(g_currentMission.player.rootNode); local distance = Utils.vector2Length(x-playerX, z-playerZ); if distance < 3.0 then g_currentMission:addHelpButtonText("Showtext ein-/ausblenden und senden", InputBinding.IMPLEMENT_EXTRA); if InputBinding.hasEvent(InputBinding.IMPLEMENT_EXTRA) then if self.showText == "" then if g_server == nil then self.showText = "client"; else self.showText = "server"; end; else self.showText = ""; end; if g_server ~= nil then g_server:broadcastEvent(NetworkEvent:new(self)); else g_client:getServerConnection():sendEvent(NetworkEvent:new(self)); end end; end; end; end; end; function SampleMapBuilding:draw() if self.showText == "client" then g_currentMission:addExtraPrintText("ShowText from Client"); elseif self.showText == "server" then g_currentMission:addExtraPrintText("ShowText from Server"); end; end; addModEventListener(SampleMapBuilding); NetworkEvent = {}; MPEvent_mt = Class(NetworkEvent, Event); InitEventClass(NetworkEvent, "NetworkEvent"); function NetworkEvent:emptyNew() local self = Event:new(MPEvent_mt); self.className="NetworkEvent"; return self; end; function NetworkEvent:new(object) local self = NetworkEvent:emptyNew() self.object = object; print("new object: ", tostring(self.object)) return self; end; function NetworkEvent:readStream(streamId, connection) local id = streamReadInt32(streamId) self.object = networkGetObject(id); self.object.showText = streamReadString(streamId); print("read networkGetObjectId:", tostring(id)) print("read object:", tostring(self.object)) if not connection:getIsServer() then g_server:broadcastEvent(NetworkEvent:new(self.object), nil, connection, self.object); end; end; function NetworkEvent:writeStream(streamId, connection) local id = networkGetObjectId(self.object) streamWriteInt32(streamId, id); streamWriteString(streamId, self.object.showText); print("write object: ", tostring(self.object)) print("write networkGetObjectId: ", tostring(id)) end; <-- lua file end --> |
Stefan Geiger - GIANTS Software | 04.01.2011 11:58 |
---|---|
The problem is that your class is not an "Object" and thus networkGetObjectId is not working http://www.ls-mode.de has the trigger script online now as well. There you can find some examples how to derive from Object and register new Network Objects with a onCreate function. I can recommend to study for example TipTrigger: http://ls-mods.de/scriptDocumentation.php?lua_file=triggers/TipTrigger |
Note: Log in to post. Create a new account here.