Stop It Slender, If player collects 8 pages then

Where abouts in the stop it slender code “http://steamcommunity.com/sharedfiles/filedetails/?id=171728689&searchtext=
Does it define what happens when a player collects 8 pages, having trouble finding it…
Cause i want to make it when a player collects 8 pages, next round they become slendy

[editline]6th September 2013[/editline]

okay, i re looked through the lua’s and i only managed to find
[lua] ply:Pages [/lua]

So would i write a code like
[lua]
function collectallpages( ply )
if ply:Pages == 8 then
setslender
end
end
hook.Add( “Think”, “allpages”, collectallpages )

function setslender( ply )
ply:SetTeam( slendy )
end

[/lua]

Sorry for noobie coding

The only way to see if something works, or fails, is by testing it. it looks good coming from a noob coder, test it.

EDit: looks like right when a user collects 8 pages they become slender right before the round ends, causing for a random person to be slender

Maybe i should make a timer?

[editline]6th September 2013[/editline]

How about

[lua]
function setslender( ply )
timer.Create(“timer1”, 20, 1, ply:SetTeam( slendy ))
end
[/lua]

[editline]6th September 2013[/editline]

Okay, so when i use the first bit of code
[lua]
function collectallpages( ply )
if ply:Pages == 8 then
setslender
end
end
hook.Add( “Think”, “allpages”, collectallpages )
[/lua]

It sets gamemode to base gamemode, so my only guess is that the “ply:Pages” Does not actually exist and i have magically thought this up from somewhere, i believe i saw it in the code somewhere, i just need to find the bit of code that defines it, cause i don’t know how to create the function for it, also there would be a duplicate so it would mess up right?

[editline]6th September 2013[/editline]

Okay, so it is the part where i try to call the function “setslender”
When i remove that code, it all works, well, besides the set slender when collect 8 pages :confused:
how do i call the function?
Maybe i just completely remove the second function and add it to the first function :confused:
I’ll test

[editline]6th September 2013[/editline]

The code that works now is
[lua]
function collectallpages( ply )
if GetPages == 8 then
timer.Create(“timer1”, 20, 1, ply:SetTeam( TEAM_SLENDER ))
end
end
hook.Add( “Think”, “allpages”, collectallpages )
[/lua]
i will test with bots, also, i will re check the code for when slender is automatically called and see if i can create something that cancels it out or something i don’t know, i’m a noobie

to get the pages a player has you use Player.GetPages.

For your code: ply:GetPages()

I can’t test this, it’s 11:30PM and it’s impossible to find a page, and i know that code ain’t gonna work

:confused:
What i need that function to do is call of the random slender script and force the ply to be slender

[editline]6th September 2013[/editline]

Thanks so much :slight_smile:

[editline]6th September 2013[/editline]

apprently to console, there is something wrong with this code
[lua]
function collectallpages( ply )
if ply:GetPages() >= 1 then
print(“Works”)
end
end
hook.Add( “Think”, “allpages”, collectallpages )
[/lua]

Apparently console says it’s line 2 of that code
[lua]
ERROR: gamemodes/stopitslender/gamemode/init.lua:39: attempt to index local ‘ply’ (a nil value)

  1. v- gamemodes/stopitslender/gamemode/init.lua:39
  2. unknown - lua/includes/modules/hook.lua:82
    [/lua]

P.S The line 39, is line 2 of the code above^^^

I think there is no argument hook. -_-

Iterates over all the players and verify. =)




function collectallpages( )

for v,ply in pairs (player.GetAll()) do

if ply:GetPages() >= 8 then
print("Works")
end

    end
end
hook.Add( "Think", "allpages", collectallpages )



Omg i love you,
i am not very familiar with all that [lua] for v,ply in pairs (player.GetAll()) do [/lua] stuff
even though it is basic, still a big noob, learning to code,

[editline]6th September 2013[/editline]

Alrighty, I am going to attempt to work out how to force slendy next round :confused:
This is gonna be a fun night

=) good luck …

OMG this is so frustrating, okay
How would i code it so that it like saves the player to a variable, then on round start, it checks all the player variables, and if they have a variable then it makes them slender, so it’s like
[lua]
if ply:GetPages == 8 then
ply:GiveToken
end
[/lua]
which would make their var go up one,
then does something like
[lua]
for v,ply in pairs (player.GetAll()) do
if ply:HasToken then
forceslendy
end
[/lua]

