Jump to content

little problem


Sparrow

Recommended Posts

I'm working on some RPG jobs to get more skills in scripting,

so this what I do, no errors.

function createPoliceTeam() 
    policeTeam = createTeam ("Police", 25, 50, 255) 
end 
addEventHandler ("onResourceStart", getRootElement(), createPoliceTeam) 
  
local jobMarker = createMarker (1574.700, -1634.300, 12.600, "cylinder", 1.5, 25, 50, 255, 255) 
function setJob(hitElement, thePlayer) 
    local wanted = getPlayerWantedLevel (thePlayer) 
    if (wanted == 0) then 
        if getElementType(hitElement) == "player" then 
            playerName = getPlayerName ( getLocalPlayer() ) 
            if not guiGetVisible(window) then 
                guiSetVisible(window, true) 
                showCursor(true) 
            elseif (wanted > 0) then 
                showCursor(false) 
                guiSetVisible(window, false) 
            end 
        end 
    end 
end 
addEventHandler("onClientMarkerHit", jobMarker, setJob) 
  
function acceptJob (thePlayer) 
    local getTeam = getTeamFromName ("Police") 
    if theTeam then 
        setPlayerTeam (thePlayer, getTeam) 
        setElementModel (thePlayer, 280) 
        guiSetVisible(window, false) 
        showCursor(false) 
        outputChatBox ("You are now police officer.", thePlayer, 0,255, 0) 
    else 
        outputChatBox ("You are wanted, you can not take this job.", thePlayer, 255, 0, 0) 
    end 
end 
addEventHandler("onClientGUIClick", acceptButton , acceptJob, false) 

it didn't set me in "Police" team, and it says that I'm wanted.

how to fix this? and thanks.

Link to comment

I do this, it didn't work, also no errors

server:

function createPoliceTeam() 
    policeTeam = createTeam ("Police", 25, 50, 255) 
end 
addEventHandler ("onResourceStart", getRootElement(), createPoliceTeam) 
  
function acceptJob ( ) 
    local getTeam = getTeamFromName ("Police") 
    if theTeam then 
        setPlayerTeam (source, policeTeam) 
        setElementModel (source, 280) 
        guiSetVisible(window, false) 
        showCursor(false) 
        outputChatBox ("You are now police officer.", source, 0,255, 0) 
    else 
        outputChatBox ("You are wanted, you can not take this job.", source, 255, 0, 0) 
    end 
end 
addEvent ("setTeam", true) 
addEventHandler ("setTeam", getRootElement(), acceptJob) 

client:

local jobMarker = createMarker (1574.700, -1634.300, 12.600, "cylinder", 1.5, 25, 50, 255, 255) 
  
function setJob(hitElement, thePlayer) 
    local wanted = getPlayerWantedLevel (thePlayer) 
    if (wanted == 0) then 
        if getElementType(hitElement) == "player" then 
            playerName = getPlayerName ( getLocalPlayer() ) 
            if not guiGetVisible(window) then 
                guiSetVisible(window, true) 
                showCursor(true) 
            elseif (wanted > 0) then 
                showCursor(false) 
                guiSetVisible(window, false) 
            end 
        end 
    end 
end 
addEventHandler("onClientMarkerHit", jobMarker, setJob) 

Link to comment

Server

addEvent( 'onAcceptJob',true ) 
  
addEventHandler( 'onAcceptJob',root, 
    function( ) 
        setPlayerTeam ( source,getTeamFromName( 'Police' ) ) 
        setElementModel ( source, 280 ) 
    end 
) 
     
addEventHandler ( 'onResourceStart', resourceRoot,  
    function( ) 
        createTeam ( "Police", 25, 50, 255 ) 
    end 
) 

Client

local jobMarker = createMarker ( 1574.700, -1634.300, 12.600, "cylinder", 1.5, 25, 50, 255, 255 ) 
function setJob( player, dim ) 
    if player == localPlayer then 
        local wanted = getPlayerWantedLevel ( ) 
        if wanted == 0 then 
            if not guiGetVisible( window ) then 
                guiSetVisible( window, true ) 
                showCursor( true ) 
            elseif wanted > 0 then 
                showCursor( false ) 
                guiSetVisible( window, false ) 
            end 
        end 
    end  
end 
addEventHandler( "onClientMarkerHit", jobMarker, setJob ) 
  
