Jump to content

script help on my server...[for all my questions]


cokacola

Recommended Posts

okay, bored of making new topics, so this thread is for my questions on my server's scripts now :P

okay mail script(few threads down) isn't working.. ticket script is working

but i have a new non-working script..

i have tried and tried and tried to make this work, but i keep getting "you are not a medic" even when i am on the medic team...

p.s - this script has no warnings or errors at all..

function medicJob ( thePlayer, command, playerToHeal ) 
medicPlayer = getClientName(thePlayer) 
healingPlayer = getPlayerFromNick(playerToHeal) 
medicTeam = getPlayerTeam ( thePlayer ) 
if ( medicTeam == "Medic" ) then -- also tried "medic" "teamMedic" and "teammedic" but i think its this line that is not working, as it says... "you are not a medic" 
if ( getVehicleOccupant(source, 0) == medicPlayer ) then 
if ( getVehicleOccupant(source, 1) == healingPlayer ) then 
if ( getElementHealth(healingPlayer) == 100 ) then 
if ( getPlayerMoney(healingPlayer) < 250 ) then 
setElementHealth(healingPlayer, 100) 
takePlayerMoney(healingPlayer, 250) 
givePlayerMoney(medicPlayer, 250) 
else 
outputChatBox("This player does not have enough money to be healed($250 required).", medicPlayer) 
outputChatBox("You do not have enough money to be healed($250 requires)", healingPlayer) 
end 
else 
outputChatBox("the player in the front seat has full health already.", medicPlayer) 
end 
else 
outputChatBox("the person you want to heal is not in the front seat of ths vehicle.") 
end 
else 
outputChatBox("You are not the driver of this vehicle.", medicPlayer) 
end 
else 
outputChatBox("You'r not a medic.", medicPlayer) 
end 
end 
addCommandHandler("heal", medicJob) 

help would be good :)

Link to comment

I'l' take a look at this, but just a hint, indenting helps a lot ;)

EDIT: I found something at the line you yourself weren't sure about.

Wiki tells, that getPlayerTeam returns: "Returns a team element representing the team the player is on, false if the player is not part of a team. "

But you are comparing team element to a string, no wonder that it always returns false. So you'd have to either use "if ( getTeamName(medicTeam) == "Medic" ) then" or "if medicTeam == getTeamFromName("Medic")"

I didn't look at the rest of the code. One useful thing in wiki is the debugging tutorial - it shows how to debug with outputChatBox even if debugscript doesn't show anything

EDIT2: Pfft slothman was faster than my edit :P

Edited by Guest
Link to comment

youve fallen into the same trap many others have:

getTeamName ( playerTeam ) is what you need to get the name of the team. getPlayerTeam ( source ) doesnt really pull up the name. seems redundant, i know, but heres the proper way:

local playerTeam = getPlayerTeam ( thePlayer ) 
local medicTeam = getTeamName ( playerTeam )  
if ( medicTeam == "Medic" ) then  

Link to comment

I'm wondering... Do you know what source is?

It's only to be used in the case of events, not commands...

Use:

theVehicle = getPlayerOccupiedVehicle ( thePlayer ) 

Do NOT use source. It can only get you to trouble when using it anywhere but in events.

Link to comment

Ofcourse bad argument there. Source is a nil value there. It is only defined for events, but you are using a command handler. And I can't understand anyway, why you put source there. It has to be a vehicle eleemnt. Go read wiki about getVehicleOccupant :)

Link to comment

yea it works now...

"player in front seat has full health"

every if just errors 1 after the other ...

function medicJob ( thePlayer, command, playerToHeal ) 
medicPlayer = getClientName(thePlayer) 
healingPlayer = getPlayerFromNick(playerToHeal) 
playerTeam = getPlayerTeam ( thePlayer ) 
medicTeam = getTeamName ( playerTeam ) 
if ( medicTeam == "Medic" ) then 
    if ( getPlayerOccupiedVehicle ( thePlayer ) == "Ambulance" ) then 
        if ( getPlayerOccupiedVehicle ( playerToheal ) == "Ambulance" ) then 
            if ( getElementHealth(healingPlayer) > 99 ) then 
                if ( getPlayerMoney(healingPlayer) < 250 ) then 
                    setElementHealth(healingPlayer, 100) 
                    takePlayerMoney(healingPlayer, 250) 
                    givePlayerMoney(medicPlayer, 250) 
                else 
                    outputChatBox("This player does not have enough money to be healed($250 required).", medicPlayer) 
                    outputChatBox("You do not have enough money to be healed($250 requires)", healingPlayer) 
                end 
            else 
                outputChatBox("the player in the front seat has full health already.", medicPlayer) 
            end 
        else 
    outputChatBox("the person you want to heal is not in the front seat of ths vehicle.") 
end 
else 
    outputChatBox("You are not in an ambulance.", medicPlayer) 
