Author Topic: Multiple Scripting Problems  (Read 200 times)

0 Members and 1 Guest are viewing this topic.

Offline StartedBullet

  • ****
  • Posts: 262
  • Gender: Male
  • Blissfully unaware, or am I?
  • Respect: +19
Multiple Scripting Problems
« on: September 05, 2010, 07:01:32 PM »
0
Hello, I'm having trouble running console commands for my gamemode, here is what im talking about:


gamemodes\laststand\gamemode\init.lua:25: '=' expected near 'player'-init
--player:concommand( "PlayerInitialGear" )
_______________



gamemodes\laststand\gamemode\cl_init.lua:21: 'then' expected near 'player'
-cl_init
--player:ConCommand( "sb_team1" )
________________

Any ideas on what I am doing wrong?/ Do you know any other ways i can run a console command?



Thats solved. But heres another problem: It considers 'ready' invalid somehow and won't paint my vgui-function HumanBuy( ply )
 
 

 

ready = vgui.Create( "BFrame" )
ready:SetPos( ScrW() / 2, ScrH() / 2 ) //Set the position. Half the screen height and half the screen width. This will result in being bottom right of the middle of the screen.
ready:SetSize( 175, 175 ) //The size, in pixels of the Frame
ready:SetTitle( "Select Items/Upgrades" )
ready:SetVisible( true )
ready:SetDraggable( true )
ready:ShowCloseButton( true )
ready:MakePopup()


ready1 = vgui.Create( "BButtonSMG1", Ready ) // Define ready1 as a "DButton" with its parent the Ready frame we just created above.
ready1:SetPos( 20, 160 ) //Set position, relative to the frame (If you didn't parent it, it would be relative to the screen
ready1:SetSize( 140, 40 ) // How big it should be, again in pixels
ready1:SetText( "Buy SMG1-5" )
ready1.DoClick = function() //ready1.doclick = function, we just defined it as a function

ply:Give( "weapon_SMG1" )
 Player:GiveAmmo(25,"smg1")
 ply:SetNWInt("killcounter", ply:GetNWInt("killcounter") - 5)
 
end
 


ready2 = vgui.Create( "BButtonSMG1Ammo", Ready ) // Define ready1 as a "DButton" with its parent the Ready frame we just created above.
ready2:SetPos( 170, 160 ) //Set position, relative to the frame (If you didn't parent it, it would be relative to the screen
ready2:SetSize( 140, 40 ) // How big it should be, again in pixels
ready2:SetText( "Buy SMG1 Ammo-2" )
ready2.DoClick = function() //ready1.doclick = function, we just defined it as a function

Player:GiveAmmo(15,"smg1")
 ply:SetNWInt("killcounter", ply:GetNWInt("killcounter") - 2)
 

 end
 

ready3 = vgui.Create( "BButtonShotgun", Ready ) // Define ready1 as a "DButton" with its parent the Ready frame we just created above.
ready3:SetPos( 20, 120 ) //Set position, relative to the frame (If you didn't parent it, it would be relative to the screen
ready3:SetSize( 140, 40 ) // How big it should be, again in pixels
ready3:SetText( "Buy Shotgun-10" )
ready3.DoClick = function() //ready1.doclick = function, we just defined it as a function

ply:Give( "weapon_Shotgun" )
 Player:GiveAmmo(10,"buckshot")
 ply:SetNWInt("killcounter", ply:GetNWInt("killcounter") - 10)
 
 end
 
 

ready4 = vgui.Create( "BButtonShotgunAmmo", Ready ) // Define ready1 as a "DButton" with its parent the Ready frame we just created above.
ready4:SetPos( 170, 120 ) //Set position, relative to the frame (If you didn't parent it, it would be relative to the screen
ready4:SetSize( 140, 40 ) // How big it should be, again in pixels
ready4:SetText( "Buy Shotgun Ammo-4" )
ready4.DoClick = function() //ready1.doclick = function, we just defined it as a function
 