function acceptJob ( ) 
    local uTeam = getPlayerTeam( localPlayer ) 
    if uTeam and getTeamName ( uTeam ) ~= 'Police' then 
        triggerServerEvent( 'onAcceptJob',localPlayer ) 
        guiSetVisible( window, false ) 
        showCursor( false ) 
        outputChatBox ( "You are now police officer.", thePlayer, 0,255, 0 ) 
    else 
        outputChatBox ( "You are wanted, you can not take this job.", thePlayer, 255, 0, 0 ) 
    end 
end 
addEventHandler( "onClientGUIClick", acceptButton , acceptJob, false ) 

You need learn https://wiki.multitheftauto.com/wiki/Scr ... troduction

You should use in side( client or server ) appropriate function or event.

Example if you create gui you need use in client side ( not in server side )

P.S variable window is defined?

P.S updated.

Link to comment

Deleted, - Kenix beat me D:

NOTE: When setting teams you can't just do this

function createTeams() 
police = createTeam("police",255,0,0) 
end 
  
function setTeam() 
setPlayerTeam(player, police) 
end 
addCommandHandler("setTeam", setTeam) 

You have to get the team name and use that to set the team, like this:

function createTeams() 
police = createTeam("police",255,0,0) 
end 
  
function setTeam() 
local getPoliceTeam = getTeamFromName("police") 
setPlayerTeam(player, getPoliceTeam) 
end 
addCommandHandler("setTeam", setTeam) 

Link to comment

here is the gui, I wanna only the GUI showed on screen when player walk to it.

window = guiCreateWindow(438,171,370,406,"Job System",false) 
guiWindowSetSizable(window,false) 
infoLabel = guiCreateLabel(150,32,66,20,"Police job",false,window) 
guiLabelSetColor(infoLabel,0,255,0) 
guiSetFont(infoLabel,"clear-normal") 
jobMemo = guiCreateMemo(19,61,332,255,"Police job: Description coming soon.!",false,window) 
guiMemoSetReadOnly(jobMemo,true) 
acceptButton = guiCreateButton(54,334,113,45,"Accept",false,window) 
closeButton = guiCreateButton(206,333,113,45,"Close",false,window) 

Link to comment
window = guiCreateWindow( 438,171,370,406,"Job System",false ) 
guiWindowSetSizable( window,false ) 
infoLabel = guiCreateLabel( 150,32,66,20,"Police job",false,window ) 
guiLabelSetColor( infoLabel,0,255,0 ) 
guiSetFont( infoLabel,"clear-normal" ) 
jobMemo = guiCreateMemo( 19,61,332,255,"Police job: Description coming soon.!",false,window ) 
guiMemoSetReadOnly( jobMemo,true ) 
acceptButton = guiCreateButton( 54,334,113,45,"Accept",false,window ) 
closeButton = guiCreateButton( 206,333,113,45,"Close",false,window ) 
guiSetVisible( window,false ) 
  
local policePed = createPed (280, 1576.751, -1634.270, 13.556, 90 ) 
local jobMarker = createMarker ( 1574.700, -1634.300, 12.600, "cylinder", 1.5, 25, 50, 255, 255 ) 
function setJob( player, dim ) 
    if player == localPlayer then 
        local wanted = getPlayerWantedLevel ( ) 
        if wanted == 0 then 
            if not guiGetVisible( window ) then 
                guiSetVisible( window, true ) 
                showCursor( true ) 
            elseif wanted > 0 then 
                showCursor( false ) 
                guiSetVisible( window, false ) 
                outputChatBox ( "You are wanted, you can not take this job.", thePlayer, 255, 0, 0 ) 
            end 
        end 
    end  
end 
addEventHandler( "onClientMarkerHit", jobMarker, setJob ) 
     
function acceptJob ( ) 
    local uTeam = getPlayerTeam( localPlayer ) 
    if not uTeam or uTeam and getTeamName ( uTeam ) ~= 'Police' then 
        triggerServerEvent( 'onAcceptJob',localPlayer ) 
        guiSetVisible( window, false ) 
        showCursor( false ) 
        outputChatBox ( "You are now police officer.", 0,255, 0 ) 
    else 
        outputChatBox ( "You are already police officer.", 0,255, 0 ) 
    end 
end 
addEventHandler( "onClientGUIClick", acceptButton , acceptJob, false ) 
  
function removePoliceWindow( ) 
    guiSetVisible( window, false ) 
    showCursor( false) 
end 
addEventHandler( "onClientGUIClick", closeButton , removePoliceWindow, false ) 

You lol.

On resource start it create window FOR ALL CLIENTS ( Why you say if you hit marker it showed for all players ???? :/ )

Code updated.

Edited by Guest
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...