Jump to content

VicToMeyeZR

Members
  • Posts

    570
  • Joined

  • Last visited

Everything posted by VicToMeyeZR

  1. Yeah. Initially I wanted to update and use the character thingoid, but I couldn't get the animations to play correctly based on the character thingoid... "when you send the message to the character thingoid, I couldn't find the right was to access that message in the character animation sequences. I was trying to reference the object.move for my if elseif, but that didn't come out right. Accessing those direct messages would be better" Also, what I meant on speed. Right now when I move forward 3 my toon moves ~REALLY fast.. But thats the same speed setting you used, so I can't quite figure out why. Also, my character mesh doesn't interact with the terrain mesh, it always at plain 0 on y.. I didn't see where you did that in the character thingoid, but your controller does go with the terrain mesh.
  2. It will crash because when you as soon as you add something the Physics comes into play. My laptop will run the editor, but will crash when adding ANYTHING to the scene.
  3. New update require("scripts/class") require("scripts/XML/XML") local class=CreateClass(...) local path = string.lower(StripExt(class.modelreference.path)) local obj,err = XmlParser:ParseXmlFile(path..".xml") function class:InitDialog(grid) self.super:InitDialog(grid) group = grid:AddGroup("Animations") if (not err) then for i,xmlNode in pairs(obj.ChildNodes) do if(xmlNode.Name=="start") then for i,subXmlNode in pairs(xmlNode.ChildNodes) do if(subXmlNode.Name) then group:AddProperty(subXmlNode.Name.."_start", PROPERTY_INTEGER, "", ""..subXmlNode.Attributes.value.."") end end end end for i,xmlNode in pairs(obj.ChildNodes) do if(xmlNode.Name=="end") then for i,subXmlNode in pairs(xmlNode.ChildNodes) do if(subXmlNode.Name) then group:AddProperty(subXmlNode.Name.."_end", PROPERTY_INTEGER, "", ""..subXmlNode.Attributes.value.."") end end end end end group:Expand(1) end function class:CreateObject(model) local object = self.super:CreateObject(model) object.model = model local pos = object.model:GetPosition() object.model:SetPosition(Vec3(pos.x, pos.y, pos.z)) object.framestart = 0 object.frameend = 50 object.height = tonumber(object:GetKey("controller_height", "1.8")) local radius = tonumber(object:GetKey("controller_radius", "0.4")) local step = tonumber(object:GetKey("controller_step_height", "0.5")) local slope = tonumber(object:GetKey("controller_max_slope", "45.0")) object.rotation = 0 object.forward = 0 object.reverse = 0 object.sright = 0 object.sleft = 0 object.tleft = 0 object.tright = 0 object.jump = 0 object.moveSpeed = 2 object.strafeSpeed = 2 --Notify(object.framestart) // Debug function object:SetKey(key,value) if key=="idle_start" then self.idle_start = tonumber(value) elseif key=="idle_end" then self.idle_end = tonumber(value) elseif key=="walk_start" then self.walk_start = tonumber(value) elseif key=="walk_end" then self.walk_end = tonumber(value) elseif key=="run_start" then self.run_start = tonumber(value) elseif key=="run_end" then self.run_end = tonumber(value) elseif key=="jump_start" then self.jump_start = tonumber(value) elseif key=="jump_end" then self.jump_end = tonumber(value) elseif key=="crouch_start" then self.crouch_start = tonumber(value) elseif key=="crouch_end" then self.crouch_end = tonumber(value) elseif key=="strafeleft_start" then self.strafeleft_start = tonumber(value) elseif key=="strafeleft_end" then self.strafeleft_end = tonumber(value) elseif key=="straferight_start" then self.straferight_start = tonumber(value) elseif key=="straferight_end" then self.straferight_end = tonumber(value) elseif key=="height" then self.height = tonumber(vaue) else return self.super:SetKey(key,value) end return 1 end function object:GetKey(key,value) if key=="idle_start" then return self.idle_start elseif key=="idle_end" then return self.idle_end elseif key=="walk_start" then return self.walk_start elseif key=="walk_end" then return self.walk_end elseif key=="run_start" then return self.run_start elseif key=="run_end" then return self.run_end elseif key=="jump_start" then return self.jump_start elseif key=="jump_end" then return self.jump_end elseif key=="crouch_start" then return self.crouch_start elseif key=="crouch_end" then return self.crouch_end elseif key=="strafeleft_start" then return self.strafeleft_start elseif key=="strafeleft_end" then return self.strafeleft_end elseif key=="straferight_start" then return self.straferight_start elseif key=="straferight_end" then return self.straferight_end elseif key=="height" then return self.height else return self.key end return value end function object:StartAnimations(movement) object.framestart = object:GetKey(movement .. "_start", "") return object.framestart end function object:EndAnimations(movement) object.frameend = object:GetKey(movement .. "_end") return object.frameend end function object:LockKeys(model) self.super:LockKeys() end function object:UnlockKeys(model) self.super:UnlockKeys() end function object:UpdateMatrix() end function object:Reset() end function object:SetTarget(target,index) end function object:Collision(entity,position,normal,force,speed) end function object:ReceiveMessage(message,extra) if message=="forward" then object.forward = tonumber(extra) * object.moveSpeed elseif message=="reverse" then object.reverse = tonumber(extra) * object.moveSpeed elseif message=="stop" then object.forward = tonumber(extra) * object.moveSpeed object.reverse = tonumber(extra) * object.moveSpeed elseif message=="sleft" then elseif message=="sright" then elseif message=="tleft" then elseif message=="tright" then elseif message=="crouch" then elseif message=="jump" then elseif message=="attack" then else self.super:ReceiveMessage(message,extra) end end function object:Render() object.framestart = object:StartAnimations("idle") object.frameend = object:EndAnimations("idle") object.move = 0 if GetGlobalString("mode") == "GAME_MODE" then local pos = object.model:GetPosition() if object.forward > 1 then object.model:SetPosition(Vec3(pos.x, pos.y, pos.z+object.forward)) elseif object.reverse < -1 then object.model:SetPosition(Vec3(pos.x, pos.y, pos.z+object.reverse)) else object.frame = math.fmod(AppTime()/30, object.framestart - object.frameend) + object.framestart Animate(object.model, object.frame, 0.5, 0, true) end else end if GetGlobalString("mode") ~= "GAME_MODE" then if object.frameend ~= nil and object.frameend ~= 0 or object.framestart ~= nil then object.frame = math.fmod(AppTime()/30, object.framestart - object.frameend) + object.framestart Animate(object.model, object.frame, 0.5, 0, true) end end end function object:Free(model) self.super:Free() end end --[[ function class:Free() self.super:Free() end ]]-- and the keyboard controller require("scripts/class") require("Scripts/Constants/keycodes") require("Scripts/hooks") local class=CreateClass(...) -- we can get the value by passing the string to _G[] function class:InitDialog(grid) self.super:InitDialog(grid) group = grid:AddGroup("Movement Controls") letters = "NO_KEY,KEY_BACKSPACE,KEY_TAB,KEY_CLEAR,KEY_RETURN,KEY_ENTER,KEY_ESCAPE,KEY_SPACE,KEY_PAGEUP,KEY_PAGEDOWN,KEY_END,KEY_HOME,KEY_LEFT,KEY_RIGHT,KEY_UP,KEY_DOWN,KEY_SELECT,KEY_PRINT,KEY_EXECUTE,KEY_SCREEN,KEY_INSERT,KEY_DELETE,KEY_0,KEY_1,KEY_2,KEY_3,KEY_4,KEY_5,KEY_6,KEY_7,KEY_8,KEY_9,KEY_NUM0,KEY_NUM1,KEY_NUM2,KEY_NUM3,KEY_NUM4,KEY_NUM5,KEY_NUM6,KEY_NUM7,KEY_NUM8,KEY_NUM9,KEY_NUMMULTIPLY,KEY_NUMADD,KEY_NUMSUBSTRACT,KEY_NUMDECIMAL,KEY_NUMDIVIDE,KEY_F1,KEY_F2,KEY_F3,KEY_F4,KEY_F5,KEY_F6,KEY_F7,KEY_F8,KEY_F9,KEY_F10,KEY_F11,KEY_F12,KEY_TILDE,KEY_MINUS,KEY_EQUALS,KEY_OPENBRACKET,KEY_CLOSEDBACKET,KEY_BACKSLASH,KEY_SEMICOLON,KEY_QUOTES,KEY_COMMA,KEY_PERIOD,KEY_SLASH,KEY_LSHIFT,KEY_RSHIFT,KEY_LCONTROL,KEY_RCONTROL,KEY_LALT,KEY_RALT,KEY_LSYS,KEY_RSYS" for i = 65,90 do letters = letters..",".."KEY_"..string.char(i) end group:AddProperty("forward", PROPERTY_CHOICEEDIT, letters, "Forward") group:AddProperty("backward", PROPERTY_CHOICEEDIT, letters, "Backward") group:AddProperty("strafe_left", PROPERTY_CHOICEEDIT, letters, "Strafe Left") group:AddProperty("strafe_right", PROPERTY_CHOICEEDIT, letters, "Strafe Right") group:AddProperty("rotate_right", PROPERTY_CHOICEEDIT, letters, "Rotate Left") group:AddProperty("rotate_right", PROPERTY_CHOICEEDIT, letters, "Rotate Right") group:AddProperty("jump", PROPERTY_CHOICEEDIT, letters, "Jump") group:AddProperty("duck", PROPERTY_CHOICEEDIT, letters, "Duck") group:Expand(1) end function class:CreateObject(model) local object=self.super:CreateObject(model) object.model = model object.forward = "" object.backward = "" object.strafeLeft = "" object.strafeRight = "" object.rotateLeft = "" object.rotateRight = "" object.jump = "" object.duck = "" object.speed = 2 object.moveOneTime = false object.strafeOneTime = false function object:SetKey(key,value) if key == "forward" then object.forward = value elseif key == "backward" then object.backward = value elseif key == "strafe_left" then object.strafeLeft = value elseif key == "strafe_right" then object.strafeRight = value elseif key == "rotate_left" then object.rotateLeft = value elseif key == "rotate_right" then object.rotateRight = value elseif key == "jump" then object.jump = value elseif key == "duck" then object.duck = value else return self.super:SetKey(key,value) end return 1 end function object:GetKey(key,value) if key == "forward" then return object.forward elseif key == "backward" then return object.backward elseif key == "strafe_left" then return object.strafeLeft elseif key == "strafe_right" then return object.strafeRight elseif key == "rotate_left" then return object.rotateLeft elseif key == "rotate_right" then return object.rotateRight elseif key == "jump" then return object.jump elseif key == "duck" then return object.duck else return self.super:GetKey(key,value) end return value end function object:Update() t = model:GetTarget(0) if GetGlobalString("mode") == "GAME_MODE" then if t ~= nil then if KeyHit(_G[object.forward]) == 1 then object.moveOneTime = true t:SendMessage("forward", "1") elseif KeyHit(_G[object.backward]) == 1 then object.moveOneTime = true t:SendMessage("reverse", "-1") else if KeyDown(_G[object.forward]) == 0 and KeyDown(_G[object.backward]) == 0 and object.moveOneTime == true then -- we only want to send the stop message once object.moveOneTime = false t:SendMessage("stop","0") end end if KeyHit(_G[object.strafeLeft]) == 1 then object.strafeOneTime = true t:SendMessage("strafe", "0", "-1") elseif KeyHit(_G[object.strafeRight]) == 1 then object.strafeOneTime = true t:SendMessage("strafe", "0", "1") else if KeyDown(_G[object.strafeLeft]) == 0 and KeyDown(_G[object.strafeRight]) == 0 and object.strafeOneTime == true then -- we only want to send the stop message once object.strafeOneTime = false t:SendMessage("strafe", "0", "0") end end if KeyHit(_G[object.jump]) == 1 then t:SendMessage("jump", "0", "4") end end else end end function object:UpdateMatrix() end --[[ function object:LockKeys(model) self.super:LockKeys() end ]]-- --[[ function object:UnlockKeys(model) self.super:UnlockKeys() end ]]-- --[[ function object:UpdateMatrix() end ]]-- --[[ function object:Reset() end ]]-- --[[ function object:SetTarget(target,index) end ]]-- --[[ function object:Collision(entity,position,normasl,force,speed) end ]]-- --[[ function object:ReceiveMessage(message,extra) if message="" then else self.super:ReceiveMessage(message,extra) end end ]]-- function object:Free(model) --Notify("Inside free") self.super:Free() end end --[[ function class:Free() self.super:Free() end ]]-- THis is a modification to Ricks... My question so far. How to determine movement speed based on the sise of the virtual world? Should I use a mathematical calculation based on the height of the model? If I move forward 3 in the editor how much is that in reference to real world terms?
  4. ahh. ok. Thats it. I just needed to look a little deeper. I was trying modelreference but couldn't get anything from it, but class is the table I needed. local test = string.lower(StripExt(class.modelreference.path)) Thanks Rick
  5. Not if josh, puts that in his core. lol. I will try that also.
  6. Very good idea. +1 from me
  7. ok. I had to add a little to the class.lua file to get this to work. Name the XML file the same as your GMF model file. change to Class.lua --Creates a class from a model reference object function CreateClass(modelreference) local class={} local super={} class.instances={} classtable[modelreference]=class class.modelreference=modelreference class.name=string.lower(StripAll(modelreference.path)) classnametable[class.name]=class Print("Creating class "..class.name) super.class=class CHANGE TO: --Creates a class from a model reference object function CreateClass(modelreference) local class={} local super={} class.instances={} classtable[modelreference]=class class.modelreference=modelreference class.name=string.lower(StripAll(modelreference.path)) class.path=string.lower(StripExt(modelreference.path)) classnametable[class.name]=class classnametable[class.path]=class.path Print("Creating class "..class.name) super.class=class Then change the top of my file from : local obj,err = XmlParser:ParseXmlFile("Models/characters/Cyber/character_visor_full.xml") CHANGE TO: local obj,err = XmlParser:ParseXmlFile(class.path..".xml")
  8. Yeah, that gives me the name, but not the path.
  9. Yeah, my thinking in this, and of course it will progress, is that no matter WHAT animations the character has, this character file will work for EVERY character/NPC. You make the XML file based of that model, and as soon as you post each one in the editor, the properties fields are set. If I could find out how to automatically pull the XML file name based off the model instance, then the file WOULD be fully automated. the model lua file, and the model file name match, so if there was a way to tell the script the the XML file is the same, sure would help out a bunch. (*hint) I will post a video, so you can see.
  10. ok. My character script. This way I won't have to change much with it. XML FILE: <?xml version="1.0" encoding="utf-8"?> <animations> <start> <idle value="Idle Start Frame">460</idle> <run value="Run Start Frame">1155</run> </start> <end> <idle value="Idle End Frame">850</idle> <run value="Run End Frame">1195</run> </end> </animations> MODEL LUA FILE: require("scripts/class") require("scripts/XML/XML") local class=CreateClass(...) local obj,err = XmlParser:ParseXmlFile("Models/characters/Cyber/character_visor_full.xml") function class:InitDialog(grid) self.super:InitDialog(grid) group = grid:AddGroup("Animations") //This adds a property field based off the XML file data structure. This file MUST meet the data structure set by my post, or you will have to modify this script if (not err) then for i,xmlNode in pairs(obj.ChildNodes) do if(xmlNode.Name=="start") then for i,subXmlNode in pairs(xmlNode.ChildNodes) do if(subXmlNode.Name) then group:AddProperty(subXmlNode.Name.."_start", PROPERTY_INTEGER, "", ""..subXmlNode.Attributes.value.."") end end end end for i,xmlNode in pairs(obj.ChildNodes) do if(xmlNode.Name=="end") then for i,subXmlNode in pairs(xmlNode.ChildNodes) do if(subXmlNode.Name) then group:AddProperty(subXmlNode.Name.."_end", PROPERTY_INTEGER, "", ""..subXmlNode.Attributes.value.."") end end end end end group:Expand(1) end
  11. Here is a Lua only Parser. test.xml <?xml version="1.0" encoding="utf-8"?> <animations> <start> <idle value="infiltrator">460</idle> <run value="infiltrator">1155</run> </start> <end> <idle value="infiltrator">850</idle> <run value="infiltrator">1195</run> </end> </animations> xml.lua XmlParser = {}; function XmlParser:ToXmlString(value) value = string.gsub (value, "&", "&"); -- '&' -> "&" value = string.gsub (value, "<", "<"); -- '<' -> "<" value = string.gsub (value, ">", ">"); -- '>' -> ">" --value = string.gsub (value, "'", "'"); -- '\'' -> "'" value = string.gsub (value, "\"", """); -- '"' -> """ -- replace non printable char -> " " value = string.gsub(value, "([^%w%&%;%p%\t% ])", function (c) return string.format("%X;", string.byte(c)) --return string.format("%02X;", string.byte(c)) --return string.format("%02d;", string.byte(c)) end); return value; end function XmlParser:FromXmlString(value) value = string.gsub(value, "([%x]+)%;", function(h) return string.char(tonumber(h,16)) end); value = string.gsub(value, "([0-9]+)%;", function(h) return string.char(tonumber(h,10)) end); value = string.gsub (value, """, "\""); value = string.gsub (value, "'", "'"); value = string.gsub (value, ">", ">"); value = string.gsub (value, "<", "<"); value = string.gsub (value, "&", "&"); return value; end function XmlParser:ParseArgs(s) local arg = {} string.gsub(s, "(%w+)=([\"'])(.-)%2", function (w, _, a) arg[w] = self:FromXmlString(a); end) return arg end function XmlParser:ParseXmlText(xmlText) local stack = {} local top = {Name=nil,Value=nil,Attributes={},ChildNodes={}} table.insert(stack, top) local ni,c,label,xarg, empty local i, j = 1, 1 while true do ni,j,c,label,xarg, empty = string.find(xmlText, "<(%/?)([%w:]+)(.-)(%/?)>", i) if not ni then break end local text = string.sub(xmlText, i, ni-1); if not string.find(text, "^%s*$") then top.Value=(top.Value or "")..self:FromXmlString(text); end if empty == "/" then -- empty element tag table.insert(top.ChildNodes, {Name=label,Value=nil,Attributes=self:ParseArgs(xarg),ChildNodes={}}) elseif c == "" then -- start tag top = {Name=label, Value=nil, Attributes=self:ParseArgs(xarg), ChildNodes={}} table.insert(stack, top) -- new level --log("openTag ="..top.Name); else -- end tag local toclose = table.remove(stack) -- remove top --log("closeTag="..toclose.Name); top = stack[#stack] if #stack < 1 then error("XmlParser: nothing to close with "..label) end if toclose.Name ~= label then error("XmlParser: trying to close "..toclose.Name.." with "..label) end table.insert(top.ChildNodes, toclose) end i = j+1 end local text = string.sub(xmlText, i); if not string.find(text, "^%s*$") then stack[#stack].Value=(stack[#stack].Value or "")..self:FromXmlString(text); end if #stack > 1 then error("XmlParser: unclosed "..stack[stack.n].Name) end return stack[1].ChildNodes[1]; end function XmlParser:ParseXmlFile(xmlFileName) local hFile,err = io.open(xmlFileName,"r"); if (not err) then local xmlText=hFile:read("*a"); -- read file content io.close(hFile); return self:ParseXmlText(xmlText),nil; else return nil,err; end end Run this file: require("Scripts/XML/xml") local obj,err = XmlParser:ParseXmlFile("Scripts/test.xml") if(not err) then for i,xmlNode in pairs(obj.ChildNodes) do if(xmlNode.Name=="start") then for i,subXmlNode in pairs(xmlNode.ChildNodes) do if(subXmlNode.Name) then Notify(subXmlNode.Name.." value=\""..subXmlNode.Attributes.value.."\""); if(subXmlNode.Value) then Notify(" Content=\""..subXmlNode.Value.."\""); end end end end end else Notify("ERROR: "..err); end It will return: idle value="infiltrator" content="460" run value="infiltrator" content="1155" With this I can have it run a dynamic menu for the object, as well as pass the deafult values based on the XML file information. I will post the scrip to run this part as soon as I have it.
  12. Yes I will. I already posted the XML lib for use so I will start on the scripting for it.
  13. I haven't done a lot of testing with this, but it will parse the XML data exactly like we were talking.
  14. File Name: LuaXML.zip File Submitter: VicToMeyeZR File Submitted: 18 Jan 2010 File Category: Lua Scripts Place to 2 DLL files in your root SDK folder. Place the core LUA file anywhere you want in the scripts folder. Go to town. Click here to download this file
  15. oo.. sweet. I like your train of thought. Good idea.
  16. 3dws could still be sold as a stand alone... Was talking about also integrating it to LE, and raise the price of LE.
  17. I am wondering about the controller you use Rick.. (specifically the height and such) Do you really have he have the controller move the model? Can you pull the model height in real time, and move it with out a controller? specifically this line: object.controller:SetPosition(Vec3(pos.x, pos.y + (object.height/2), pos.z)) Your moving the controller by half the distance of the height. Can you pull the model height in real time and move it with out the controller by half its real height? hope that makes sense.
  18. It can. RIght now its only setup for idle animation, so if you never enter anything other than the idle(which can be any frames) then it will only do that animation
  19. Me to. I really like Lua. mostly because I am a scripter, not a programmer. lol
  20. That was a debug so I could see if my value of framestart or frameend was being set... I you find the Notify() and put a -- in front of it, and change this line: function object:GetKey(key,value) if key=="idle_start" then return self.idle_start elseif key=="idle_end" then return self.idle_start to : function object:GetKey(key,value) if key=="idle_start" then return self.idle_start elseif key=="idle_end" then return self.idle_end It will work. Then you can double click in the character in the objects window, and set your frame start and ends for each function. Right now, all the guy does is idle animate, and yes its a dexsoft model, so theirs do work, just requires little fix with the textures. When I get the controller to work with this, I will post it again for everyone to play with if they want.
  21. Thats what I thought 2 days ago. It really is easy, well easier than I thought at first. I do still have a lot to add to it, and I plan to integrate Rick's character scripts in a way to control the character better.
×
×
  • Create New...