end 
else 
    outputChatBox("You'r not a medic.", medicPlayer) 
end 
end 
addCommandHandler("heal", medicJob) 

Edit: added indentation - since apparently it makes it easier to read or something...never made sense to me, it just a effort taking time thingy :D

Edited by Guest
Link to comment

Way better to read it now. :)

            if ( getElementHealth(healingPlayer) > 99 ) then 
  

Now,this line tells that if the player health is over 99, then continue with the things until else or end.

So if he has less than 99 then it will trigger the else part. I believe you want it this way:

if getElementHealth(healingPlayer) < 100 then 

EDIT: Also, getPlayerOccupiedVehicle (for nightlys getPedOccupiedVehicle) returns an element not a string, so getPlayerOccupiedVehicle(thePlayer) == "Ambulance" always returns false

Link to comment

so i should set it to...something else?(the vehicle occupied thingy) abnd what should i set it to?

oh also, if it helps that much i will indent my code before posting :)

o i can't help but show you my first job script ever(you can tell me how to improve it if you wish, for example, the map blip and text comes up on everyones screen not just the player doing the job - main reason i am posting it here :) - )

--dilivery mission 
createMarker(2221.9304199219, -1173.4736328125, 25.7265625, cylinder) 
truckJobMarkersStrt = createColCircle ( 2221.9304199219, -1173.4736328125, 10.0 ) 
function truckJobStart ( thePlayer ) 
    playerUse = getClientName(source) 
    missionon = playerUse 
    outputChatBox("You've started a delivery mission. Get to the truck marker on the map to finnish and get paid.", playerUse) 
    truckJobBlip = createBlip ( 857.07098388672, -1292.5166015625, 13.617831230164, 51, 2, 255, 0, 0, 255, 0 , getRootElement() ) 
end 
    addEventHandler ( "onColShapeHit", truckJobMarkersStrt, truckJobStart ) 
function finnishTruckJob ( thePlayer ) 
    playerUse = getClientName(thePlayer) 
    if ( missionon == playerUse)  then 
        outputChatBox("Thanks for the crack! here is m..m...money..", playerUse) 
        setPlayerWantedLevel(thePlayer, 3) 
        givePlayerMoney(thePlayer, 5000) 
        missionon = "none" 
        destroyElement ( truckJobBlip ) 
    end 
end 
truckJobEndMark = createColCircle(857.07098388672, -1292.5166015625, 10.0) 
addEventHandler ( "onColShapeHit", truckJobEndMark, finnishTruckJob ) 

Edited by Guest
Link to comment
    if ( getVehicleName(getPlayerOccupiedVehicle ( thePlayer )) == "Ambulance" ) then   -- This checks for the name, instead of the element 
        if ( getPlayerOccupiedVehicle ( playerToheal ) == getPlayerOccupiedVehicle ( thePlayer ) ) then   -- Instead of checking if they're both in an Ambulance, why not checking if they're in the SAME ambulance?  
            if ( getElementHealth(healingPlayer) < 100 ) then   -- See lord's post 

I think this should fix that particular part. Didn't test it though. You can remove the things after the -- by the way, they're just there to explain some stuff. ;)

Link to comment

hmm "player you're trying to heal is not in the front seat"

aka bad argument at 'getPlayerOccupiedVehicle'

(this line: if ( getPlayerOccupiedVehicle ( playerToHeal ) == getPlayerOccupiedVehicle ( thePlayer ) ) then )

yea i changed playerToheal to playerToHeal to see if it would work...

:/

Link to comment

Mistake on my part too I guess. It should be healingPlayer. :P

Expecting no more catastrophe from that, therefore moving on to your next piece of script.

... 
function truckJobStart ( thePlayer ) 
    playerUse = getClientName(source) 
    missionon = playerUse 
    outputChatBox("You've started a delivery mission. Get to the truck marker on the map to finnish and get paid.", playerUse) 
    truckJobBlip = createBlip ( 857.07098388672, -1292.5166015625, 13.617831230164, 51, 2, 255, 0, 0, 255, 0 , getRootElement() ) 
end 
... 

This is the only blip I found, and I understand why it shows up for everyone. getRootElement() means parent of all elements. visibleTo is set to the root element. In this case, that means that all players will get to see it.

How to fix this? Replace getRootElement() with a player element. I'd say you need to use thePlayer.

By the way, is it just me, or doesn't truckJobStart make any sense at all? Let's sum up some things:

- You're making the function, with thePlayer as first argument.

- Here you're trying to get a player name out of a marker... Ehm... You need to give a player element (thePlayer) not a marker... (source) (more info on this event HERE)

- The outputChatBox function needs a player element, not the player name. (although it's actually the "marker name" right now, which doesn't exist and therefor is false :P)

- Seeing that you use getClientName, I assume you're still on DP2.x. createBlip does NOT have the ordering parameter in DP2, only in 1.0.

- I might have missed something...

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