Jump to content

Element not being stored?


glowdemon1

Recommended Posts

Remove cindex from getNearbyCorpses. Arrays are automatically pushed and you won't have to define the key manually. If you want to erase the array, you can just empty the array with curly brackets, but as the array is defined locally, you won't have to worry about erasing anything.

This might be the solution for the issue.

Also, when you incremented cindex variable, it was set to local, so it never actually increased the value because it was unset after the round was completed.

Link to comment
snip

thanks for the reply. I've tried this and didn't work, I decided to leave some checks to get some errors and it keeps on saying that getElementData retrieves a nil value. :

currentID = 0  
  
function spawnPedUponDead() 
    local pedSkin = getElementModel(source) 
    local x,y,z = getElementPosition(source) 
    local _,_,rz = getElementRotation(source) 
    local ped = createPed(pedSkin,x,y,z,rz,false) 
    if ped then 
        local data = setElementData(ped,"ped_id",curentID) 
        setElementData(ped,"ped_type","deadcorpse") 
        setElementData(ped,"postmortum",getPlayerName(source)) 
        killPed(ped) 
        if data then 
            outputChatBox(currentID..getElementData(ped,"ped_id")..getElementData(ped,"postmortum")) 
            currentID = currentID + 1 
        end 
    end 
end 
addEventHandler("onPlayerWasted",root,spawnPedUponDead) 

Link to comment

You don't need the data check. Also, you have a typo in the setElementData part.

setElementData(ped,"ped_id",curentID) 

'curentID' should be 'currentID'. Remove the 'local data' part as well, it doesn't return anything except a boolean and it always returns true as long as your arguments are valid, which in this case are not, because of the typo.

Link to comment
You don't need the data check. Also, you have a typo in the setElementData part.
setElementData(ped,"ped_id",curentID) 

'curentID' should be 'currentID'. Remove the 'local data' part as well, it doesn't return anything except a boolean and it always returns true as long as your arguments are valid, which in this case are not, because of the typo.

Mh alrighty, thanks for the help. Works fine now, didn't even see the typo.

Link to comment

You're welcome. The biggest issue in the world of programming are the smallest mistakes we make. I've spent days trying to find out a reason for a problem myself in Ajax and PHP data transfer, there are no errors either even though all debugs are on and logging, still no errors outputted, so yep, it's always good for someone else to have a look at the code because people spot different type of things.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...