Something like that, i’m really tired, i have been trying to do this all night and day and i really want to get this done, someone help please



local meta = FindMetaTable("Player")

function meta:GiveToken(amount)

if self.token == nil then self.token = 0 end

self.token = self.token + amount

end

function meta:HasToken()
return self.token!=nil
end

if ply:GetPages == 8 then 
ply:GiveToken(10)
end


for v,ply in pairs (player.GetAll()) do

if ply:HasToken() then
forceslendy
end

end


Okay :confused: i thought the only way to cancel the random slender is to place the code right before it checks for 1 slender, so it sees 1 slender and carries on playing,
here is the code without me adding to it

[lua]
function GM:PlayerInitialSpawn( pl )

if CurTime() - ROUNDTIME <= 2*60 or #player.GetAll() <= 1 then

	if #player.GetAll() > 1 and #team.GetPlayers(TEAM_SLENDER) <= 0 and #ents.FindByClass("slendy") <= 0 then
	
		local slendy = player.GetAll()[math.random(1,#player.GetAll())]
			
	elseif #player.GetAll() >= 21 and #team.GetPlayers(TEAM_SLENDER) <= 1 and #ents.FindByClass("slendy") <= 1 then
				
		if !pl:IsBot() and self.LastSlender ~= pl then
			pl:SetTeam(TEAM_SLENDER)
			self.LastSlender = pl
			game.GetWorld():SetDTEntity(2,pl)
			pl:CollisionRulesChanged()
		else
			pl:SetTeam(TEAM_HUMENS)
			pl:CollisionRulesChanged()
		end
		
	else
		pl:SetTeam(TEAM_HUMENS)
		pl:CollisionRulesChanged()			
	end
	
else
	pl:SetTeam(TEAM_SPECTATOR)
	pl:CollisionRulesChanged()
end

pl:SetCustomCollisionCheck(true)

pl:SetFrags(0)
pl:SetDeaths(0)

pl:SetPages( 0 )

net.Start( "InitialSpawn" )
net.Send(pl)

pl:SendLua("FixMotionBlur()")

end
[/lua]
That works fine
but when i do this
[lua]
function GM:PlayerInitialSpawn( pl )

for v,pl in pairs (player.GetAll()) do     
if pl:HasToken() then
pl:SetTeam( TEAM_SLENDER )
end
end

if CurTime() - ROUNDTIME <= 2*60 or #player.GetAll() <= 1 then

	if #player.GetAll() > 1 and #team.GetPlayers(TEAM_SLENDER) <= 0 and #ents.FindByClass("slendy") <= 0 then
	
		local slendy = player.GetAll()[math.random(1,#player.GetAll())]
			
	elseif #player.GetAll() >= 21 and #team.GetPlayers(TEAM_SLENDER) <= 1 and #ents.FindByClass("slendy") <= 1 then
	
				
		if !pl:IsBot() and self.LastSlender ~= pl then
			pl:SetTeam(TEAM_SLENDER)
			self.LastSlender = pl
			game.GetWorld():SetDTEntity(2,pl)
			pl:CollisionRulesChanged()
		else
			pl:SetTeam(TEAM_HUMENS)
			pl:CollisionRulesChanged()
		end
		
	else
		pl:SetTeam(TEAM_HUMENS)
		pl:CollisionRulesChanged()			
	end
	
else
	pl:SetTeam(TEAM_SPECTATOR)
	pl:CollisionRulesChanged()
end

pl:SetCustomCollisionCheck(true)

pl:SetFrags(0)
pl:SetDeaths(0)

pl:SetPages( 0 )

net.Start( "InitialSpawn" )
net.Send(pl)

pl:SendLua("FixMotionBlur()")

end
[/lua]

It goes base gamemode, someone help me thanks

[editline]7th September 2013[/editline]

this code sets my gamemode to base
[lua]
if ply:GetPages == 8 then
ply:GiveToken(10)
end
[/lua]

Fixed
[lua]
if ply:GetPages() == 8 then
ply:GiveToken(10)
end
[/lua]