Jump to content

[Help] Bad Arguments[fadeCamera,setCameraMatrix,createPed]


Guest d1sch4rg3d

Recommended Posts

local currentPedId = -1 
local currentTeam = "grove" 
function rightCharacterSelection() 
    local pedId = { 105, 106, 107, 102, 103, 104, 280, 281, 282, 283, 284, 285, 286, 287, 288 } -- All the peds i'm using 
    if ( currentPedId > 14 ) then currentPedId = -1 end -- Reset the current ped id after it's passed the end of the number of pedId values 
    currentPedId = currentPedId + 1 -- Increase the number by 1 so that it'll go to the next skin each time 
    if ( currentPedId > 5 ) then currentTeam = "police" end -- Make sure the teams are correct 
    if ( currentPedId <= 2 ) then currentTeam = "grove" end 
    if ( currentPedId > 2 and currentPedId < 5 ) then currentTeam = "ballas" end 
    outputChatBox( "CurrentPedId: " .. currentPedId, source ) -- Just for debugging to make sure it worked 
    outputChatBox( "CurrentTeam: " .. currentTeam, source ) -- Just for debugging 
    if ( currentTeam == "grove" and currentPedId <= 2 ) then -- If the team is grove and the skin is between the grove skins in PedId then.. 
        fadeCamera ( source, true ) -- fade camera 
        setCameraMatrix ( source, 2491, -1660, 13, 2502, -1668, 14 ) -- move the camera and look at the grove spawn spot. 
        createPed( pedId[currentPedId], 2502, -1668, 14 ) -- create a current ped for the camera to look at. 
    elseif ( currentTeam == "police" and currentPedId > 5 ) then -- if the team and id are police..then.. 
        fadeCamera ( source, true ) -- fadeCamera 
        setCameraMatrix ( source, 1539, -1674, 14, 1544, 1675, 14 ) -- move and look at police spawn 
        createPed( pedId[currentPedId], 1544, 1675, 14 ) -- create the police ped. 
    elseif ( currentTeam == "ballas" and currentPedId > 2 and currentPedId < 5 ) then -- If the current ped and and team are balla 
        -- NEED To Finish Rest of code here..  NOT FINISHED...don't tell me how this screws up my code.. I know. I still have to get locations etc. 
    end 
end 

I get these errors ( I added comments into the code. Some of the comments might be useless, but i only added them on here for people to be able to understand the code easier..hopefully )

[14:08:02] WARNING: script.lua: Bad argument @ 'fadeCamera' - Line: 20

[14:08:02] WARNING: script.lua: Bad argument @ 'setCameraMatrix' - Line: 21

[14:08:02] WARNING: script.lua: Bad argument @ 'createPed' - Line: 22

Which is the code under the If statement with grove street.

This lines are:

fadeCamera ( source, true ) 
setCameraMatrix ( source, 2491, -1660, 13, 2502, -1668, 14 ) 
createPed( pedId[currentPedId], 2502, -1668, 14 ) 

Can someone maybe tell me why i'm getting these errors? If you need more code or information please ask. I'll gladly give you more.

( Btw. Sorry if my code isn't very professional or if i am making a simple mistake. I haven't been scripting long. About 2 days. )

Link to comment

The dangling source. It's evil. Don't use it other than in events. It's EVILLLL!!!

Also you do

local currentPedId = -1

currentPedId = currentPedId + 1

So currentPedID will be 0. I don't think that there is pedId[0], the first one "pedId = { 105...." is pedId[1]

Link to comment

Ah. Okayy. Thank you haha. :] I'll try it out and either edit my post or post a new reply.

Oh i see. I was thinking a table is the same thing as an array.

Array's start at 0 in most languages at least so that's why i did that. Thank you again.

Link to comment

It didn't work man. I still get the same errors.

The table thing helped, but the Camera still doesn't do what it's supposed to do?

local currentPedId = -1 
local currentTeam = "grove" 
function rightCharacterSelection() 
    local pedId = { 105, 106, 107, 102, 103, 104, 280, 281, 282, 283, 284, 285, 286, 287, 288 } -- All the peds i'm using 
    if ( currentPedId > 14 ) then currentPedId = -1 end -- Reset the current ped id after it's passed the end of the number of pedId values 
    currentPedId = currentPedId + 1 -- Increase the number by 1 so that it'll go to the next skin each time 
    if ( currentPedId > 5 ) then currentTeam = "police" end -- Make sure the teams are correct 
    if ( currentPedId <= 2 ) then currentTeam = "grove" end 
    if ( currentPedId > 2 and currentPedId < 5 ) then currentTeam = "ballas" end 
    outputChatBox( "CurrentPedId: " .. currentPedId, source ) -- Just for debugging to make sure it worked 
    outputChatBox( "CurrentTeam: " .. currentTeam, source ) -- Just for debugging 
    if ( currentTeam == "grove" and currentPedId <= 2 ) then -- If the team is grove and the skin is between the grove skins in PedId then.. 
        fadeCamera ( source, true ) -- fade camera 
        setCameraMatrix ( source, 2491, -1660, 13, 2502, -1668, 14 ) -- move the camera and look at the grove spawn spot. 
        createPed( pedId[currentPedId], 2502, -1668, 14 ) -- create a current ped for the camera to look at. 
    elseif ( currentTeam == "police" and currentPedId > 5 ) then -- if the team and id are police..then.. 
        fadeCamera ( source, true ) -- fadeCamera 
        setCameraMatrix ( source, 1539, -1674, 14, 1544, 1675, 14 ) -- move and look at police spawn 
        createPed( pedId[currentPedId], 1544, 1675, 14 ) -- create the police ped. 
    elseif ( currentTeam == "ballas" and currentPedId > 2 and currentPedId < 5 ) then -- If the current ped and and team are balla 
        -- NEED To Finish Rest of code here..  NOT FINISHED...don't tell me how this screws up my code.. I know. I still have to get locations etc. 
    end 
end 
  
function characterSpawn() 
    if( currentTeam == "grove" ) then  
        spawnPlayer ( 2502, -1668, 14  ) -- spawn character grove. ( i know it doesn't pick up..... the model yet, but i'm trying to get the cameras to work. 
    elseif( currentTeam == "police" ) then 
        spawnPlayer ( 1544, 1675, 14 ) -- spawn character in police position (once again same thing with model. ) 
    end 
end 
  
function joinHandler() 
    fadeCamera( source, true ) 
    setCameraMatrix ( source,2491, -1660, 13, 2502, -1668, 14 ) --- ( goes to default grove camera position. so it's not black at beginning ) 
    bindKey ( source, "arrow_r", "down", rightCharacterSelection ) ----( when player hits Right arrow key it executes the code, which SHOULD go through the characters and show me them in their spawn locations )  
    bindKey ( source, "rshift", "down", characterSpawn ) -- left shift spawns character with current model. 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), joinHandler ) 

Can someone please help :[[ I can't figure this out. thanks very much.

Link to comment

You still did nothing about the source.

At joinhandler () it may be, because the addEventHandler() passes source argument. But at rightCharacterSelection() it's a nil value.

Look for bindKey documentation in wiki to see how you can retrieve the player who pressed the button.

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...