View unanswered posts | View active topics It is currently Fri Dec 27, 2024 7:12 am



Reply to topic  [ 6 posts ] 
 Tagging/Naming 
Author Message
User avatar

Joined: Sun Apr 25, 2010 12:04 am
Posts: 303
Location: Australia
Reply with quote
Post Tagging/Naming
Is it possible to add a actor based tagging system, that is also global?
As in, not to one specific actor but to all actors once one of something - such as a brain case - is placed.

For example:

local name = Actor1
--(Entered in console)(Not sure if the 'local' part would be accurate to this use)
--Then:
Actor1: Gibthis;
--(Also entered in console)
--Or something like that.


This would make it possible to tag enemies from your perspective, with advanced Lua, like a curser based tagging system.
Make sense?


Thu Jun 09, 2011 1:30 pm
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: Tagging/Naming
Make a global table and dump all the actors into there using their presetname and a random number (or a non-random number if you like). You'll need an "organisation" actor on the map (probably at 0,0 for simplicity, or your brain case if you so wish) that would keep a track of anything dying or coming into play. You could build a GUI with MOSPs, or just use the CLI by making a bunch of functions members of that fancy global table you just made (oh look its a namespace). Then you can do something like
Code:
world_CLI:getFirst("Dimitri"):GibThis(1000);
and the worlds your oyster.


Thu Jun 09, 2011 2:11 pm
Profile WWW
User avatar

Joined: Sun Apr 25, 2010 12:04 am
Posts: 303
Location: Australia
Reply with quote
Post Re: Tagging/Naming
I was sort of hoping for something a little more simple than that.

I mean to say, naming is the main thing, the stuff about a curser based tagging system was - to me - probably not going to happen.
And just so you know: I know hardly anything about Lua. Only the logic, and some commands to do with CC.


Thanks.


Thu Jun 09, 2011 3:20 pm
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: Tagging/Naming
Making a global table is as simple as
Code:
if (CC_CLI == nil) then CC_CLI = {}; end

You could also define functions inside and outside of that block like
Code:
--expects a table
function populateWithActors(a,c)
   c = c or 0;
   for actor in MovableMan.Actors do --iterate all the actors
      c = c + 1; --increment "count"
      table.insert(a,actor,actor.PresetName .. count);
   end
end

--pads a string to a set length with spaces
function padStringToLength(s,l)
   local length = s:len()
   if length  > l then
      s = s:sub(1,l);
   elseif length < l then
      s = s .. " ":rep(l-length);
   end
   return s
end

--initialising CC_CLI if needed
if (CC_CLI == nil) then
   CC_CLI = {};      --set up a global table to hold everything
   CC_CLI.count = 0;   --start a count
   CC_CLI.Actors = {}; --create a table for the actors
   --populate the CLI's actor table with actors NOTE THIS IS ONLY VALID FOR THIS FRAME THINGS MIGHT DIE OR COME INTO EXISTANCE!
   populateWithActors(CC_CLI.Actors, CC_CLI.count);
   
   --this returns the first found actor with a string in its tag or nil if none is found
   function CC_CLI.firstWithTag(a)
      for k,v in pairs(CC_CLI.Actors) do
         if type(k) ~= "string" then continue;
         elseif k:find(a) ~= nil then
            return v;
         end
      end
      return nil;
   end
   
   --dumps tags, names, and positions in a visual table.
   function CC_CLI.dumpAll()
      print(padStringToLength("TAG",30) .. "|" .. padStringToLength("PRESETNAME",30) .. "|" .. padStringToLength("POS",15));
      for k,v in pairs(CC_CLI.Actors) do
         print(padStringToLength(k,30) .. "|" .. padStringToLength(v.PresetName,30) .. "|" .. padStringToLength(v.Pos:toString(),15));
      end
   end
   
end
for a semi-functional CLI. Feel free to expand it, I'd prefer credit to not but everything is only partially likely to work as I haven't done much CC-lua (or lua in general) for a long time. a way of updating the list wouldn't go astray, remember to clear it first.


Fri Jun 10, 2011 2:41 am
Profile WWW
User avatar

Joined: Sun Apr 25, 2010 12:04 am
Posts: 303
Location: Australia
Reply with quote
Post Re: Tagging/Naming
...

Well, I was hoping not to make a releasable mod, but just make it as a proof of concept sort of thing. I wasn't going to release it or anything.

I think this is best left to you Lua pros. :]
I'll just wait until someone gets so bored that they make this into an actual mod.


Fri Jun 10, 2011 3:20 am
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: Tagging/Naming
... It would've been nice to know you didn't have any drive whatsoever to learn before I bothered typing educational code.


Sat Jun 11, 2011 3:55 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.100s | 14 Queries | GZIP : Off ]