Player:GiveAmmo(8,"buckshot")
 ply:SetNWInt("killcounter", ply:GetNWInt("killcounter") - 4)
 
 

 
end
end

Then theres my last post aswell. But im extremely close to finishing my gamemode (first).
« Last Edit: September 06, 2010, 12:47:50 AM by StartedBullet »
Turned a new leaf.


Furry artist.

Offline Tomcat

  • Your Argument is Inert
  • ******
  • Donator
    View More Badges!

  • Posts: 2539
  • Gender: Male
  • Wat Do?
  • Respect: +503
    • Tomcat's blog
Re: Gamemode LUA scripting problem/player:ConCommand
« Reply #1 on: September 05, 2010, 07:42:27 PM »
0
you need to do LocalPlayer:ConCommand()

Offline Кrаsher

  • ****
  • Posts: 436
  • Gender: Male
  • Posts: 9001
  • Respect: +50
Re: Gamemode LUA scripting problem/player:ConCommand
« Reply #2 on: September 05, 2010, 08:02:41 PM »
0
you need to do LocalPlayer:ConCommand()
that is deprecated bro

since I know what tut you are getting this from...

put that in GM:PlayerInitialSpawn( ply )
as RunConsoleCommand("sb_team1")
« Last Edit: September 05, 2010, 08:09:18 PM by Кrашер »





Offline Rbn

  • **
  • Linux UserOld Forum MemberrNd Developer
    View More Badges!

  • Posts: 55
  • Gender: Male
  • Include( 'Yuban.lua' )
  • Respect: +121
Re: Gamemode LUA scripting problem/player:ConCommand
« Reply #3 on: September 05, 2010, 08:52:37 PM »
0
Hello, I'm having trouble running console commands for my gamemode, here is what im talking about:


gamemodes\laststand\gamemode\init.lua:25: '=' expected near 'player'-init
--player:concommand( "PlayerInitialGear" )
_______________



gamemodes\laststand\gamemode\cl_init.lua:21: 'then' expected near 'player'
-cl_init
--player:ConCommand( "sb_team1" )
________________

Any ideas on what I am doing wrong?/ Do you know any other ways i can run a console command?

Let's see...

- If your working on a clientside script to set player on a custom team, need to be triggered somehow like a button or something, you can do other things but
  i do not really recommend it on client :/, unless you want to make the player select team.

- Кrашер GM:PlayerInitialSpawn( ply ) is serverside only so RunConsoleCommand Will affect console not the player.

Code: [Select]
function GM:PlayerInitialSpawn( ply )

   ply:ConCommand("sb_team1") -- notice that server will trigger it only on the 1stly spawn.

end

naturally sb_team1 command will be like.

