Jump to content

help on write gamemode


XetaQuake

Recommended Posts

You can only give money to players. Maybe there's another element in that sphere. Try this:

function Money( hitElement, matchingDimension) 
    if ( getElementType ( hitElement ) == "player" ) then 
        timer = setTimer( givePlayerMoney, 1000, 0, hitElement, 10 ) 
    end 
end 

Edited by Guest
Link to comment

hm... i think it's just an incorrect function you defined in the timer. Try this:

function Place(name) 
   if name ~= getThisResource() then return else 
   local marker = createMarker ( -1025.5623779297, 457.65173339844, 14, "cylinder", 4, 0, 100, 200, 250 ) 
     end 
  end 
  
function Money( hitElement, matchingDimension) 
timer = setTimer( givePlayerMoney, 1000, 0, hitElement, 10 )-- there's no function called giveMoney you should better try givePlayerMoney 
end 
  
function money_stop () 
killTimer (timer) 
end 
  
Col = createColSphere ( -1025.5623779297, 457.65173339844, 14, 4 ) 
addEventHandler ( "onColShapeHit", Col, Money ) 
addEventHandler ( "onColShapeLeave", Col, money_stop) 
addEventHandler ( "onResourceStart", getRootElement(), Place) 

Link to comment

hitElement is the marker that you hit/enter... use source.

You can't give money to marker

http://development.mtasa.com/index.php? ... rMarkerHit

You can call "native" functions using timer. giveMoney's native, like all of the functions you can find on wiki. So there is no need of creating new function which calls 1 different function. It's not like PAWN where you must do it that way.

Link to comment
well i couldn't find a function that is called giveMoney http://development.mtasa.com/index.php?search=giveMoney&fulltext=Search

and i always used this and it works fine http://development.mtasa.com/index.php?title=GivePlayerMoney

hm... and for the marker you're right the hitElement is the marker i have never checked it but someone here in this thread said that hitElement is the player^^

That's because he's using onColShapeHit event not OnPlayerMarkerHit ;)

Link to comment

hi again :D

i have found a bug ;/

when two players are in the marker the player get every time money! not only when there are in the marker :(

here my currently code i use:

  
function Place(name) 
   if name ~= getThisResource() then return else 
   local marker = createMarker ( -1025.5623779297, 457.65173339844, 14, "cylinder", 4, 0, 100, 200, 250 ) 
     end 
  end 
  
function Money( hitElement, matchingDimension) 
    if ( getElementType ( hitElement ) == "player" ) then 
        timer = setTimer( givePlayerMoney, 1000, 0, hitElement, 10 ) 
    end 
end 
  
function money_stop () 
killTimer (timer) 
end 
  
Col = createColSphere ( -1025.5623779297, 457.65173339844, 14, 4 ) 
addEventHandler ( "onColShapeHit", Col, Money ) 
addEventHandler ( "onColShapeLeave", Col, money_stop) 
addEventHandler ( "onResourceStart", getRootElement(), Place) 
  

have anybody a idea to fix this? i think the problem is anywhere on killTimer

Link to comment

You can create a table which will store each players' timer and then kill them when it's required. What you did was just create a timer when someone enters marker, the timer is killed, but the timer is only for one player and can be killed when you don't really want to.

So, try a global table and store each player's timer in that table. eg:

local timers = { } -- somewhere at the top of script 
... 
-- replace old: timer = setTimer... with this: 
timers[ source ] = setTimer(blah, ...) 
... 
-- and so killTimer 
killTimer( timers[ source ] ) 

Link to comment

good idea but this dont work so good, because:

when only 1 player go in the marker all working good, and when i go out of the marker, i get no money - perfect

but:

when 2 players in the marker, i dont only get money when the first player that joined the server are in the marker, and when the player go out of the marker, i get no money too

it is realy not easy to explain the problem...i hope somebody know a fix

all realy strange :|:?

Link to comment

Me and my freind are going to make drifting movie in san andreas, and we was thinking to take away the crosshair on the camera and use fraps to record. but we dont have a lan mode for that, and we was wondering if some one could make that for us? a mode so we can have camera as weapon, our own handling, and mayby if possible a car spawner that can spawn any cars. can some one make that for us? i dont think it gonna take a long time, becouse we dont need that spawns in the street and no missions or somthing like that..

Sry for bad english! im from norway.

Thanx for help :)

