Giving Weapons for Specifix Maps

Hi all!
I’m kinda a lua noob, but i’m trying to learn.
I’m wondering if i could get some help with this script


  if SERVER then
      AddCSLuaFile("Pirate.lua")
end
  if game.GetMap()=="ttt_pirate.bsp" then
local function giveWeapon(ply)
if ply:IsUser() or ply:IsAdmin() then
ply:Give("weapon_ttt_pirate1")
ply:Give("weapon_ttt_pirate2")
ply:Give("weapon_ttt_pirate3")
ply:SetModel("models/player/pirate_blue.mdl")
elseif ply:Issuperadmin() then
ply:Give("weapon_ttt_pirate1")
ply:Give("weapon_ttt_pirate2")
ply:Give("weapon_ttt_pirate3")
ply:SetModel("models/player/pirate_redd.mdl")
end
end
hook.Add("playerInitialSpawn", "giverankedWeapon", giveWeapon)


Basically I’m trying to get it so that if it’s a certain map give players weapons and a model, at the moment I am getting


lua: Pirate.lua:14: 'end' expected (to close 'if' at line 4) near '<eof>'

Move "local function "one line up and add an “end” before hook.Add.

try something like this


hook.Add("PlayerSpawn", "giveRankedWeapon", function( ply )
	if game.GetMap() = "ttt_pirate.bsp" then
		if ply:IsSuperAdmin() then
			ply:Give("weapon_ttt_pirate1")
			ply:Give("weapon_ttt_pirate2")
			ply:Give("weapon_ttt_pirate3")
			ply:SetModel("models/player/pirate_redd.mdl")
		else
			ply:Give("weapon_ttt_pirate1")
			ply:Give("weapon_ttt_pirate2")
			ply:Give("weapon_ttt_pirate3")
			ply:SetModel("models/player/pirate_blue.mdl")
		end
	end
end)

Also, read up on code formatting.

Alright thanks for the help, sorry i am kinda new to this.

[editline]30th October 2013[/editline]

Also just to add, it seems like the Set model isn’t working any suggestions?

game.GetMap doesn’t return a .bsp
Put
if game.GetMap() == “ttt_pirate” then

Yeah I managed to work that out pretty quick but I still can’t get the models working.

They must be overridden by another script somewhere else. Or by the gamemode.

Alrighty then I’ll try I figure it out then.

Dgenaraition if you are hooking into PlayerInitialSpawn, that will only be called the first time the player spawns. I suggest hooking into ‘PlayerSpawn’ or ‘PlayerLoadout’ either should work just fine.

Good luck fellow Lua noob :slight_smile:

[editline]30th October 2013[/editline]

Add a short timer before setting the player models. TTT could possibly be setting the model after you set your pirate model.



timer.Simple( 1.5, function()
ply:SetModel("models/player/pirate_blue.mdl")
end)


Thank you for the suggestions I’ll let you know how it goes.

Everything is working, just quickly what is the lua code for checking if someones a t, so i can give a t a weapon on spawn.



if ply:GetRole() == ROLE_TRAITOR then


Just a guess let me know if it works.

I can’t find the radar anyone know where it is and does anyone know how to get guns to not colide with eachother.

Uh, TTT has a basic function for spawning with weapons. In the SWEP files, SWEP.InLoadoutFor or something simular

No one’ll be T on spawn, use the TTTBeginRound hook

Make sure you check that the player is alive/not a spectator, or you’ll have floating guns flying around.