Code: [Select]
concommand.Add("sb_team1", function( p,c,a ) p:SetTeam("TEAM_NAME" [[ or #index of team ]]) end )
But if you want to work over performance and efficiency, DEPENDING ON WHAT YOU ARE DOING.

I recommend using like this.

Code: [Select]
function GM:PlayerInitialSpawn( ply )

   ply:SetTeam( "TEAM_NAME" [[ or #index of team ]] ) -- This will make that server set player on the specified team and do not need to trigger command on client.

end

On wiki when they put "player",  this mean that you need the Player Entity, not to put it as they write, like first Entities on a 16 / 16 server are related to player entity slots so will be like

Entity(1):Nick() -- Return Nick of the player that Have in the Entity index #1.

Entity(1) = Whole Class Entity of a player, Nick() method to obtain the name or nick.

Check an example or trying to do an example lol.

Code: [Select]
function SetPlayerOnTeam( playerobtained )

   playerobtained:SetTeam(1)

end

SetPlayerOnTeam( Entity(1) ) -- i sent the player's entity as an argument, then the function make the rest of the work.

ClientSide = RunConsoleCommand( STRING )

ServerSide = PLAYER:ConCommand( STRING )

PLAYER = Entity of the player as explained before.

Hope that will be helpful for you.
« Last Edit: September 05, 2010, 09:21:01 PM by Luben »


Offline StartedBullet

  • ****
  • Posts: 262
  • Gender: Male
  • Blissfully unaware, or am I?
  • Respect: +19
Re: Gamemode LUA scripting problem/player:ConCommand
« Reply #4 on: September 06, 2010, 12:44:40 AM »
0
Thank you this seems to have solved it, but I have seem to have another (hopefully last bug):

gamemodes\laststand\gamemode\init.lua:126: bad argument #1 to 'random' (interval is empty)

Heres the code snippet:

   function GMZombieSpawn( tr )
   
   
   
   
   local spawns = ents.FindByClass( "Zombie_Spawn_Point" )
     local RandomSpawn = math.random(#spawns)   <---- 126
 

 local ent = ents.Create( "npc_zombie" )
ent:SetPos( tr.HitPos )
ent:Spawn( RandomSpawn )
ent:Activate()

 

 
 end



Any ideas? Also, what would be a good way to put a cap on how many zombies spawn?
Turned a new leaf.


Furry artist.

Offline mdew355

  • **
  • Posts: 76
  • Respect: +14
Re: Multiple Scripting Problems
« Reply #5 on: September 06, 2010, 01:21:04 AM »
0
I think you can only use math.random with numbers like math.random(0, 10)
I don't know zombie survival's LUA that well (if that's whats this for) but I don't know where you got #spawns from 0.o
Max: i picked it up
Max: SAID OMG
Max: THIS IS A TONKA TOY
Max: then i played with
Max: it
Max: Loved IT
mdew: that's what she said
mdew: :O

Offline StartedBullet

  • ****
  • Posts: 262
  • Gender: Male
  • Blissfully unaware, or am I?
  • Respect: +19
Re: Multiple Scripting Problems
« Reply #6 on: September 06, 2010, 09:06:56 AM »
0
This is for a single-player LFD last stand mode. Ive seen multiple examples of random spawning through this method on the wki. If not this, how will I randomly spawn zombies.
_______
function GM:PlayerSelectSpawn( pl )
 
    local spawns = ents.FindByClass( "info_player_start" )
    local random_entry = math.random(#spawns)
 
    return spawns[random_entry]
 
end
_________
Thats the wiki script.
Turned a new leaf.


Furry artist.

Offline Кrаsher

  • ****
  • Posts: 436
  • Gender: Male
  • Posts: 9001
  • Respect: +50
Re: Multiple Scripting Problems
« Reply #7 on: September 06, 2010, 10:46:06 AM »
0
I really don't think it is needed to run that on GMod lua, as info_player_start is the main set of spawn points and will automatically be selected. (Randomly)





Offline StartedBullet

  • ****
  • Posts: 262
  • Gender: Male
  • Blissfully unaware, or am I?
  • Respect: +19
Re: Multiple Scripting Problems
« Reply #8 on: September 06, 2010, 11:02:06 AM »
0
No, Im trying to use it to randomly spawn npcs.
Turned a new leaf.


Furry artist.

Offline Tomcat

  • Your Argument is Inert
  • ******
  • Donator
    View More Badges!

  • Posts: 2539
  • Gender: Male
  • Wat Do?
  • Respect: +503
    • Tomcat's blog
Re: Multiple Scripting Problems
« Reply #9 on: September 06, 2010, 11:51:05 AM »
0
No, Im trying to use it to randomly spawn npcs.


find all of the npc spawns then




put them into a table lol

Offline StartedBullet

  • ****
  • Posts: 262
  • Gender: Male
  • Blissfully unaware, or am I?
  • Respect: +19
Re: Multiple Scripting Problems
« Reply #10 on: September 06, 2010, 11:53:29 AM »
0
0.o  :idk: Well can you give me an example? Im still kinda new to programming.
Turned a new leaf.


Furry artist.

Offline Кrаsher

  • ****
  • Posts: 436
  • Gender: Male
  • Posts: 9001
  • Respect: +50
Re: Multiple Scripting Problems
« Reply #11 on: September 06, 2010, 11:58:55 AM »
0
to make ein table

SpawnTable={}

To use ein table

SpawnTable[1]="rite hear"





Offline Tomcat

  • Your Argument is Inert
  • ******
  • Donator
    View More Badges!

  • Posts: 2539
  • Gender: Male
  • Wat Do?
  • Respect: +503
    • Tomcat's blog
Re: Multiple Scripting Problems
« Reply #12 on: September 06, 2010, 02:27:12 PM »
0
to make ein table

SpawnTable={}

To use ein table

SpawnTable[1]="rite hear"




nonoonono


Code: [Select]
ents.FindByClass("pingaz")

Offline Rbn

  • **
  • Linux UserOld Forum MemberrNd Developer
    View More Badges!

  • Posts: 55
  • Gender: Male
  • Include( 'Yuban.lua' )
  • Respect: +121
Re: Multiple Scripting Problems
« Reply #13 on: September 06, 2010, 05:43:03 PM »
0
I think you can only use math.random with numbers like math.random(0, 10)
I don't know zombie survival's LUA that well (if that's whats this for) but I don't know where you got #spawns from 0.o

Actually a # will retrieve the quantity of registers than a table has.

Example:

Code: [Select]
Player: World Spawned: models/weapons/v_toolgun.mdlPlayer: World Spawned: models/weapons/v_superphyscannon.mdl
Player: World Spawned: maps/gm_construct.bsp
] net_graph 1
] net_graph 0
] lua_run spawns = ents.FindByClass( "info_player_start" )
> spawns = ents.FindByClass( "info_player_start" )...
] lua_run print(#spawns)
> print(#spawns)...
18
] lua_run PrintTable(spawns)
> PrintTable(spawns)...
1 = Entity [18][info_player_start]
2 = Entity [19][info_player_start]
3 = Entity [20][info_player_start]
4 = Entity [21][info_player_start]
5 = Entity [22][info_player_start]
6 = Entity [23][info_player_start]
7 = Entity [24][info_player_start]
8 = Entity [25][info_player_start]
9 = Entity [26][info_player_start]
10 = Entity [27][info_player_start]
11 = Entity [28][info_player_start]
12 = Entity [29][info_player_start]
13 = Entity [30][info_player_start]
14 = Entity [31][info_player_start]
15 = Entity [32][info_player_start]
16 = Entity [33][info_player_start]
17 = Entity [34][info_player_start]
18 = Entity [35][info_player_start]

This is for a single-player LFD last stand mode. Ive seen multiple examples of random spawning through this method on the wki. If not this, how will I randomly spawn zombies.
_______
function GM:PlayerSelectSpawn( pl )
 
    local spawns = ents.FindByClass( "info_player_start" )
    local random_entry = math.random(#spawns)
 
    return spawns[random_entry]
 
end
_________
Thats the wiki script.

Try something like this

spawns should be loaded before the function or will make a table every time you call it, memory vs processor. :/

local spawns = ents.FindByClass( "info_player_start" ) --This is what actually a map uses to spawn a (Default player). You can use with Zombie_Spawn_Point too but idk what map u using.

Code: [Select]
function RandomSpot( player )

if player:IsValid() then
player:Spawn()
player:SetPos( spawns[math.random( #spawns )]:GetPos() )  -- Every product in the table is an Entity so we can retrieve using the methos GetPos()
else
return
end

end

I'll help ya later with derma, I HATE DERMA :/ k laterz.
« Last Edit: September 06, 2010, 05:45:47 PM by Luben »


Offline mdew355

  • **
  • Posts: 76
  • Respect: +14
Re: Multiple Scripting Problems
« Reply #14 on: January 12, 2011, 10:03:35 PM »
0
I know this is a really old post, but with the derma you use a line like this:

local ready = vgui.Create("DFrame"); //It's DFrame, not BFrame.
Max: i picked it up
Max: SAID OMG
Max: THIS IS A TONKA TOY
Max: then i played with
Max: it
Max: Loved IT
mdew: that's what she said
mdew: :O