Jump to content

DD or DM check


maarten123

Recommended Posts

hi, now i have make a script to check the map on DD/DM

now this script check if there is a vehicle that is a hunter

addEventHandler("onMapStarting", root, 
function(mapInfo, mapOptions, gameOptions) 
    if #getElementsByType ( "checkpoint" ) == 0 then -- checking DD/DM map 
        for i, pu in pairs ( getElementsByType ( "racepickup" ) ) do 
            if getElementData ( pu, "type" ) == "vehiclechange" 
            and getElementData ( pu, "vehicle" ) == getVehicleModelFromName ( "Hunter" ) then 
                maptype = "DM" 
            else 
                maptype = "DD" 
            end 
        end 
        outputChatBox(getPlayerName(source).."*this is a"..tostring(maptype).." map",getRootElement(),0,255,0) 
    end 
end 
) 

But now he always saying This is a DD map

Can anyone help me out?

Greetings Maarten123 :D

EDIT: line 2

Edited by Guest
Link to comment

becouse it reset this to "dd" on another pickup.

do it like this:

  
addEventHandler("onMapStarting", root, 
function(mapInfo, mapOptions, gameOptions) 
    local hunterFound = false 
    for i, pu in pairs ( getElementsByType ( "racepickup" ) ) do 
        if getElementData ( pu, "type" ) == "vehiclechange" 
        and getElementData ( pu, "vehicle" ) == getVehicleModelFromName ( "Hunter" ) then 
            hunterFound = true 
        end 
    end 
    if hunterFound then maptype = "DM" else maptype = "DD" end 
    outputChatBox(getPlayerName(source).."*this is a"..tostring(maptype).." map",getRootElement(),0,255,0) 
end 
) 
  

edit: ive only checked/fixed the logic of script!, not if these lines:

  
if getElementData ( pu, "type" ) == "vehiclechange" 
        and getElementData ( pu, "vehicle" ) == getVehicleModelFromName ( "Hunter" ) then 
  

are valid and doing what they should

Link to comment
becouse it reset this to "dd" on another pickup.

do it like this:

  
addEventHandler("onMapStarting", root, 
function(mapInfo, mapOptions, gameOptions) 
    local hunterFound = false 
    for i, pu in pairs ( getElementsByType ( "racepickup" ) ) do 
        if getElementData ( pu, "type" ) == "vehiclechange" 
        and getElementData ( pu, "vehicle" ) == getVehicleModelFromName ( "Hunter" ) then 
            hunterFound = true 
        end 
    end 
    if hunterFound then maptype = "DM" else maptype = "DD" end 
    outputChatBox(getPlayerName(source).."*this is a"..tostring(maptype).." map",getRootElement(),0,255,0) 
end 
) 
  

edit: ive only checked/fixed the logic of script!, not if these lines:

  
if getElementData ( pu, "type" ) == "vehiclechange" 
        and getElementData ( pu, "vehicle" ) == getVehicleModelFromName ( "Hunter" ) then 
  

are valid and doing what they should

sorry also don't work :(

Again the same issue

Link to comment
try Debugging your script.

Read this carefully - you will need this many times.

especially outputDebugString

yes i know what debugscript is, i use it but there is not a error or waring

the only point is that he said it's alway a DD (also in DM maps)

script:

addEventHandler("onMapStarting", root, 
function(mapInfo, mapOptions, gameOptions) 
    if #getElementsByType ( "checkpoint" ) == 0 then -- checking DD/DM map 
        local hunterFound = false 
        for i, pu in pairs ( getElementsByType ( "racepickup" ) ) do 
        if getElementData ( pu, "type" ) == "vehiclechange" and getElementData ( pu, "vehicle" ) == getVehicleModelFromName ( "Hunter" ) then 
  
                hunterFound = true 
            end 
        end 
        if hunterFound then maptype = "DM" else maptype = "DD" end 
        outputChatBox("*this is a "..tostring(maptype).." map",getRootElement(),0,255,0) 
    end 
end 
) 

Link to comment
GOD! ! Read WHOLE wiki page I've sent you! Debugscript command is only small part in the art of debugging. Read especially that part about outputDebugString.

oh sorry xD

script:

addEventHandler("onMapStarting", root, 
function(mapInfo, mapOptions, gameOptions) 
    if #getElementsByType ( "checkpoint" ) == 0 then -- if 1 
        outputDebugString("entered if1") 
        local hunterFound = false 
        for i, pu in pairs ( getElementsByType ( "racepickup" ) ) do -- for1 
        outputDebugString("entered for1") 
        if getElementData ( pu, "type" ) == "vehiclechange" and getElementData ( pu, "vehicle" ) == getVehicleModelFromName ( "Hunter" ) then -- if2 
        outputDebugString("entered if2") 
                hunterFound = true 
            end 
        end 
        if hunterFound then maptype = "DM" else maptype = "DD" end 
        outputChatBox("*this is a "..tostring(maptype).." map",getRootElement(),0,255,0) 
    end 
end 
) 

you means like this?

so this is the result:

0times : entered if2 
1times : entered if 1 
number of vehicleschanges times: entered for1 

Link to comment

much better :)

you can do also:

outputDebugString(getElementData (pu, "type").." --- "..getElementData (pu, "vehicle")) 

oh! i just realized that getElementData from map file will probably return string for all values. this means for numebrs too.

so "425" (string) will never equal to 425 (integer) !

getElementData(pu, "vehicle") is probably returning "425" and getVehicleModelFromName is returning 425 (number) for sure.

if getElementData ( pu, "type" ) == "vehiclechange" and getElementData ( pu, "vehicle" ) == tostring(getVehicleModelFromName ("Hunter")) then -- if2 

if you will do debug with displaying each value - you will easly see that

Link to comment

You're wrong.

if hunterFound then maptype = "DM" else maptype = "DD" end 

You're checkin if hunterFound is nil. It can only be false or true (since it is defined as false and maybe defined as true later in the script), so you should be checking:

if hunterFound == true then maptype = "DM" else maptype = "DD" end 

:)

Link to comment

wut?

if variable then outputChatBox("1") end 

will output 1 if variable equals to true.

will not output if variable is nil or false.

It's logical:

  
if true then outputChatBox("1") end 
-- will always output 
if false then outputChatBox("1") end 
-- will never output 
  
-- logical eh? 
-- "if" conditional is passing when after "parsing" all checks the results is "true" - it's standard across all coding languages 
  

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