Author |
Message |
Ophanim
Joined: Wed Dec 26, 2007 6:33 am Posts: 1743 Location: Trapped in UCP. Send help.
|
Re: Quick Lua Tips
Of course negative x works, why the hell wouldn't it?
|
Mon Aug 25, 2008 5:36 pm |
|
|
Beef
Joined: Sun Dec 09, 2007 3:31 pm Posts: 19
|
Re: Quick Lua Tips
Grif was referring to the absolute value of a location on the map. You start at 0 and it increases from there, it can't be negative.
|
Mon Aug 25, 2008 5:38 pm |
|
|
Tea
|
Re: Quick Lua Tips
Thanks.
|
Mon Aug 25, 2008 5:52 pm |
|
|
casey
Joined: Wed Dec 27, 2006 10:05 pm Posts: 100
|
Re: Quick Lua Tips
what would a loadfile argument look like
|
Mon Aug 25, 2008 9:26 pm |
|
|
Lord Tim
Joined: Fri Apr 27, 2007 4:55 pm Posts: 1178 Location: America!
|
Re: Quick Lua Tips
loadfile("filename")
|
Mon Aug 25, 2008 9:36 pm |
|
|
Daman
Joined: Fri Jan 26, 2007 3:22 am Posts: 1451
|
Re: Quick Lua Tips
Why would you use loadfile? Use dofile.
dofile("cc.lua")
|
Tue Aug 26, 2008 1:05 am |
|
|
casey
Joined: Wed Dec 27, 2006 10:05 pm Posts: 100
|
Re: Quick Lua Tips
i got this
ERROR:attempt to call global dofile(a string value)
|
Sat Aug 30, 2008 2:57 am |
|
|
Daman
Joined: Fri Jan 26, 2007 3:22 am Posts: 1451
|
Re: Quick Lua Tips
I can't even think of how you're GETTING that error. Maybe you should post what you put in?
|
Sun Aug 31, 2008 6:54 am |
|
|
TheLastBanana
DRL Developer
Joined: Wed Dec 13, 2006 5:27 am Posts: 3138 Location: A little south and a lot west of Moscow
|
Re: Quick Lua Tips
This seems like an appropriate topic to post this in, so ARIIIISE! All right, after much screwing around, I've figured a few things out. First off, we've all noticed that areas are read-only and can't be moved. As annoying as this is, there's workarounds to avoid using them. One thing you can do is simple check coordinates relative to those of a pinned object, which you can then move. To do so, just get Object.Pos.X or Object.Pos.Y. This returns the coords. Also, much like MovableMan.Actors, there IS in fact a class for weapons and devices called MovableMan.Items. Use it to your advantage. Now, there is one thing I'm trying to figure out. When I retrieve an item from MovableMan.Items, it seems to return the same thing as if we directly retrieved it from Create<InsertItem>. However, if I use Actor:AddInventoryItem() to add that object, I get an error stating that I in fact had TWO arguments, the first one always being Actor and the second one being MovableObject. However, I'm noticing that the function calls for a MovableObject* and that this doesn't seem to be returning it. On the other hand, if I directly create on via CreateHDFirearm for instance, it works just fine. This leads me to believe that MovableMan.Actors and Items and all that don't actually return a pointer to the object. Is there any way to find a pointer to said object?
Also, last tidbit of information: <InsertActorHere>.ID returns a number. Not sure if there's any use for this... YET.
|
Sat Nov 15, 2008 2:58 am |
|
|
Lord Tim
Joined: Fri Apr 27, 2007 4:55 pm Posts: 1178 Location: America!
|
Re: Quick Lua Tips
The ID is that actor's unique identifier. To seperate the 7 Green Clones you might have. It could be used to keep track of specific actors without storing the entire actor in a variable. You'd just store the ID. Areas can essentially be recreated in a non-readonly way by making your own function and adding it to your lua file. It'd look something like this: Code: function WithinBox(x,y,x1,y1,x2,y2) if(x>x1 and x<x2 and y>y2 and y<y2) then return true end return false end
Where x and y are the point you're using, and x1,y1,x2,y2 are the edges of the box. You could also easily modify this to use Vectors like so: Code: function WithinBox(point,topleft,bottomright) if(point.GetX()>topleft.GetX() and point.GetX()<bottomright.GetX() and point.GetY()>topleft.GetY() and point.GetY()<bottomright.GetY()) then return true end return false end
In which case you can call the function like WithinBox(Vector(0,0),Vector(20,50),Vector(40,80))
|
Sat Nov 15, 2008 3:39 am |
|
|
TheLastBanana
DRL Developer
Joined: Wed Dec 13, 2006 5:27 am Posts: 3138 Location: A little south and a lot west of Moscow
|
Re: Quick Lua Tips
That would work too. Still looking for help on the non-pointer return, though.
|
Sat Nov 15, 2008 3:51 am |
|
|
Lord Tim
Joined: Fri Apr 27, 2007 4:55 pm Posts: 1178 Location: America!
|
Re: Quick Lua Tips
I did a bit of testing for you. Basically, a summary of what this all means: Items is a function that returns the first item, and the function that will return the next item. This function is built specifically for Lua's "for" loops. Basically, it means that "Items" doesn't really contain all of the items. It just tells you where to find them. Specifically, it's built like a Linked List if anyone is taking computer science classes. The first item stores some data, and has a pointer to the next item in the list. The only way to look at everything, or just one thing, is to look at all of them, or at least up to the thing you're looking for. It has it's pros and cons. A weapon created from "CreateHDFirearm" is initially a "MovableObject". (Notice that it becomes an HDFirearm when it is added to an inventory) A weapon currently in an actor's inventory is an "HDFirearm". A weapon found on the ground is a "MovableObject". (But apparently you can't add it to your inventory, since it's already been added to the world) A weapon cloned from another weapon is basically a string right now. Until Data fixes his Clone function. All it keeps is the "tostring" of the object. Code: - RTE Lua Console - See the Data Realms Wiki for commands: http://www.datarealms.com/wiki/ ------------------------------------- SYSTEM: Scene "Tutorial Bunker" was loaded ERROR: Could not find the requested Scene Area named: LZ Team 2 ERROR: Could not find the requested Scene Area named: Landing Zone SYSTEM: Activity "Tutorial Mission" was successfully started actor = ActivityMan:GetActivity():GetControlledActor(0) print(actor) PRINT: Dummy, AHuman print(MovableMan.Items) PRINT: function: 0BE247B8 for item in MovableMan.Items do print(item) end PRINT: Light Digger, HDFirearm PRINT: AK-47, HDFirearm print(item) PRINT: nil something = nil for item in MovableMan.Items do something = item end print(something) PRINT: AK-47, HDFirearm print(something.ID) PRINT: 87 print(something:IsDevice()) PRINT: true print(something:IsGeneric()) PRINT: false print(actor.Items) PRINT: nil somethingelse = something:Clone() print(somethingelse) PRINT: AK-47, HDFirearm print(somethingelse.ID) PRINT: nil print(somethingelse.Pos) PRINT: nil print(somethingelse:IsDevice()) ERROR: [string "print(somethingelse:IsDevice())"]:1: attempt to call method 'IsDevice' (a nil value) print(somethingelse:IsGeneric()) ERROR: [string "print(somethingelse:IsGeneric())"]:1: attempt to call method 'IsGeneric' (a nil value) somethingother = CreateHDFirearm("AK-47") print(somethingother) PRINT: AK-47, HDFirearm print(somethingother.ID) PRINT: 255 print(somethingother:IsDevice()) PRINT: true print(somethingother:IsGeneric()) PRINT: false print(actor) PRINT: Dummy, AHuman actor:AddInventoryItem(something) ERROR: no overload of 'Actor:AddInventoryItem' matched the arguments (Actor, MovableObject) candidates are: Actor:AddInventoryItem(MovableObject*)
actor:AddInventoryItem(somethingelse) ERROR: no overload of 'Actor:AddInventoryItem' matched the arguments (Actor, Entity) candidates are: Actor:AddInventoryItem(MovableObject*)
actor:AddInventoryItem(somethingother) actor:AddInventoryItem(somethingother) ERROR: no overload of 'Actor:AddInventoryItem' matched the arguments (Actor, HDFirearm) candidates are: Actor:AddInventoryItem(MovableObject*)
actor:AddInventoryItem(somethingelse) ERROR: no overload of 'Actor:AddInventoryItem' matched the arguments (Actor, Entity) candidates are: Actor:AddInventoryItem(MovableObject*)
actor:AddInventoryItem(something) ERROR: no overload of 'Actor:AddInventoryItem' matched the arguments (Actor, MovableObject) candidates are: Actor:AddInventoryItem(MovableObject*)
print(something) PRINT: AK-47, HDFirearm print(something.Pos) PRINT: {1279.99, 362.141} ConsoleMan:SaveAllText("testing.stuff") Bonus: If you want to pick something up off the ground that isn't super unique, you can use these lines of magic code: (Only works for things that are currently in the game world (i.e. In MovableMan.Items), so you can't use it to steal weapons from other actors as far as I know.) Code: gun = MovableMan.Items() -- Gets the first item (You can use any item in "Items") actor = ActivityMan:GetActivity():GetControlledActor(0) -- Gets the actor (You can use any actor) newgun = CreateHDFirearm(gun.PresetName) -- Creates a copy of the gun (What "Clone" should do) actor:AddInventoryItem(newgun) -- Add gun to actor's inventory gun.Pos = Vector(0,-5000) -- Remove the existing ingame gun
|
Sat Nov 15, 2008 8:08 am |
|
|
TheLastBanana
DRL Developer
Joined: Wed Dec 13, 2006 5:27 am Posts: 3138 Location: A little south and a lot west of Moscow
|
Re: Quick Lua Tips
I tried that and it certainly did work. I was just wondering if there was a less bloated way of doing it. Also for the last line of code, MovableMan:RemoveActor(gun) should work too. Anyway, thanks for the explanation. Hopefully Data will fix this.
|
Sat Nov 15, 2008 11:44 pm |
|
|
robolee
Joined: Fri May 11, 2007 4:30 pm Posts: 1040 Location: England
|
Re: Quick Lua Tips
TheLastBanana wrote: Also, much like MovableMan.Actors, there IS in fact a class for weapons and devices called MovableMan.Items. you don't have to specify class, you can just use "MovableMan" instead of "MovableMan.xxx"
|
Sat Nov 15, 2008 11:47 pm |
|
|
TheLastBanana
DRL Developer
Joined: Wed Dec 13, 2006 5:27 am Posts: 3138 Location: A little south and a lot west of Moscow
|
Re: Quick Lua Tips
Yes, but that returns everything on the screen, which is very very bad if you are adding weapons to your inventory. You end up holding 14 zombies, a couple hundred pixels, a gib, and a lot of angry-looking bombs.
|
Sun Nov 16, 2008 12:09 am |
|
|
|
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
|
|