Jump to content

Couple of problems with my racing script


kuwalda

Recommended Posts

Hello everyone, I have finally almost finished my first big script (I have posted only main part here), but I have some troubles with it, which I can`t still fix after numerous times of trying. I have commented almost every line of code, so you can understand easyer what this code does:

function testejam(thePlayer, command) 
    if ( getElementData( thePlayer, "allowrace" ) == 1 ) then --predefined value, all fine here =) 
        local ciga = getElementData ( thePlayer, "dbid" ) --variable "ciga" contains players checkpoint ID number 
        if ( #_G[""..getElementData( thePlayer, "raceParticipate" )..""] > ciga ) then -- checks if player have not reached last checkpoint from defined race 
            destroyElement(getElementData(thePlayer, "checkpoints")) -- lets destroy last checkpoint 
            setElementData(thePlayer, "checkpoints", createMarker(..., "checkpoint", 6, 190, 156, 252, 50, thePlayer)) -- store that all big checkpoint info in players element data 
            setMarkerTarget(getElementData(thePlayer, "checkpoints"),... ) -- and its sets its target point 
            setElementVisibleTo(getElementData(thePlayer, "checkpoints"), root, false) -- noone sees checkpoint 
            setElementVisibleTo(getElementData(thePlayer, "checkpoints"), thePlayer, true) -- ^ exept player 
            setElementData ( thePlayer, "dbid", getElementData ( thePlayer, "dbid" ) + 1 ) -- and adds up +1 to next checkpoint for next time on activating 
        end 
            if isElementVisibleTo(getElementData(thePlayer, "checkpoints"),thePlayer) then -- if player can see this checkpoint 
                addEventHandler( "onMarkerHit", getElementData(thePlayer, "checkpoints"), testejam ) -- you can activate same loop on next time hiting that checkpoint 
            end 
    end 
end 
  
--Command to type, to active this event only once 
addCommandHandler("race", 
function (thePlayer, command) 
     if (getElementData(thePlayer, "allowedToUseThisCommand") == true) then 
           testejam(thePlayer, command) 
           setElementData( thePlayer, "allowedToUseThisCommand", false) 
     end 
end 
) 

(you may want to copy this into some text editor to see those lines better)

With this script I have 2 main problems:

* When any player types /race , this race is activated for everyone. Other players can`t see 1st checkpoint, but when they drive through them, they activate the whole loop and are into race.

* When 2 players have checkpoint at same place ("dbid" value is the same for both players), then:

first player who reaches this checkpoint drives as normal, everything is fine for him

second player who reaches this checkpoint, after reaching it, gets +2 to his "dbid" value, meaning he skips 1 checkpoint. Like if I see checkpoint number 5, after hitting it I will see checkpoint number 7 instantly.

If anyone have found my mistakes or can suggest anything, I would be greatful, because I have tried to fix these problems over an week.

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