Link to comment

yeh! ^^

this is my thread xD

and here is my currently full code, so PLEAS peaple test it on own server with 2 players in the marker, than you can see the problem.

i dont know how to exlain this problem (or to fix it) :/

  
local timers = { } 
  
function Place(name) 
   if name ~= getThisResource() then return else 
   local marker = createMarker ( -1025.5623779297, 457.65173339844, 14, "cylinder", 4, 0, 100, 200, 250 ) 
     end 
  end 
  
function Money( hitElement, matchingDimension) 
    if ( getElementType ( hitElement ) == "player" ) then 
        timers[ source ] = setTimer( givePlayerMoney, 1000, 0, hitElement, 10 ) 
    end 
end 
  
function money_stop () 
killTimer( timers[ source ] ) 
end 
  
Col = createColSphere ( -1025.5623779297, 457.65173339844, 14, ) 
addEventHandler ( "onColShapeHit", Col, Money ) 
addEventHandler ( "onColShapeLeave", Col, money_stop) 
addEventHandler ( "onResourceStart", getRootElement(), Place) 
  

the marker are on the airport, second city on the end of the starting area

Link to comment

Read: http://development.mtasa.com/index.php? ... ShapeLeave

function money_stop () 
    killTimer( timers[ source ] ) 
end 

You are killing the timer for ColShape not the player which is wrong. It should look like this:

function money_stop (leaveElement, matchingDimension) 
    if ( getElementType ( leaveElement ) == "player" ) then  -- not really needed. just to prevent killing non-existing timers 
        killTimer( timers[ leaveElement ] ) 
    end 
end 

Link to comment

ahhh okay thanks :D

OnColshapeLeave is good!

i get a warning when i leave the marker and the money dont stop, the problem are on line 17:

    killTimer( timers[ leaveElement ] ) 

i have already try to change the line a bit with some possibles, but that don't have solved the bug

a last help? :mrgreen:

Link to comment

Also noticed this:

function Money( hitElement, matchingDimension) 
    if ( getElementType ( hitElement ) == "player" ) then 
        timers[ source ] = setTimer( givePlayerMoney, 1000, 0, hitElement, 10 ) 
    end 
end 

Should be:

function Money( hitElement, matchingDimension) 
    if ( getElementType ( hitElement ) == "player" ) then 
        timers[ hitElement ] = setTimer( givePlayerMoney, 1000, 0, hitElement, 10 ) 
    end 
end 

And read what 50p said. Why use a ColShape at all?

Link to comment

Me and my freind are going to make drifting movie in san andreas, and we was thinking to take away the crosshair on the camera and use fraps to record. but we dont have a lan mode for that, and we was wondering if some one could make that for us? a mode so we can have camera as weapon, our own handling, and mayby if possible a car spawner that can spawn any cars. can some one make that for us? i dont think it gonna take a long time, becouse we dont need that spawns in the street and no missions or somthing like that..

Sry for bad english! im from norway.

Thanx for help

Link to comment
Also noticed this:
function Money( hitElement, matchingDimension) 
    if ( getElementType ( hitElement ) == "player" ) then 
        timers[ source ] = setTimer( givePlayerMoney, 1000, 0, hitElement, 10 ) 
    end 
end 

Should be:

function Money( hitElement, matchingDimension) 
    if ( getElementType ( hitElement ) == "player" ) then 
        timers[ hitElement ] = setTimer( givePlayerMoney, 1000, 0, hitElement, 10 ) 
    end 
end 

And read what 50p said. Why use a ColShape at all?

thanks szlend! thats works

i am wondered that the problem was not the killtimmer, but now i have learning :)

and yes you are right its better i read a little bit more on the wiki :/

and to answer your question: the marker and colshape are from a marker+teleport script :wink:

thanks for all

thread finish (for me ^)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...