Pay system wont work!

Heya Facepunchers!

Kay, so, heres my problem. Im programming a gamemode, where you pay for props, but it wont work.

I have a table that contains the props model, and the props price, the thing is, that it just wont pay the correct price.

If its in the table, it still pays the default price!

Heres my code to get the price, and the table:

[lua]
local DEFAULT_PRICE_PROP = 1 – Prop default price
local propPrices = { [“models/Combine_Helicopter/helicopter_bomb01.mdl”] = 10 } – [“model_name”] = price

function getPropPrice(mdl)
if(!propPrices[mdl] or propPrices[mdl] == nil) then
return DEFAULT_PRICE_PROP
else
return propPrices[mdl]
end
end
[/lua]

Oliver

  • snip for odd coding habits -

[lua]local DEFAULT_PRICE_PROP = 1 – Prop default price
local propPrices = { [“models/Combine_Helicopter/helicopter_bomb01.mdl”] = 10 } – [“model_name”] = price

function getPropPrice(mdl)
return propPrices[mdl] or DEFAULT_PRICE_PROP
end
[/lua]

Try that.

YAY! Thank you very much MakeR :woop:

I’ve not seen that syntax for tables before. I’m probably wasting time but just to be on the safe side try

[lua]
local propPrices = {}
propPrices[“models/Combine_Helicopter/helicopter_bomb01.mdl”] = 10
[/lua]

Also add some print lines to help with the debugging.

eg
[lua]
local DEFAULT_PRICE_PROP = 1 – Prop default price
local propPrices = { [“models/Combine_Helicopter/helicopter_bomb01.mdl”] = 10 } – [“model_name”] = price

function getPropPrice(mdl)
print(mdl)
print(propPrices[mdl]
if(!propPrices[mdl] or propPrices[mdl] == nil) then
return DEFAULT_PRICE_PROP
else
return propPrices[mdl]
end
end
[/lua]

Well, your kinda late. But the syntax is from GMod Wiki, I cant remember where, but I saw it, and I wrote it down in the comment, so I would remember. See, im new at LUA.

But MakeR’s example worked perfeclty :-).

You are welcome.