School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,495 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,844 people online right now. Registration is fast and FREE... Join Now!




Need help with LUA

 

Need help with LUA

A208

19 May, 2009 - 08:47 AM
Post #1

New D.I.C Head
*

Joined: 19 May, 2009
Posts: 5


My Contributions
In particular with LUA for a gamemode for the game Garrysmod, i will post the code when i get home right now im at school i was just wondering if anyone here knows much LUA that would be helpful

User is offlineProfile CardPM
+Quote Post


erik.price

RE: Need Help With LUA

19 May, 2009 - 11:11 AM
Post #2

Segfault Artist
Group Icon

Joined: 18 Dec, 2008
Posts: 694



Thanked: 23 times
Dream Kudos: 525
My Contributions
I know some, and might be able to help you out, but more likely then not KYA will be here and beat me up with his superior Lua knowledge. tongue.gif So the answer is yes, someone will probably be able to help you smile.gif
User is offlineProfile CardPM
+Quote Post

A208

RE: Need Help With LUA

19 May, 2009 - 03:02 PM
Post #3

New D.I.C Head
*

Joined: 19 May, 2009
Posts: 5


My Contributions
ok thank you and the main problem of my gamemode for garrysmod is that for some reason the teams arnt loading and i know not everyone that understands normal lua will be able to help me with this but here it goes and i have a couple of problems heres the 1st

1st problem which probly causes the 2nd
the teams wont work when you look at team menu it show everyone on team Unassigned and since Friendly fire is off because this is a team deathmatch game mode noone can kill
CODE
function GM:PlayerInitialSpawn(ply)
  if team.NumPlayers(TEAM_BLUE) <= team.NumPlayers(TEAM_RED) then
    ply:SetTeam(TEAM_BLUE)
  else
    ply:SetTeam(TEAM_RED)
  end
  self.BaseClass:PlayerInitialSpawn(ply)
end

function GM:PlayerLoadout(ply)
  return
end



2nd problem
For some reason it does not want to print the part about changing teams on game join and the f4 doesnt work which f4=showspare2
CODE
function GM:KeyPress(p, key)
    if ( key == ShowSpare2 ) then
        if ( p:Team( )== TEAM_BLUE ) then
        p:SetTeam( TEAM_RED )
        p:Kill( )
        p:PrintMessage(HUD_PRINTTALK,"you don't want to be in the Red team? Press 'F4' to be one again!"); -- eg: Aliens (blue)
        p:SprintEnable ()
        p:AddFrags(1)
        else
        p:SetTeam( TEAM_BLUE )
        p:Kill( )
        p:PrintMessage(HUD_PRINTTALK,"you don't want to be in the Blue team? Press 'F4' to be one again!"); -- eg: Predator(red)
        p:SprintDisable ()
        p:AddFrags(1)
        end
    end
    self.BaseClass:KeyPress(p, key)
end



Edit: this might also be where the teams problem comes from but i dont think so
CODE
TEAM_RED = 1
TEAM_BLUE = 2
team.SetUp(TEAM_RED, "Red Team", Color(255, 0, 0, 255)) -- RED TEAM, It appear in scores
team.SetUp(TEAM_BLUE, "Blue Team", Color(0, 0, 255, 255)) -- BLUE TEAM, It appear in scores


This post has been edited by A208: 19 May, 2009 - 03:05 PM
User is offlineProfile CardPM
+Quote Post

Jubb

RE: Need Help With LUA

20 May, 2009 - 07:30 AM
Post #4

D.I.C Head
**

Joined: 6 May, 2009
Posts: 76



Thanked: 5 times
My Contributions
Are TEAM_RED and TEAM_BLUE still in scope when you use them to assign players to each team? Check if they're nil before doing the condition:

CODE
if team.NumPlayers(TEAM_BLUE) <= team.NumPlayers(TEAM_RED)

User is offlineProfile CardPM
+Quote Post

A208

RE: Need Help With LUA

20 May, 2009 - 08:54 AM
Post #5

New D.I.C Head
*

Joined: 19 May, 2009
Posts: 5


My Contributions
yes i think they are still in scope but i just thought it might be better if the 3rd code is in init.lua with the 1st code lol right now the 3rd part is in shared.lua


but my friend gave me an idea what if i change

CODE
TEAM_RED = 1
TEAM_BLUE = 2
team.SetUp(TEAM_RED, "Red Team", Color(255, 0, 0, 255)) -- RED TEAM, It appear in scores
team.SetUp(TEAM_BLUE, "Blue Team", Color(0, 0, 255, 255)) -- BLUE TEAM, It appear in scores


to
CODE
TEAM_RED = 1
TEAM_BLUE = 2
team.SetUp(1, "Red Team", Color(255, 0, 0, 255)) -- RED TEAM, It appear in scores
team.SetUp(2, "Blue Team", Color(0, 0, 255, 255)) -- BLUE TEAM, It appear in scores


i changed the team.setup(team_red to 1 which is team red as you can see that might be better but i have no clue if it will work any comments on that idea?? maybe it might fix my prob but for now i cant test as once again i am at school

This post has been edited by A208: 20 May, 2009 - 08:56 AM
User is offlineProfile CardPM
+Quote Post

KYA

RE: Need Help With LUA

20 May, 2009 - 09:09 AM
Post #6

#include <nerd.h>
Group Icon

Joined: 14 Sep, 2007
Posts: 11,192



Thanked: 489 times
Dream Kudos: 2825
Expert In: C, C++, Java

My Contributions
The problem here isn't really a familiarity with Lua, but with how Garry's Mod uses its scripts. Isn't there a wiki or knowledge base on it somewhere?
User is offlineProfile CardPM
+Quote Post

A208

RE: Need Help With LUA

20 May, 2009 - 03:40 PM
Post #7

New D.I.C Head
*

Joined: 19 May, 2009
Posts: 5


My Contributions
QUOTE(KYA @ 20 May, 2009 - 09:09 AM) *

The problem here isn't really a familiarity with Lua, but with how Garry's Mod uses its scripts. Isn't there a wiki or knowledge base on it somewhere?


Yes there is but really it is the most usless "Help" site i have ever seen to tell you the truth i think how garrys set up garrysmod to use its scripts is stupid as hell and look this is how it tells you to do it for teams which this is exactly how i did it (with some modification of corse)
CODE

function GM:CreateTeams()

    if ( !self.TeamBased ) then return end

    TEAM_USSR = 1
    team.SetUp( TEAM_USSR, "USSR/Russia", Color( 255, 0, 0, 255 ) )
    team.SetSpawnPoint( TEAM_USSR, "info_player_terrorist" )

    TEAM_USA = 2
    team.SetUp( TEAM_USA, "USA", Color( 0, 0, 255, 255 ) )
    team.SetSpawnPoint( TEAM_USA, "info_player_counterterrorist" )

end    


Edit: Omg im so stupid i never called the function for createteams..its always those stupid little things that mess me up icon_down.gif

This post has been edited by A208: 20 May, 2009 - 03:42 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 04:49AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month