Trying to spawn armour in the safehouse
-
I'm trying to spawn armour in each character's safe house with the LUA code shown. It works if I change the hash key, to let's say health pack, the health pack will spawn, but if I use the armor hash key, nothing spawns, any ideas?
code snippet:
for i, coords in pairs(newPickups.spawnLocations) do
OBJECT.CREATE_AMBIENT_PICKUP(GAMEPLAY.GET_HASH_KEY("PICKUP_ARMOUR_STANDARD"), coords[1], coords[2], coords[3], 0, 0, GAMEPLAY.GET_HASH_KEY("PICKUP_ARMOUR_STANDARD"), true, true)
end
-
Managed to get this to work, I think it might be because I installed openiv though, it worked after that.... If anyone knows why?
-
@darren111 maybe you made a typo somewhere (in the string) somehow, making it invalid (so nothing happened), or did invalid syntax so it never loaded? There's no way that OpenIV would have anything to do with it if it was loaded/working before. Also, you don't really necessarily have to, but you could
local
ize the hash/return, so that you aren't calling the native more times than you really need to.JM36.CreateThread(function() local pickupHash = GetHashKey("PICKUP_ARMOUR_STANDARD") for i, coords in ipairs(newPickups.spawnLocations) do CreateAmbientPickup(pickupHash, coords[1], coords[2], coords[3], 0, 0, pickupHash, true, true) -- coords "should" always be x/y/z based, but meh, just following the given code end end)
Side note, now that I've looked back/closer, you may have to request the entity model, if it isn't already loaded or doesn't already exist someplace in the world, otherwise it will not spawn; here's some example code that shows/includes this step:
JM36.CreateThread(function() local pickupHash = GetHashKey("PICKUP_ARMOUR_STANDARD") if IsModelValid(pickupHash) then while not HasModelLoaded(pickupHash) do RequestModel(pickupHash) JM36.yield() end for i, coords in ipairs(newPickups.spawnLocations) do CreateAmbientPickup(pickupHash, coords[1], coords[2], coords[3], 0, 0, pickupHash, true, true) -- coords "should" always be x/y/z based, but meh, just following the given code end SetModelAsNoLongerNeeded(pickupHash) end end)
-
How honoured do I feel to receive a reply from you, yourself, there were no syntax errors, I do debug with "print" buy who knows maybe I was doing something wrong..
I do have another problem, the armor stays in the air and it doesn't go onto the floor, with CREATE_PICKUP, any ideas how I would get it to spawn on the floor, with the CREATE_PICKUP function?
I can't seem to remove the Armor again with CREATE_AMBIENT_PICKUP, so I used CREATE_PICKUP, but that created this problem where it floats in the air.
EDIT
here is the code: https://pastebin.com/8kLJ4eBP
As you can see I save the pickup into a variable (so I can unset it later), only it doesnt work with CREATE_AMBIENT_PICKUP
-
@darren111 Hmm, after doing some research (by reviewing/searching decompiled scripts), it seems that pickups pretty much are objects, just called/labeled pickups because they can be picked up by the player; you *should* be able to use both entity and object related natives on the pickup return value as far as I can see. Natives that you may try:
1:
ActivatePhysics
- should make it pretty much just fall down to the ground from where it was,SetActivateObjectPhysicsAsSoonAsItIsUnfrozen
seems to be very commonly used/called prior to this.
2:PlaceObjectOnGroundProperly
- self explanatory, should place it smoothly on the ground.You may also test out whether the pickups are actually objects as suspected or not via
GetEntityType
.How honoured do I feel to receive a reply from you, yourself
Well, it seems like for whatever reason everyone in the GTA V SP modding community hates Lua with a non existent or invalid reason, so I figured why not keep an eye out and monitor for Lua related stuff myself and help out the best that I can, since no one else is gonna even try to assist at all with it, despite how easy and simple it is in comparison.
-
Thanks for your help. I love LUA, because you just open notepad and you're ready to go.
Anyway, I tried, and it still spawns the object in the air.
With that other native 'ActivatePhysics', how would I go about calling that? 'PHYSICS.ACTIVATE_PHYSICS'?Thanks for your help, I appreciate it, and will release the mod if I ever get it to work as I want.
Here's the code (I've beatified it this time so it's easier for you to read), looks right to you?
-
Solved with ENTITY.DOES_ENTITY_EXIST, the reason wny CREATE_AMBIENT_PICKUP didnt work was because if you moved the armor away from the original coords, then it would be detected as no longer existing, what kind of function is that? lol
Now, to get on with the fun bit, adding weapons and more locations!
-
Thanks for your help. I love LUA, because you just open notepad and you're ready to go.
No problem, and same, it pretty much just works; I wrote something about that just yesterday in another post where I was requested to rewrite a very simple and efficient Lua script in C# or C++ (which I can't do because I don't know those languages and abandoned trying to learn them due to their nonsensical requirements and errors in comparison to Lua)
With that other native 'ActivatePhysics', how would I go about calling that? 'PHYSICS.ACTIVATE_PHYSICS'?
That all depends upon which Lua Plugin you are using; if you are using the old/outdated/original, then your only option pretty much is via
PHYSICS.ACTIVATE_PHYSICS
as you stated, except,PHYSICS
instead isROPE
there, so it'd actually beROPE.ACTIVATE_PHYSICS
when using that style of native calling. If you are using my (JM36) Lua Plugin on the other hand however, it is the same thing/way for that style of native calling (nothing's changed there, it's exactly the same, since that style is really only kept around for legacy/backward compatibility with older/existing scripts at the moment), but you can also call natives via their newer names (as well as any of their known/documented older names, provided that there are no naming conflicts which afaik there are none), using the style likeActivatePhysics
.Thanks for your help, I appreciate it, and will release the mod if I ever get it to work as I want.
Here's the code (I've beatified it this time so it's easier for you to read), looks right to you?
No problem, and yeah for the most part it looks pretty decently written, just could be optimized in a few different ways, but that's something for another time, sometime after I would say.
Also, here's a (pretty much) complete list of RAGE native functions (at the time of writing) that you can call/use from within JM36 Lua Plugin (and I guess also the old/original/outdated Lua Plugin too if you take a look at where/what the new/modern names point to and whatnot) - https://github.com/JayMontana36/LuaPlugin-GTAV/blob/221e77693a46e31f75b0b999075e402ff567b56f/GameDir-GTAV/scripts/ScriptsDir-Lua/__Internal/0A_Natives-1660760508.lua
-
@darren111 said in Trying to spawn armour in the safehouse:
Solved with ENTITY.DOES_ENTITY_EXIST, the reason wny CREATE_AMBIENT_PICKUP didnt work was because if you moved the armor away from the original coords, then it would be detected as no longer existing, what kind of function is that? lol
Now, to get on with the fun bit, adding weapons and more locations!
Hmm, interesting, moved in what way?
Edit: I suppose setting the entity coords after may remove the pickup properties from the object, so that could make sense, although at the same time not really, considering the ammo crate drop spawns high up "from a plane" and then slowly descends/falls down and whatnot.
-
I use your plugin but I think I've done it, the problem was if the ped wasn't in the area where the objects was being spawned, then it would float in the air. I've had to rewrite it from scratch (it's not finished yet). I've used GET_DISTANCE_BETWEEN_COORDS, so when the player is near to the spawn point only then will it spawn
-
@darren111 Hmm, well, I mean that also would make sense, as there are no collisions and whatnot loaded for far away areas, and so physics wouldn't necessarily work right (if at all) without them, and setting on ground properly also wouldn't work properly (at all) either; you could however request collisions for the coordinates, but for something like this, meh, nah, distance calculations would be better/fine depending upon implementation.
On a side note, there are a ton of things that I would do differently, mostly for optimization, but overall it's pretty interesting; how long have you been doing Lua (both in general, and for either one of the two Lua Plugins, if you don't mind me asking)?